Skip to content

Commit 3354e0f

Browse files
committed
Upgrade to Spring Security 5.4.0-SNAPSHOT
See gh-22668
1 parent 94148e9 commit 3354e0f

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.security.cert.CertificateFactory;
2121
import java.security.cert.X509Certificate;
2222
import java.security.interfaces.RSAPrivateKey;
23-
import java.util.ArrayList;
2423
import java.util.List;
2524
import java.util.Map;
2625
import java.util.stream.Collectors;
@@ -34,8 +33,7 @@
3433
import org.springframework.context.annotation.Configuration;
3534
import org.springframework.core.io.Resource;
3635
import org.springframework.security.converter.RsaKeyConverters;
37-
import org.springframework.security.saml2.credentials.Saml2X509Credential;
38-
import org.springframework.security.saml2.credentials.Saml2X509Credential.Saml2X509CredentialType;
36+
import org.springframework.security.saml2.core.Saml2X509Credential;
3937
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
4038
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
4139
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
@@ -69,15 +67,19 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
6967
boolean signRequest = properties.getIdentityprovider().getSinglesignon().isSignRequest();
7068
validateSigningCredentials(properties, signRequest);
7169
RelyingPartyRegistration.Builder builder = RelyingPartyRegistration.withRegistrationId(id);
72-
builder.assertionConsumerServiceUrlTemplate(
70+
builder.assertionConsumerServiceLocation(
7371
"{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
74-
builder.providerDetails(
75-
(details) -> details.webSsoUrl(properties.getIdentityprovider().getSinglesignon().getUrl()));
76-
builder.providerDetails((details) -> details.entityId(properties.getIdentityprovider().getEntityId()));
77-
builder.providerDetails(
78-
(details) -> details.binding(properties.getIdentityprovider().getSinglesignon().getBinding()));
79-
builder.providerDetails((details) -> details.signAuthNRequest(signRequest));
80-
builder.credentials((credentials) -> credentials.addAll(asCredentials(properties)));
72+
builder.assertingPartyDetails((details) -> {
73+
details.singleSignOnServiceLocation(properties.getIdentityprovider().getSinglesignon().getUrl());
74+
details.entityId(properties.getIdentityprovider().getEntityId());
75+
details.singleSignOnServiceBinding(properties.getIdentityprovider().getSinglesignon().getBinding());
76+
details.wantAuthnRequestsSigned(signRequest);
77+
});
78+
builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream()
79+
.map(this::asSigningCredential).forEach(credentials::add));
80+
builder.assertingPartyDetails((details) -> details
81+
.verificationX509Credentials((credentials) -> properties.getIdentityprovider().getVerification()
82+
.getCredentials().stream().map(this::asVerificationCredential).forEach(credentials::add)));
8183
return builder.build();
8284
}
8385

@@ -88,25 +90,17 @@ private void validateSigningCredentials(Registration properties, boolean signReq
8890
}
8991
}
9092

91-
private List<Saml2X509Credential> asCredentials(Registration properties) {
92-
List<Saml2X509Credential> credentials = new ArrayList<>();
93-
properties.getSigning().getCredentials().stream().map(this::asSigningCredential).forEach(credentials::add);
94-
properties.getIdentityprovider().getVerification().getCredentials().stream().map(this::asVerificationCredential)
95-
.forEach(credentials::add);
96-
return credentials;
97-
}
98-
9993
private Saml2X509Credential asSigningCredential(Signing.Credential properties) {
10094
RSAPrivateKey privateKey = readPrivateKey(properties.getPrivateKeyLocation());
10195
X509Certificate certificate = readCertificate(properties.getCertificateLocation());
102-
return new Saml2X509Credential(privateKey, certificate, Saml2X509CredentialType.SIGNING,
103-
Saml2X509CredentialType.DECRYPTION);
96+
return new Saml2X509Credential(privateKey, certificate, Saml2X509Credential.Saml2X509CredentialType.SIGNING,
97+
Saml2X509Credential.Saml2X509CredentialType.DECRYPTION);
10498
}
10599

106100
private Saml2X509Credential asVerificationCredential(Verification.Credential properties) {
107101
X509Certificate certificate = readCertificate(properties.getCertificateLocation());
108-
return new Saml2X509Credential(certificate, Saml2X509CredentialType.ENCRYPTION,
109-
Saml2X509CredentialType.VERIFICATION);
102+
return new Saml2X509Credential(certificate, Saml2X509Credential.Saml2X509CredentialType.ENCRYPTION,
103+
Saml2X509Credential.Saml2X509CredentialType.VERIFICATION);
110104
}
111105

112106
private RSAPrivateKey readPrivateKey(Resource location) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void autoConfigurationUsingJwkSetUriShouldConfigureResourceServerUsingJwsAlgorit
105105
"spring.security.oauth2.resourceserver.jwt.jws-algorithm=RS512")
106106
.run((context) -> {
107107
NimbusReactiveJwtDecoder nimbusReactiveJwtDecoder = context.getBean(NimbusReactiveJwtDecoder.class);
108-
assertThat(nimbusReactiveJwtDecoder).extracting("jwtProcessor.arg$2")
108+
assertThat(nimbusReactiveJwtDecoder).extracting("jwtProcessor.arg$2.arg$1.jwsAlgs")
109109
.matches((algorithms) -> ((Set<JWSAlgorithm>) algorithms).contains(JWSAlgorithm.RS512));
110110
});
111111
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void autoConfigurationShouldMatchDefaultJwsAlgorithm() {
9898
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
9999
Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor");
100100
Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector");
101-
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlg", JWSAlgorithm.RS256);
101+
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlgs",
102+
Collections.singleton(JWSAlgorithm.RS256));
102103
});
103104
}
104105

@@ -111,7 +112,8 @@ void autoConfigurationShouldConfigureResourceServerWithJwsAlgorithm() {
111112
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
112113
Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor");
113114
Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector");
114-
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlg", JWSAlgorithm.RS384);
115+
assertThat(keySelector).hasFieldOrPropertyWithValue("jwsAlgs",
116+
Collections.singleton(JWSAlgorithm.RS384));
115117
assertThat(getBearerTokenFilter(context)).isNotNull();
116118
});
117119
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent(
8080
this.contextRunner.withPropertyValues(getPropertyValues()).run((context) -> {
8181
RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
8282
RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
83-
assertThat(registration.getProviderDetails().getWebSsoUrl())
83+
84+
assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceLocation())
8485
.isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php");
85-
assertThat(registration.getProviderDetails().getEntityId())
86+
assertThat(registration.getAssertingPartyDetails().getEntityId())
8687
.isEqualTo("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php");
87-
assertThat(registration.getAssertionConsumerServiceUrlTemplate())
88+
assertThat(registration.getAssertionConsumerServiceLocation())
8889
.isEqualTo("{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
89-
assertThat(registration.getProviderDetails().getBinding()).isEqualTo(Saml2MessageBinding.POST);
90-
assertThat(registration.getProviderDetails().isSignAuthNRequest()).isEqualTo(false);
91-
assertThat(registration.getSigningCredentials()).isNotNull();
92-
assertThat(registration.getVerificationCredentials()).isNotNull();
90+
assertThat(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding())
91+
.isEqualTo(Saml2MessageBinding.POST);
92+
assertThat(registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()).isEqualTo(false);
93+
assertThat(registration.getSigningX509Credentials()).isNotNull();
94+
assertThat(registration.getAssertingPartyDetails().getVerificationX509Credentials()).isNotNull();
9395
});
9496
}
9597

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ bom {
16161616
]
16171617
}
16181618
}
1619-
library("Spring Security", "5.4.0-M1") {
1619+
library("Spring Security", "5.4.0-SNAPSHOT") {
16201620
group("org.springframework.security") {
16211621
imports = [
16221622
"spring-security-bom"

0 commit comments

Comments
 (0)