Commit 3354e0f0 authored by Brian Clozel's avatar Brian Clozel

Upgrade to Spring Security 5.4.0-SNAPSHOT

See gh-22668
parent 94148e9b
...@@ -20,7 +20,6 @@ import java.io.InputStream; ...@@ -20,7 +20,6 @@ import java.io.InputStream;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -34,8 +33,7 @@ import org.springframework.context.annotation.Conditional; ...@@ -34,8 +33,7 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.security.converter.RsaKeyConverters; import org.springframework.security.converter.RsaKeyConverters;
import org.springframework.security.saml2.credentials.Saml2X509Credential; import org.springframework.security.saml2.core.Saml2X509Credential;
import org.springframework.security.saml2.credentials.Saml2X509Credential.Saml2X509CredentialType;
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository; import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration; import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository; import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
...@@ -69,15 +67,19 @@ class Saml2RelyingPartyRegistrationConfiguration { ...@@ -69,15 +67,19 @@ class Saml2RelyingPartyRegistrationConfiguration {
boolean signRequest = properties.getIdentityprovider().getSinglesignon().isSignRequest(); boolean signRequest = properties.getIdentityprovider().getSinglesignon().isSignRequest();
validateSigningCredentials(properties, signRequest); validateSigningCredentials(properties, signRequest);
RelyingPartyRegistration.Builder builder = RelyingPartyRegistration.withRegistrationId(id); RelyingPartyRegistration.Builder builder = RelyingPartyRegistration.withRegistrationId(id);
builder.assertionConsumerServiceUrlTemplate( builder.assertionConsumerServiceLocation(
"{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI); "{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
builder.providerDetails( builder.assertingPartyDetails((details) -> {
(details) -> details.webSsoUrl(properties.getIdentityprovider().getSinglesignon().getUrl())); details.singleSignOnServiceLocation(properties.getIdentityprovider().getSinglesignon().getUrl());
builder.providerDetails((details) -> details.entityId(properties.getIdentityprovider().getEntityId())); details.entityId(properties.getIdentityprovider().getEntityId());
builder.providerDetails( details.singleSignOnServiceBinding(properties.getIdentityprovider().getSinglesignon().getBinding());
(details) -> details.binding(properties.getIdentityprovider().getSinglesignon().getBinding())); details.wantAuthnRequestsSigned(signRequest);
builder.providerDetails((details) -> details.signAuthNRequest(signRequest)); });
builder.credentials((credentials) -> credentials.addAll(asCredentials(properties))); builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream()
.map(this::asSigningCredential).forEach(credentials::add));
builder.assertingPartyDetails((details) -> details
.verificationX509Credentials((credentials) -> properties.getIdentityprovider().getVerification()
.getCredentials().stream().map(this::asVerificationCredential).forEach(credentials::add)));
return builder.build(); return builder.build();
} }
...@@ -88,25 +90,17 @@ class Saml2RelyingPartyRegistrationConfiguration { ...@@ -88,25 +90,17 @@ class Saml2RelyingPartyRegistrationConfiguration {
} }
} }
private List<Saml2X509Credential> asCredentials(Registration properties) {
List<Saml2X509Credential> credentials = new ArrayList<>();
properties.getSigning().getCredentials().stream().map(this::asSigningCredential).forEach(credentials::add);
properties.getIdentityprovider().getVerification().getCredentials().stream().map(this::asVerificationCredential)
.forEach(credentials::add);
return credentials;
}
private Saml2X509Credential asSigningCredential(Signing.Credential properties) { private Saml2X509Credential asSigningCredential(Signing.Credential properties) {
RSAPrivateKey privateKey = readPrivateKey(properties.getPrivateKeyLocation()); RSAPrivateKey privateKey = readPrivateKey(properties.getPrivateKeyLocation());
X509Certificate certificate = readCertificate(properties.getCertificateLocation()); X509Certificate certificate = readCertificate(properties.getCertificateLocation());
return new Saml2X509Credential(privateKey, certificate, Saml2X509CredentialType.SIGNING, return new Saml2X509Credential(privateKey, certificate, Saml2X509Credential.Saml2X509CredentialType.SIGNING,
Saml2X509CredentialType.DECRYPTION); Saml2X509Credential.Saml2X509CredentialType.DECRYPTION);
} }
private Saml2X509Credential asVerificationCredential(Verification.Credential properties) { private Saml2X509Credential asVerificationCredential(Verification.Credential properties) {
X509Certificate certificate = readCertificate(properties.getCertificateLocation()); X509Certificate certificate = readCertificate(properties.getCertificateLocation());
return new Saml2X509Credential(certificate, Saml2X509CredentialType.ENCRYPTION, return new Saml2X509Credential(certificate, Saml2X509Credential.Saml2X509CredentialType.ENCRYPTION,
Saml2X509CredentialType.VERIFICATION); Saml2X509Credential.Saml2X509CredentialType.VERIFICATION);
} }
private RSAPrivateKey readPrivateKey(Resource location) { private RSAPrivateKey readPrivateKey(Resource location) {
......
...@@ -105,7 +105,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { ...@@ -105,7 +105,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests {
"spring.security.oauth2.resourceserver.jwt.jws-algorithm=RS512") "spring.security.oauth2.resourceserver.jwt.jws-algorithm=RS512")
.run((context) -> { .run((context) -> {
NimbusReactiveJwtDecoder nimbusReactiveJwtDecoder = context.getBean(NimbusReactiveJwtDecoder.class); NimbusReactiveJwtDecoder nimbusReactiveJwtDecoder = context.getBean(NimbusReactiveJwtDecoder.class);
assertThat(nimbusReactiveJwtDecoder).extracting("jwtProcessor.arg$2") assertThat(nimbusReactiveJwtDecoder).extracting("jwtProcessor.arg$2.arg$1.jwsAlgs")
.matches((algorithms) -> ((Set<JWSAlgorithm>) algorithms).contains(JWSAlgorithm.RS512)); .matches((algorithms) -> ((Set<JWSAlgorithm>) algorithms).contains(JWSAlgorithm.RS512));
}); });
} }
......
...@@ -98,7 +98,8 @@ class OAuth2ResourceServerAutoConfigurationTests { ...@@ -98,7 +98,8 @@ class OAuth2ResourceServerAutoConfigurationTests {
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class); JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor"); Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor");
Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector"); Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector");
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlg", JWSAlgorithm.RS256); assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlgs",
Collections.singleton(JWSAlgorithm.RS256));
}); });
} }
...@@ -111,7 +112,8 @@ class OAuth2ResourceServerAutoConfigurationTests { ...@@ -111,7 +112,8 @@ class OAuth2ResourceServerAutoConfigurationTests {
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class); JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor"); Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor");
Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector"); Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector");
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlg", JWSAlgorithm.RS384); assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlgs",
Collections.singleton(JWSAlgorithm.RS384));
assertThat(getBearerTokenFilter(context)).isNotNull(); assertThat(getBearerTokenFilter(context)).isNotNull();
}); });
} }
......
...@@ -80,16 +80,18 @@ public class Saml2RelyingPartyAutoConfigurationTests { ...@@ -80,16 +80,18 @@ public class Saml2RelyingPartyAutoConfigurationTests {
this.contextRunner.withPropertyValues(getPropertyValues()).run((context) -> { this.contextRunner.withPropertyValues(getPropertyValues()).run((context) -> {
RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class); RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
RelyingPartyRegistration registration = repository.findByRegistrationId("foo"); RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
assertThat(registration.getProviderDetails().getWebSsoUrl())
assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceLocation())
.isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php"); .isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php");
assertThat(registration.getProviderDetails().getEntityId()) assertThat(registration.getAssertingPartyDetails().getEntityId())
.isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php"); .isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php");
assertThat(registration.getAssertionConsumerServiceUrlTemplate()) assertThat(registration.getAssertionConsumerServiceLocation())
.isEqualTo("{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI); .isEqualTo("{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
assertThat(registration.getProviderDetails().getBinding()).isEqualTo(Saml2MessageBinding.POST); assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding())
assertThat(registration.getProviderDetails().isSignAuthNRequest()).isEqualTo(false); .isEqualTo(Saml2MessageBinding.POST);
assertThat(registration.getSigningCredentials()).isNotNull(); assertThat(registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()).isEqualTo(false);
assertThat(registration.getVerificationCredentials()).isNotNull(); assertThat(registration.getSigningX509Credentials()).isNotNull();
assertThat(registration.getAssertingPartyDetails().getVerificationX509Credentials()).isNotNull();
}); });
} }
......
...@@ -1616,7 +1616,7 @@ bom { ...@@ -1616,7 +1616,7 @@ bom {
] ]
} }
} }
library("Spring Security", "5.4.0-M1") { library("Spring Security", "5.4.0-SNAPSHOT") {
group("org.springframework.security") { group("org.springframework.security") {
imports = [ imports = [
"spring-security-bom" "spring-security-bom"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment