Merge branch '3.0.x' into 3.1.x

Closes gh-37482
3.1.x
Moritz Halbritter 1 year ago
commit b2dc52fc74

@ -295,7 +295,7 @@ public class Saml2RelyingPartyProperties {
/**
* Whether to sign authentication requests.
*/
private boolean signRequest = true;
private Boolean signRequest;
public String getUrl() {
return this.url;
@ -317,7 +317,11 @@ public class Saml2RelyingPartyProperties {
return this.signRequest;
}
public void setSignRequest(boolean signRequest) {
public Boolean getSignRequest() {
return this.signRequest;
}
public void setSignRequest(Boolean signRequest) {
this.signRequest = signRequest;
}

@ -79,10 +79,10 @@ class Saml2RelyingPartyRegistrationConfiguration {
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
boolean usingMetadata = StringUtils.hasText(properties.getAssertingparty().getMetadataUri());
Builder builder = (!usingMetadata) ? RelyingPartyRegistration.withRegistrationId(id)
: createBuilderUsingMetadata(id, properties.getAssertingparty()).registrationId(id);
: createBuilderUsingMetadata(properties.getAssertingparty()).registrationId(id);
builder.assertionConsumerServiceLocation(properties.getAcs().getLocation());
builder.assertionConsumerServiceBinding(properties.getAcs().getBinding());
builder.assertingPartyDetails(mapAssertingParty(properties.getAssertingparty(), usingMetadata));
builder.assertingPartyDetails(mapAssertingParty(properties.getAssertingparty()));
builder.signingX509Credentials((credentials) -> properties.getSigning()
.getCredentials()
.stream()
@ -110,7 +110,7 @@ class Saml2RelyingPartyRegistrationConfiguration {
return registration;
}
private RelyingPartyRegistration.Builder createBuilderUsingMetadata(String id, AssertingParty properties) {
private RelyingPartyRegistration.Builder createBuilderUsingMetadata(AssertingParty properties) {
String requiredEntityId = properties.getEntityId();
Collection<Builder> candidates = RelyingPartyRegistrations
.collectionFromMetadataLocation(properties.getMetadataUri());
@ -128,16 +128,13 @@ class Saml2RelyingPartyRegistrationConfiguration {
return result[0];
}
private Consumer<AssertingPartyDetails.Builder> mapAssertingParty(AssertingParty assertingParty,
boolean usingMetadata) {
private Consumer<AssertingPartyDetails.Builder> mapAssertingParty(AssertingParty assertingParty) {
return (details) -> {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(assertingParty::getEntityId).to(details::entityId);
map.from(assertingParty.getSinglesignon()::getBinding).to(details::singleSignOnServiceBinding);
map.from(assertingParty.getSinglesignon()::getUrl).to(details::singleSignOnServiceLocation);
map.from(assertingParty.getSinglesignon()::isSignRequest)
.when((signRequest) -> !usingMetadata)
.to(details::wantAuthnRequestsSigned);
map.from(assertingParty.getSinglesignon()::getSignRequest).to(details::wantAuthnRequestsSigned);
map.from(assertingParty.getSinglelogout()::getUrl).to(details::singleLogoutServiceLocation);
map.from(assertingParty.getSinglelogout()::getResponseUrl).to(details::singleLogoutServiceResponseLocation);
map.from(assertingParty.getSinglelogout()::getBinding).to(details::singleLogoutServiceBinding);

@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.security.saml2;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@ -253,7 +252,26 @@ class Saml2RelyingPartyAutoConfigurationTests {
testMultipleProviders("https://idp2.example.com/idp/shibboleth", "https://idp2.example.com/idp/shibboleth");
}
private void testMultipleProviders(String specifiedEntityId, String expected) throws IOException, Exception {
@Test
void signRequestShouldApplyIfMetadataUriIsSet() 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.assertingparty.metadata-uri=" + metadataUrl,
PREFIX + ".foo.assertingparty.singlesignon.sign-request=true",
PREFIX + ".foo.signing.credentials[0].private-key-location=classpath:org/springframework/boot/autoconfigure/security/saml2/rsa.key",
PREFIX + ".foo.signing.credentials[0].certificate-location=classpath:org/springframework/boot/autoconfigure/security/saml2/rsa.crt")
.run((context) -> {
RelyingPartyRegistrationRepository repository = context
.getBean(RelyingPartyRegistrationRepository.class);
RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
assertThat(registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()).isTrue();
});
}
}
private void testMultipleProviders(String specifiedEntityId, String expected) throws Exception {
try (MockWebServer server = new MockWebServer()) {
server.start();
String metadataUrl = server.url("").toString();

@ -67,7 +67,7 @@ class Saml2RelyingPartyPropertiesTests {
.get("simplesamlphp")
.getAssertingparty()
.getSinglesignon()
.isSignRequest()).isFalse();
.getSignRequest()).isFalse();
}
@Test
@ -93,13 +93,13 @@ class Saml2RelyingPartyPropertiesTests {
}
@Test
void customizeSsoSignRequestsIsTrueByDefault() {
void customizeSsoSignRequestsIsNullByDefault() {
this.properties.getRegistration().put("simplesamlphp", new Saml2RelyingPartyProperties.Registration());
assertThat(this.properties.getRegistration()
.get("simplesamlphp")
.getAssertingparty()
.getSinglesignon()
.isSignRequest()).isTrue();
.getSignRequest()).isNull();
}
private void bind(String name, String value) {

@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIID1zCCAr+gAwIBAgIUCzQeKBMTO0iHVW3iKmZC41haqCowDQYJKoZIhvcNAQEL
BQAwezELMAkGA1UEBhMCWFgxEjAQBgNVBAgMCVN0YXRlTmFtZTERMA8GA1UEBwwI
Q2l0eU5hbWUxFDASBgNVBAoMC0NvbXBhbnlOYW1lMRswGQYDVQQLDBJDb21wYW55
U2VjdGlvbk5hbWUxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMzA5MjAwODI5MDNa
Fw0zMzA5MTcwODI5MDNaMHsxCzAJBgNVBAYTAlhYMRIwEAYDVQQIDAlTdGF0ZU5h
bWUxETAPBgNVBAcMCENpdHlOYW1lMRQwEgYDVQQKDAtDb21wYW55TmFtZTEbMBkG
A1UECwwSQ29tcGFueVNlY3Rpb25OYW1lMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDUfi4aaCotJZX6OSDjv6fxCCfc
ihSs91Z/mmN+yc1fsxVSs53SIbqUuo+Wzhv34kp8I/r03P9LWVTkFPbeDxAl75Oa
PGggxK55US0Zfy9Hj1BwWIK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