Search in sources :

Example 51 with RelyingPartyRegistration

use of org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration in project spring-boot by spring-projects.

the class Saml2RelyingPartyRegistrationConfiguration method asRegistration.

private RelyingPartyRegistration asRegistration(String id, Registration properties) {
    boolean usingMetadata = StringUtils.hasText(properties.getIdentityprovider().getMetadataUri());
    Builder builder = (usingMetadata) ? RelyingPartyRegistrations.fromMetadataLocation(properties.getIdentityprovider().getMetadataUri()).registrationId(id) : RelyingPartyRegistration.withRegistrationId(id);
    builder.assertionConsumerServiceLocation(properties.getAcs().getLocation());
    builder.assertionConsumerServiceBinding(properties.getAcs().getBinding());
    builder.assertingPartyDetails(mapIdentityProvider(properties, usingMetadata));
    builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream().map(this::asSigningCredential).forEach(credentials::add));
    builder.decryptionX509Credentials((credentials) -> properties.getDecryption().getCredentials().stream().map(this::asDecryptionCredential).forEach(credentials::add));
    builder.assertingPartyDetails((details) -> details.verificationX509Credentials((credentials) -> properties.getIdentityprovider().getVerification().getCredentials().stream().map(this::asVerificationCredential).forEach(credentials::add)));
    builder.entityId(properties.getEntityId());
    RelyingPartyRegistration registration = builder.build();
    boolean signRequest = registration.getAssertingPartyDetails().getWantAuthnRequestsSigned();
    validateSigningCredentials(properties, signRequest);
    return registration;
}
Also used : X509Certificate(java.security.cert.X509Certificate) Decryption(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Decryption) CertificateFactory(java.security.cert.CertificateFactory) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) RsaKeyConverters(org.springframework.security.converter.RsaKeyConverters) InMemoryRelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Map(java.util.Map) Signing(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration.Signing) AssertingPartyDetails(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails) Resource(org.springframework.core.io.Resource) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Registration(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) Collectors(java.util.stream.Collectors) Saml2X509CredentialType(org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType) Consumer(java.util.function.Consumer) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Builder(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder) Bean(org.springframework.context.annotation.Bean) Verification(org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Identityprovider.Verification) Conditional(org.springframework.context.annotation.Conditional) RelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Builder(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder)

Example 52 with RelyingPartyRegistration

use of org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration in project spring-boot by spring-projects.

the class Saml2RelyingPartyAutoConfigurationTests method autoconfigurationWhenNoMetadataUrlOrPropertyPresentShouldUseRedirectBinding.

@Test
void autoconfigurationWhenNoMetadataUrlOrPropertyPresentShouldUseRedirectBinding() {
    this.contextRunner.withPropertyValues(getPropertyValuesWithoutSsoBinding()).run((context) -> {
        RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
        RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
        assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
    });
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) Test(org.junit.jupiter.api.Test)

Example 53 with RelyingPartyRegistration

use of org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration in project spring-boot by spring-projects.

the class Saml2RelyingPartyAutoConfigurationTests method autoconfigurationWhenMetadataUrlAndPropertyPresentShouldUseBindingFromProperty.

@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.identityprovider.metadata-uri=" + metadataUrl, PREFIX + ".foo.identityprovider.singlesignon.binding=redirect").run((context) -> {
            RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
            RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
            assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
        });
    }
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) MockWebServer(okhttp3.mockwebserver.MockWebServer) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 54 with RelyingPartyRegistration

use of org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration in project spring-boot by spring-projects.

the class Saml2RelyingPartyAutoConfigurationTests method autoconfigurationShouldUseBindingFromMetadataUrlIfPresent.

@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.identityprovider.metadata-uri=" + metadataUrl).run((context) -> {
            RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
            RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
            assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.POST);
        });
    }
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) MockWebServer(okhttp3.mockwebserver.MockWebServer) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 55 with RelyingPartyRegistration

use of org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration in project spring-boot by spring-projects.

the class Saml2RelyingPartyAutoConfigurationTests method relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent.

@Test
void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent() {
    this.contextRunner.withPropertyValues(getPropertyValues()).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");
    });
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) RelyingPartyRegistrationRepository(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository) Test(org.junit.jupiter.api.Test)

Aggregations

RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)97 Test (org.junit.jupiter.api.Test)68 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)41 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)36 TestRelyingPartyRegistrations (org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations)36 Saml2MessageBinding (org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)34 BDDMockito.given (org.mockito.BDDMockito.given)28 Saml2X509Credential (org.springframework.security.saml2.core.Saml2X509Credential)28 Authentication (org.springframework.security.core.Authentication)26 StandardCharsets (java.nio.charset.StandardCharsets)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)24 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)22 Mockito.mock (org.mockito.Mockito.mock)22 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)22 Saml2Exception (org.springframework.security.saml2.Saml2Exception)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)21 Mockito.verify (org.mockito.Mockito.verify)19 MockFilterChain (org.springframework.mock.web.MockFilterChain)19 Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)19