From 8e75817d6a15f26807dc9d4bc73e8d37871c4dde Mon Sep 17 00:00:00 2001 From: BenchmarkingBuffalo <46448799+benchmarkingbuffalo@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:20:05 +0100 Subject: [PATCH] Add nameIdFormat to Properties Add the new property nameIdFormat to the Saml2RelyingPartyProperties and the corresponding mapping to the Saml2RelyingPartyRegistrationConfiguration. See gh-39395 --- .../saml2/Saml2RelyingPartyProperties.java | 15 +++++++++++++-- ...aml2RelyingPartyRegistrationConfiguration.java | 2 ++ .../saml2/Saml2RelyingPartyPropertiesTests.java | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java index 8898587a46b..ca747354f17 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java @@ -31,6 +31,7 @@ import org.springframework.security.saml2.provider.service.registration.Saml2Mes * @author Madhura Bhave * @author Phillip Webb * @author Moritz Halbritter + * @author Lasse Wulff * @since 2.2.0 */ @ConfigurationProperties("spring.security.saml2.relyingparty") @@ -72,6 +73,8 @@ public class Saml2RelyingPartyProperties { */ private final AssertingParty assertingparty = new AssertingParty(); + private String nameIdFormat; + public String getEntityId() { return this.entityId; } @@ -92,12 +95,20 @@ public class Saml2RelyingPartyProperties { return this.decryption; } + public Singlelogout getSinglelogout() { + return this.singlelogout; + } + public AssertingParty getAssertingparty() { return this.assertingparty; } - public Singlelogout getSinglelogout() { - return this.singlelogout; + public String getNameIdFormat() { + return this.nameIdFormat; + } + + public void setNameIdFormat(String nameIdFormat) { + this.nameIdFormat = nameIdFormat; } public static class Acs { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java index 830077fae5b..7dee3c397dd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java @@ -56,6 +56,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @author Moritz Halbritter * @author Lasse Lindqvist + * @author Lasse Wulff */ @Configuration(proxyBeanMethods = false) @Conditional(RegistrationConfiguredCondition.class) @@ -104,6 +105,7 @@ class Saml2RelyingPartyRegistrationConfiguration { builder.singleLogoutServiceResponseLocation(properties.getSinglelogout().getResponseUrl()); builder.singleLogoutServiceBinding(properties.getSinglelogout().getBinding()); builder.entityId(properties.getEntityId()); + builder.nameIdFormat(properties.getNameIdFormat()); RelyingPartyRegistration registration = builder.build(); boolean signRequest = registration.getAssertingPartyDetails().getWantAuthnRequestsSigned(); validateSigningCredentials(properties, signRequest); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java index ff0e8106209..ab959705a86 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java @@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link Saml2RelyingPartyProperties}. * * @author Madhura Bhave + * @author Lasse Wulff */ class Saml2RelyingPartyPropertiesTests { @@ -102,6 +103,13 @@ class Saml2RelyingPartyPropertiesTests { .getSignRequest()).isNull(); } + @Test + void customizeNameIdFormat() { + bind("spring.security.saml2.relyingparty.registration.simplesamlphp.name-id-format", "sampleNameIdFormat"); + assertThat(this.properties.getRegistration().get("simplesamlphp").getNameIdFormat()) + .isEqualTo("sampleNameIdFormat"); + } + private void bind(String name, String value) { bind(Collections.singletonMap(name, value)); }