Skip to content

Commit 829453b

Browse files
committed
Support configuration of localEntityIdTemplate for a SAML Relying Party
Closes gh-20352
1 parent f405249 commit 829453b

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ public Map<String, Registration> getRegistration() {
5151
public static class Registration {
5252

5353
/**
54-
* Relying Party identifier URI pattern.
54+
* Relying party's EntityID.
55+
*
56+
* This value may contain a number of placeholders. They are: baseUrl,
57+
* registrationId, baseScheme, baseHost, and basePort.
58+
*
59+
* The default value is
60+
* {baseUrl}/saml2/service-provider-metadata/{registrationId}.
5561
*/
56-
private String localEntityIdTemplate;
62+
private String relyingPartyEntityId = "{baseUrl}/saml2/service-provider-metadata/{registrationId}";
5763

5864
private final Signing signing = new Signing();
5965

@@ -62,12 +68,12 @@ public static class Registration {
6268
*/
6369
private Identityprovider identityprovider = new Identityprovider();
6470

65-
public String getLocalEntityIdTemplate() {
66-
return this.localEntityIdTemplate;
71+
public String getRelyingPartyEntityId() {
72+
return this.relyingPartyEntityId;
6773
}
6874

69-
public void setLocalEntityIdTemplate(String template) {
70-
this.localEntityIdTemplate = template;
75+
public void setRelyingPartyEntityId(String entityId) {
76+
this.relyingPartyEntityId = entityId;
7177
}
7278

7379
public Signing getSigning() {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.ArrayList;
2424
import java.util.List;
2525
import java.util.Map;
26-
import java.util.Optional;
2726
import java.util.stream.Collectors;
2827

2928
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -79,8 +78,7 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
7978
(details) -> details.binding(properties.getIdentityprovider().getSinglesignon().getBinding()));
8079
builder.providerDetails((details) -> details.signAuthNRequest(signRequest));
8180
builder.credentials((credentials) -> credentials.addAll(asCredentials(properties)));
82-
Optional.ofNullable(properties.getLocalEntityIdTemplate())
83-
.ifPresent((template) -> builder.localEntityIdTemplate(template));
81+
builder.localEntityIdTemplate(properties.getRelyingPartyEntityId());
8482
return builder.build();
8583
}
8684

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent(
9090
assertThat(registration.getProviderDetails().isSignAuthNRequest()).isEqualTo(false);
9191
assertThat(registration.getSigningCredentials()).isNotNull();
9292
assertThat(registration.getVerificationCredentials()).isNotNull();
93-
assertThat(registration.getLocalEntityIdTemplate()).isEqualTo("{baseUrl}/saml2/local-entity-id");
93+
assertThat(registration.getLocalEntityIdTemplate()).isEqualTo("{baseUrl}/saml2/foo-entity-id");
9494
});
9595
}
9696

@@ -149,7 +149,7 @@ private String[] getPropertyValues() {
149149
PREFIX + ".foo.identityprovider.singlesignon.sign-request=false",
150150
PREFIX + ".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php",
151151
PREFIX + ".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location",
152-
PREFIX + ".foo.local-entity-id-template={baseUrl}/saml2/local-entity-id" };
152+
PREFIX + ".foo.relying-party-entity-id={baseUrl}/saml2/foo-entity-id" };
153153
}
154154

155155
private boolean hasFilter(AssertableWebApplicationContext context, Class<? extends Filter> filter) {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.boot.context.properties.bind.Binder;
2626
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
2727
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
28+
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
2829
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding;
2930

3031
import static org.assertj.core.api.Assertions.assertThat;
@@ -88,17 +89,17 @@ void customizeSsoSignRequestsIsTrueByDefault() {
8889
}
8990

9091
@Test
91-
void customizeLocalEntityIdTemplate() {
92-
bind("spring.security.saml2.relyingparty.registration.simplesamlphp.local-entity-id-template",
93-
"{baseUrl}/saml2/local-entity-id");
94-
assertThat(this.properties.getRegistration().get("simplesamlphp").getLocalEntityIdTemplate())
95-
.isEqualTo("{baseUrl}/saml2/local-entity-id");
92+
void customizeRelyingPartyEntityId() {
93+
bind("spring.security.saml2.relyingparty.registration.simplesamlphp.relying-party-entity-id",
94+
"{baseUrl}/saml2/custom-entity-id");
95+
assertThat(this.properties.getRegistration().get("simplesamlphp").getRelyingPartyEntityId())
96+
.isEqualTo("{baseUrl}/saml2/custom-entity-id");
9697
}
9798

9899
@Test
99-
void customizeLocalEntityIdTemplateDefaultsToServiceProviderMetadata() {
100-
this.properties.getRegistration().put("simplesamlphp", new Saml2RelyingPartyProperties.Registration());
101-
assertThat(this.properties.getRegistration().get("simplesamlphp").getLocalEntityIdTemplate()).isNull();
100+
void customizeRelyingPartyEntityIdDefaultsToServiceProviderMetadata() {
101+
assertThat(RelyingPartyRegistration.withRegistrationId("id")).extracting("localEntityIdTemplate")
102+
.isEqualTo(new Saml2RelyingPartyProperties.Registration().getRelyingPartyEntityId());
102103
}
103104

104105
private void bind(String name, String value) {

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/src/main/resources/application.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spring:
1515
entity-id: simplesaml
1616
singlesignon:
1717
url: https://simplesaml-for-spring-saml/SSOService.php
18-
local-entity-id-template: "{baseUrl}/saml2/service-provider-metadata"
18+
relying-party-entity-id: "{baseUrl}/saml2/simple-relying-party"
1919
okta:
2020
signing:
2121
credentials:
@@ -29,4 +29,3 @@ spring:
2929
singlesignon:
3030
url:
3131
https://okta-for-spring/saml2/idp/SSOService.php
32-
local-entity-id-template: "{baseUrl}/saml2/service-provider-metadata"

0 commit comments

Comments
 (0)