Skip to content

Commit c362864

Browse files
committed
Incorporate PR Feedback
1 parent 006f58d commit c362864

File tree

5 files changed

+69
-65
lines changed

5 files changed

+69
-65
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static class Identityprovider {
143143
/**
144144
* Endpoint for discovery-based configuration.
145145
*/
146-
private String metadataUrl;
146+
private String metadataUri;
147147

148148
private final Singlesignon singlesignon = new Singlesignon();
149149

@@ -157,12 +157,12 @@ public void setEntityId(String entityId) {
157157
this.entityId = entityId;
158158
}
159159

160-
public String getMetadataUrl() {
161-
return this.metadataUrl;
160+
public String getMetadataUri() {
161+
return this.metadataUri;
162162
}
163163

164-
public void setMetadataUrl(String metadataUrl) {
165-
this.metadataUrl = metadataUrl;
164+
public void setMetadataUri(String metadataUri) {
165+
this.metadataUri = metadataUri;
166166
}
167167

168168
@Deprecated

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ private RelyingPartyRegistration asRegistration(Map.Entry<String, Registration>
6868

6969
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
7070
RelyingPartyRegistration.Builder builder;
71-
boolean usingMetadata = StringUtils.hasText(properties.getIdentityprovider().getMetadataUrl());
71+
boolean usingMetadata = StringUtils.hasText(properties.getIdentityprovider().getMetadataUri());
7272
if (usingMetadata) {
73-
builder = RelyingPartyRegistrations.fromMetadataLocation(properties.getIdentityprovider().getMetadataUrl())
73+
builder = RelyingPartyRegistrations.fromMetadataLocation(properties.getIdentityprovider().getMetadataUri())
7474
.registrationId(id);
7575
}
7676
else {

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

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
package org.springframework.boot.autoconfigure.security.saml2;
1818

19+
import java.io.InputStream;
1920
import java.util.List;
2021

2122
import javax.servlet.Filter;
2223

2324
import okhttp3.mockwebserver.MockResponse;
2425
import okhttp3.mockwebserver.MockWebServer;
25-
import org.junit.jupiter.api.AfterEach;
26+
import okio.Buffer;
2627
import org.junit.jupiter.api.Test;
2728

2829
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -33,6 +34,7 @@
3334
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
3435
import org.springframework.context.annotation.Bean;
3536
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.core.io.ClassPathResource;
3638
import org.springframework.security.config.BeanIds;
3739
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3840
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -58,15 +60,6 @@ class Saml2RelyingPartyAutoConfigurationTests {
5860
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().withConfiguration(
5961
AutoConfigurations.of(Saml2RelyingPartyAutoConfiguration.class, SecurityAutoConfiguration.class));
6062

61-
private MockWebServer server;
62-
63-
@AfterEach
64-
void cleanup() throws Exception {
65-
if (this.server != null) {
66-
this.server.shutdown();
67-
}
68-
}
69-
7063
@Test
7164
void autoConfigurationShouldBeConditionalOnRelyingPartyRegistrationRepositoryClass() {
7265
this.contextRunner.withPropertyValues(getPropertyValues()).withClassLoader(new FilteredClassLoader(
@@ -126,15 +119,16 @@ void autoConfigurationWhenSignRequestsFalseAndNoSigningCredentialsShouldNotThrow
126119

127120
@Test
128121
void autoconfigurationShouldQueryIdentityProviderMetadataWhenMetadataUrlIsPresent() throws Exception {
129-
this.server = new MockWebServer();
130-
this.server.start();
131-
String metadataUrl = this.server.url("").toString();
132-
setupMockResponse();
133-
this.contextRunner.withPropertyValues(PREFIX + ".foo.identityprovider.metadata-url=" + metadataUrl)
134-
.run((context) -> {
135-
assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class);
136-
assertThat(this.server.getRequestCount()).isEqualTo(1);
137-
});
122+
try (MockWebServer server = new MockWebServer()) {
123+
server.start();
124+
String metadataUrl = server.url("").toString();
125+
setupMockResponse(server);
126+
this.contextRunner.withPropertyValues(PREFIX + ".foo.identityprovider.metadata-uri=" + metadataUrl)
127+
.run((context) -> {
128+
assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class);
129+
assertThat(server.getRequestCount()).isEqualTo(1);
130+
});
131+
}
138132
}
139133

140134
@Test
@@ -201,44 +195,12 @@ private boolean hasFilter(AssertableWebApplicationContext context, Class<? exten
201195
return filters.stream().anyMatch(filter::isInstance);
202196
}
203197

204-
private void setupMockResponse() {
205-
String metadataResponse = "<md:EntityDescriptor entityID=\"https://idp.example.com/idp/shibboleth\"\n"
206-
+ " xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"\n"
207-
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
208-
+ " xmlns:shibmd=\"urn:mace:shibboleth:metadata:1.0\"\n"
209-
+ " xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\"\n"
210-
+ " xmlns:mdui=\"urn:oasis:names:tc:SAML:metadata:ui\">\n" + " \n"
211-
+ " <md:IDPSSODescriptor protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n"
212-
+ " <md:KeyDescriptor>\n" + " <ds:KeyInfo>\n" + " <ds:X509Data>\n"
213-
+ " <ds:X509Certificate>\n"
214-
+ " MIIDZjCCAk6gAwIBAgIVAL9O+PA7SXtlwZZY8MVSE9On1cVWMA0GCSqGSIb3DQEB\n"
215-
+ " BQUAMCkxJzAlBgNVBAMTHmlkZW0tcHVwYWdlbnQuZG16LWludC51bmltby5pdDAe\n"
216-
+ " Fw0xMzA3MjQwMDQ0MTRaFw0zMzA3MjQwMDQ0MTRaMCkx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" V5p4IQRV6QBsNw9CISJFuHzkVYTH5ZxzN80Ru46vh4y2M0Nu8GQ9I085KoZkrf5e\n"
232-
+ " Cq53OZt9ISjHEw==\n" + " </ds:X509Certificate>\n"
233-
+ " </ds:X509Data>\n" + " </ds:KeyInfo>\n" + " </md:KeyDescriptor>\n" + " \n"
234-
+ " <md:SingleSignOnService\n"
235-
+ " Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\"\n"
236-
+ " Location=\"https://idp.example.com/sso\"/>\n" + " </md:IDPSSODescriptor>\n" + " \n"
237-
+ " <md:ContactPerson contactType=\"technical\">\n"
238-
+ " <md:EmailAddress>mailto:[email protected]</md:EmailAddress>\n"
239-
+ " </md:ContactPerson>\n" + " \n" + "</md:EntityDescriptor>";
240-
MockResponse mockResponse = new MockResponse().setBody(metadataResponse);
241-
this.server.enqueue(mockResponse);
198+
private void setupMockResponse(MockWebServer server) throws Exception {
199+
try (InputStream metadataSource = new ClassPathResource("saml/idp-metadata").getInputStream()) {
200+
Buffer metadataBuffer = new Buffer().readFrom(metadataSource);
201+
MockResponse metadataResponse = new MockResponse().setBody(metadataBuffer);
202+
server.enqueue(metadataResponse);
203+
}
242204
}
243205

244206
@Configuration(proxyBeanMethods = false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void customizeRelyingPartyEntityIdDefaultsToServiceProviderMetadata() {
106106
void customizeIdentityProviderMetadataUrl() {
107107
bind("spring.security.saml2.relyingparty.registration.simplesamlphp.identityprovider.metadata-url",
108108
"https://idp.example.org/metadata");
109-
assertThat(this.properties.getRegistration().get("simplesamlphp").getIdentityprovider().getMetadataUrl())
109+
assertThat(this.properties.getRegistration().get("simplesamlphp").getIdentityprovider().getMetadataUri())
110110
.isEqualTo("https://idp.example.org/metadata");
111111
}
112112

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<md:EntityDescriptor entityID="https://idp.example.com/idp/shibboleth"
2+
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:shibmd="urn:mace:shibboleth:metadata:1.0"
5+
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
6+
xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui">
7+
<md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
8+
<md:KeyDescriptor>
9+
<ds:KeyInfo>
10+
<ds:X509Data>
11+
<ds:X509Certificate>
12+
MIIDZjCCAk6gAwIBAgIVAL9O+PA7SXtlwZZY8MVSE9On1cVWMA0GCSqGSIb3DQEB
13+
BQUAMCkxJzAlBgNVBAMTHmlkZW0tcHVwYWdlbnQuZG16LWludC51bmltby5pdDAe
14+
Fw0xMzA3MjQwMDQ0MTRaFw0zMzA3MjQwMDQ0MTRaMCkxJzAlBgNVBAMTHmlkZW0t
15+
cHVwYWdlbnQuZG16LWludC51bmltby5pdDCCASIwDQYJKoZIhvcNAMIIDQADggEP
16+
ADCCAQoCggEBAIAcp/VyzZGXUF99kwj4NvL/Rwv4YvBgLWzpCuoxqHZ/hmBwJtqS
17+
v0y9METBPFbgsF3hCISnxbcmNVxf/D0MoeKtw1YPbsUmow/bFe+r72hZ+IVAcejN
18+
iDJ7t5oTjsRN1t1SqvVVk6Ryk5AZhpFW+W9pE9N6c7kJ16Rp2/mbtax9OCzxpece
19+
byi1eiLfIBmkcRawL/vCc2v6VLI18i6HsNVO3l2yGosKCbuSoGDx2fCdAOk/rgdz
20+
cWOvFsIZSKuD+FVbSS/J9GVs7yotsS4PRl4iX9UMnfDnOMfO7bcBgbXtDl4SCU1v
21+
dJrRw7IL/pLz34Rv9a8nYitrzrxtLOp3nYUCAwEAAaOBhDCBgTBgBgMIIDEEWTBX
22+
gh5pZGVtLXB1cGFnZW50LmRtei1pbnQudW5pbW8uaXSGNWh0dHBzOi8vaWRlbS1w
23+
dXBhZ2VudC5kbXotaW50LnVuaW1vLml0L2lkcC9zaGliYm9sZXRoMB0GA1UdDgQW
24+
BBT8PANzz+adGnTRe8ldcyxAwe4VnzANBgkqhkiG9w0BAQUFAAOCAQEAOEnO8Clu
25+
9z/Lf/8XOOsTdxJbV29DIF3G8KoQsB3dBsLwPZVEAQIP6ceS32Xaxrl6FMTDDNkL
26+
qUvvInUisw0+I5zZwYHybJQCletUWTnz58SC4C9G7FpuXHFZnOGtRcgGD1NOX4UU
27+
duus/4nVcGSLhDjszZ70Xtj0gw2Sn46oQPHTJ81QZ3Y9ih+Aj1c9OtUSBwtWZFkU
28+
yooAKoR8li68Yb21zN2N65AqV+ndL98M8xUYMKLONuAXStDeoVCipH6PJ09Z5U2p
29+
V5p4IQRV6QBsNw9CISJFuHzkVYTH5ZxzN80Ru46vh4y2M0Nu8GQ9I085KoZkrf5e
30+
Cq53OZt9ISjHEw==
31+
</ds:X509Certificate>
32+
</ds:X509Data>
33+
</ds:KeyInfo>
34+
</md:KeyDescriptor>
35+
<md:SingleSignOnService
36+
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
37+
Location="https://idp.example.com/sso"/>
38+
</md:IDPSSODescriptor>
39+
<md:ContactPerson contactType="technical">
40+
<md:EmailAddress>mailto:[email protected]</md:EmailAddress>
41+
</md:ContactPerson>
42+
</md:EntityDescriptor>

0 commit comments

Comments
 (0)