Search in sources :

Example 1 with Registration

use of org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration 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 2 with Registration

use of org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration in project spring-boot by spring-projects.

the class Saml2RelyingPartyRegistrationConfiguration method mapIdentityProvider.

private Consumer<AssertingPartyDetails.Builder> mapIdentityProvider(Registration properties, boolean usingMetadata) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Saml2RelyingPartyProperties.Identityprovider identityprovider = properties.getIdentityprovider();
    return (details) -> {
        map.from(identityprovider::getEntityId).to(details::entityId);
        map.from(identityprovider.getSinglesignon()::getBinding).whenNonNull().to(details::singleSignOnServiceBinding);
        map.from(identityprovider.getSinglesignon()::getUrl).to(details::singleSignOnServiceLocation);
        map.from(identityprovider.getSinglesignon()::isSignRequest).when((signRequest) -> !usingMetadata).to(details::wantAuthnRequestsSigned);
    };
}
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) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Aggregations

InputStream (java.io.InputStream)2 CertificateFactory (java.security.cert.CertificateFactory)2 X509Certificate (java.security.cert.X509Certificate)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Decryption (org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Decryption)2 Verification (org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Identityprovider.Verification)2 Registration (org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration)2 Signing (org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyProperties.Registration.Signing)2 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)2 Bean (org.springframework.context.annotation.Bean)2 Conditional (org.springframework.context.annotation.Conditional)2 Configuration (org.springframework.context.annotation.Configuration)2 Resource (org.springframework.core.io.Resource)2 RsaKeyConverters (org.springframework.security.converter.RsaKeyConverters)2 Saml2X509Credential (org.springframework.security.saml2.core.Saml2X509Credential)2