@ -62,7 +62,15 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoConfigurationShouldBeConditionalOnRelyingPartyRegistrationRepositoryClass ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( ) ) . withClassLoader ( new FilteredClassLoader (
this . contextRunner . withPropertyValues ( getPropertyValues ( false ) ) . withClassLoader ( new FilteredClassLoader (
"org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository" ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@Test
@Deprecated
void autoConfigurationShouldBeConditionalOnRelyingPartyRegistrationRepositoryClassDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( true ) ) . withClassLoader ( new FilteredClassLoader (
"org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository" ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@ -71,7 +79,16 @@ class Saml2RelyingPartyAutoConfigurationTests {
void autoConfigurationShouldBeConditionalOnServletWebApplication ( ) {
new ApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( Saml2RelyingPartyAutoConfiguration . class ) )
. withPropertyValues ( getPropertyValues ( ) )
. withPropertyValues ( getPropertyValues ( false ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@Test
@Deprecated
void autoConfigurationShouldBeConditionalOnServletWebApplicationDeprecated ( ) {
new ApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( Saml2RelyingPartyAutoConfiguration . class ) )
. withPropertyValues ( getPropertyValues ( true ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@ -83,7 +100,31 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( ) ) . run ( ( context ) - > {
this . contextRunner . withPropertyValues ( getPropertyValues ( false ) ) . run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context . getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceLocation ( ) )
. isEqualTo ( "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getEntityId ( ) )
. isEqualTo ( "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ) ;
assertThat ( registration . getAssertionConsumerServiceLocation ( ) )
. isEqualTo ( "{baseUrl}/login/saml2/foo-entity-id" ) ;
assertThat ( registration . getAssertionConsumerServiceBinding ( ) ) . isEqualTo ( Saml2MessageBinding . REDIRECT ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceBinding ( ) )
. isEqualTo ( Saml2MessageBinding . POST ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getWantAuthnRequestsSigned ( ) ) . isEqualTo ( false ) ;
assertThat ( registration . getSigningX509Credentials ( ) ) . hasSize ( 1 ) ;
assertThat ( registration . getDecryptionX509Credentials ( ) ) . hasSize ( 1 ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getVerificationX509Credentials ( ) ) . isNotNull ( ) ;
assertThat ( registration . getEntityId ( ) ) . isEqualTo ( "{baseUrl}/saml2/foo-entity-id" ) ;
} ) ;
}
@Test
@Deprecated
void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresentDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( true ) ) . run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context . getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
@ -106,7 +147,18 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoConfigurationWhenSignRequestsTrueAndNoSigningCredentialsShouldThrowException ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( true ) ) . run ( ( context ) - > {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( true , false ) )
. run ( ( context ) - > {
assertThat ( context ) . hasFailed ( ) ;
assertThat ( context . getStartupFailure ( ) ) . hasMessageContaining (
"Signing credentials must not be empty when authentication requests require signing." ) ;
} ) ;
}
@Test
@Deprecated
void autoConfigurationWhenSignRequestsTrueAndNoSigningCredentialsShouldThrowExceptionDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( true , true ) ) . run ( ( context ) - > {
assertThat ( context ) . hasFailed ( ) ;
assertThat ( context . getStartupFailure ( ) ) . hasMessageContaining (
"Signing credentials must not be empty when authentication requests require signing." ) ;
@ -115,12 +167,34 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoConfigurationWhenSignRequestsFalseAndNoSigningCredentialsShouldNotThrowException ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( false ))
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( false , false ))
. run ( ( context ) - > assertThat ( context ) . hasSingleBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@Test
void autoconfigurationShouldQueryIdentityProviderMetadataWhenMetadataUrlIsPresent ( ) throws Exception {
@Deprecated
void autoConfigurationWhenSignRequestsFalseAndNoSigningCredentialsShouldNotThrowExceptionDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSigningCredentials ( false , true ) )
. run ( ( context ) - > assertThat ( context ) . hasSingleBean ( RelyingPartyRegistrationRepository . class ) ) ;
}
@Test
void autoconfigurationShouldQueryAssertingPartyMetadataWhenMetadataUrlIsPresent ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
setupMockResponse ( server , new ClassPathResource ( "saml/idp-metadata" ) ) ;
this . contextRunner . withPropertyValues ( PREFIX + ".foo.asserting-party.metadata-uri=" + metadataUrl )
. run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( RelyingPartyRegistrationRepository . class ) ;
assertThat ( server . getRequestCount ( ) ) . isEqualTo ( 1 ) ;
} ) ;
}
}
@Test
@Deprecated
void autoconfigurationShouldQueryAssertingPartyMetadataWhenMetadataUrlIsPresentDeprecated ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
@ -135,6 +209,24 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoconfigurationShouldUseBindingFromMetadataUrlIfPresent ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
setupMockResponse ( server , new ClassPathResource ( "saml/idp-metadata" ) ) ;
this . contextRunner . withPropertyValues ( PREFIX + ".foo.asserting-party.metadata-uri=" + metadataUrl )
. run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context
. getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceBinding ( ) )
. isEqualTo ( Saml2MessageBinding . POST ) ;
} ) ;
}
}
@Test
@Deprecated
void autoconfigurationShouldUseBindingFromMetadataUrlIfPresentDeprecated ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
@ -152,6 +244,24 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoconfigurationWhenMetadataUrlAndPropertyPresentShouldUseBindingFromProperty ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
setupMockResponse ( server , new ClassPathResource ( "saml/idp-metadata" ) ) ;
this . contextRunner . withPropertyValues ( PREFIX + ".foo.asserting-party.metadata-uri=" + metadataUrl ,
PREFIX + ".foo.asserting-party.singlesignon.binding=redirect" ) . run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context
. getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceBinding ( ) )
. isEqualTo ( Saml2MessageBinding . REDIRECT ) ;
} ) ;
}
}
@Test
@Deprecated
void autoconfigurationWhenMetadataUrlAndPropertyPresentShouldUseBindingFromPropertyDeprecated ( ) throws Exception {
try ( MockWebServer server = new MockWebServer ( ) ) {
server . start ( ) ;
String metadataUrl = server . url ( "" ) . toString ( ) ;
@ -169,7 +279,18 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void autoconfigurationWhenNoMetadataUrlOrPropertyPresentShouldUseRedirectBinding ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSsoBinding ( ) ) . run ( ( context ) - > {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSsoBinding ( false ) ) . run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context . getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceBinding ( ) )
. isEqualTo ( Saml2MessageBinding . REDIRECT ) ;
} ) ;
}
@Test
@Deprecated
void autoconfigurationWhenNoMetadataUrlOrPropertyPresentShouldUseRedirectBindingDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValuesWithoutSsoBinding ( true ) ) . run ( ( context ) - > {
RelyingPartyRegistrationRepository repository = context . getBean ( RelyingPartyRegistrationRepository . class ) ;
RelyingPartyRegistration registration = repository . findByRegistrationId ( "foo" ) ;
assertThat ( registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceBinding ( ) )
@ -179,7 +300,17 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void relyingPartyRegistrationRepositoryShouldBeConditionalOnMissingBean ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( ) )
this . contextRunner . withPropertyValues ( getPropertyValues ( false ) )
. withUserConfiguration ( RegistrationRepositoryConfiguration . class ) . run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( RelyingPartyRegistrationRepository . class ) ;
assertThat ( context ) . hasBean ( "testRegistrationRepository" ) ;
} ) ;
}
@Test
@Deprecated
void relyingPartyRegistrationRepositoryShouldBeConditionalOnMissingBeanDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( true ) )
. withUserConfiguration ( RegistrationRepositoryConfiguration . class ) . run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( RelyingPartyRegistrationRepository . class ) ;
assertThat ( context ) . hasBean ( "testRegistrationRepository" ) ;
@ -188,59 +319,102 @@ class Saml2RelyingPartyAutoConfigurationTests {
@Test
void samlLoginShouldBeConfigured ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( ) )
this . contextRunner . withPropertyValues ( getPropertyValues ( false ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isTrue ( ) ) ;
}
@Test
@Deprecated
void samlLoginShouldBeConfiguredDeprecated ( ) {
this . contextRunner . withPropertyValues ( getPropertyValues ( true ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isTrue ( ) ) ;
}
@Test
void samlLoginShouldBackOffWhenAWebSecurityConfigurerAdapterIsDefined ( ) {
this . contextRunner . withUserConfiguration ( WebSecurityConfigurerAdapterConfiguration . class )
. withPropertyValues ( getPropertyValues ( ) )
. withPropertyValues ( getPropertyValues ( false ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isFalse ( ) ) ;
}
@Test
@Deprecated
void samlLoginShouldBackOffWhenAWebSecurityConfigurerAdapterIsDefinedDeprecated ( ) {
this . contextRunner . withUserConfiguration ( WebSecurityConfigurerAdapterConfiguration . class )
. withPropertyValues ( getPropertyValues ( true ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isFalse ( ) ) ;
}
@Test
void samlLoginShouldBackOffWhenASecurityFilterChainBeanIsPresent ( ) {
this . contextRunner . withUserConfiguration ( TestSecurityFilterChainConfig . class )
. withPropertyValues ( getPropertyValues ( ) )
. withPropertyValues ( getPropertyValues ( false ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isFalse ( ) ) ;
}
@Test
@Deprecated
void samlLoginShouldBackOffWhenASecurityFilterChainBeanIsPresentDeprecated ( ) {
this . contextRunner . withUserConfiguration ( TestSecurityFilterChainConfig . class )
. withPropertyValues ( getPropertyValues ( true ) )
. run ( ( context ) - > assertThat ( hasFilter ( context , Saml2WebSsoAuthenticationFilter . class ) ) . isFalse ( ) ) ;
}
@Test
void samlLoginShouldShouldBeConditionalOnSecurityWebFilterClass ( ) {
this . contextRunner . withClassLoader ( new FilteredClassLoader ( SecurityFilterChain . class ) )
. withPropertyValues ( getPropertyValues ( ) )
. withPropertyValues ( getPropertyValues ( false ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( SecurityFilterChain . class ) ) ;
}
private String [ ] getPropertyValuesWithoutSigningCredentials ( boolean signRequests ) {
return new String [ ] { PREFIX
+ ".foo.identityprovider.singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo.identityprovider.singlesignon.binding=post" ,
PREFIX + ".foo.identityprovider.singlesignon.sign-request=" + signRequests ,
PREFIX + ".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location" } ;
@Test
@Deprecated
void samlLoginShouldShouldBeConditionalOnSecurityWebFilterClassDeprecated ( ) {
this . contextRunner . withClassLoader ( new FilteredClassLoader ( SecurityFilterChain . class ) )
. withPropertyValues ( getPropertyValues ( true ) )
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( SecurityFilterChain . class ) ) ;
}
private String [ ] getPropertyValuesWithoutSsoBinding ( ) {
return new String [ ] { PREFIX
+ ".foo.identityprovider.singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo.identityprovider.singlesignon.sign-request=false" ,
PREFIX + ".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location" } ;
private String [ ] getPropertyValuesWithoutSigningCredentials ( boolean signRequests , boolean useDeprecated ) {
String assertingParty = useDeprecated ? "identityprovider" : "asserting-party" ;
return new String [ ] {
PREFIX + ".foo." + assertingParty
+ ".singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo." + assertingParty + ".singlesignon.binding=post" ,
PREFIX + ".foo." + assertingParty + ".singlesignon.sign-request=" + signRequests ,
PREFIX + ".foo." + assertingParty
+ ".entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo." + assertingParty
+ ".verification.credentials[0].certificate-location=classpath:saml/certificate-location" } ;
}
private String [ ] getPropertyValuesWithoutSsoBinding ( boolean useDeprecated ) {
String assertingParty = useDeprecated ? "identityprovider" : "asserting-party" ;
return new String [ ] {
PREFIX + ".foo." + assertingParty
+ ".singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo." + assertingParty + ".singlesignon.sign-request=false" ,
PREFIX + ".foo." + assertingParty
+ ".entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo." + assertingParty
+ ".verification.credentials[0].certificate-location=classpath:saml/certificate-location" } ;
}
private String [ ] getPropertyValues ( ) {
private String [ ] getPropertyValues ( boolean useDeprecated ) {
String assertingParty = useDeprecated ? "identityprovider" : "asserting-party" ;
return new String [ ] {
PREFIX + ".foo.signing.credentials[0].private-key-location=classpath:saml/private-key-location" ,
PREFIX + ".foo.signing.credentials[0].certificate-location=classpath:saml/certificate-location" ,
PREFIX + ".foo.decryption.credentials[0].private-key-location=classpath:saml/private-key-location" ,
PREFIX + ".foo.decryption.credentials[0].certificate-location=classpath:saml/certificate-location" ,
PREFIX + ".foo.identityprovider.singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo.identityprovider.singlesignon.binding=post" ,
PREFIX + ".foo.identityprovider.singlesignon.sign-request=false" ,
PREFIX + ".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location" ,
PREFIX + ".foo." + assertingParty
+ ".singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php" ,
PREFIX + ".foo." + assertingParty + ".singlesignon.binding=post" ,
PREFIX + ".foo." + assertingParty + ".singlesignon.sign-request=false" ,
PREFIX + ".foo." + assertingParty
+ ".entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ,
PREFIX + ".foo." + assertingParty
+ ".verification.credentials[0].certificate-location=classpath:saml/certificate-location" ,
PREFIX + ".foo.entity-id={baseUrl}/saml2/foo-entity-id" ,
PREFIX + ".foo.acs.location={baseUrl}/login/saml2/foo-entity-id" ,
PREFIX + ".foo.acs.binding=redirect" } ;