|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.security.saml2;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -55,6 +56,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
*
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
|
* @author Moritz Halbritter
|
|
|
|
|
* @author Lasse Lindqvist
|
|
|
|
|
*/
|
|
|
|
|
class Saml2RelyingPartyAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
@ -404,39 +406,35 @@ class Saml2RelyingPartyAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void autoconfigurationShouldWorkWithMultipleProvidersWithNoEntityId() throws Exception {
|
|
|
|
|
try (MockWebServer server = new MockWebServer()) {
|
|
|
|
|
server.start();
|
|
|
|
|
String metadataUrl = server.url("").toString();
|
|
|
|
|
setupMockResponse(server, new ClassPathResource("saml/idp-metadata-with-multiple-providers"));
|
|
|
|
|
this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl)
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
assertThat(server.getRequestCount()).isOne();
|
|
|
|
|
RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
|
|
|
|
|
assertThat(registration.getAssertingPartyDetails().getEntityId())
|
|
|
|
|
.isEqualTo("https://idp.example.com/idp/shibboleth");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
void autoconfigurationWhenMultipleProvidersAndNoSpecifiedEntityId() throws Exception {
|
|
|
|
|
testMultipleProviders(null, "https://idp.example.com/idp/shibboleth");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void autoconfigurationShouldWorkWithMultipleProviders() throws Exception {
|
|
|
|
|
void autoconfigurationWhenMultipleProvidersAndSpecifiedEntityId() throws Exception {
|
|
|
|
|
testMultipleProviders("https://idp.example.com/idp/shibboleth", "https://idp.example.com/idp/shibboleth");
|
|
|
|
|
testMultipleProviders("https://idp2.example.com/idp/shibboleth", "https://idp2.example.com/idp/shibboleth");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testMultipleProviders(String specifiedEntityId, String expected) throws IOException, Exception {
|
|
|
|
|
try (MockWebServer server = new MockWebServer()) {
|
|
|
|
|
server.start();
|
|
|
|
|
String metadataUrl = server.url("").toString();
|
|
|
|
|
setupMockResponse(server, new ClassPathResource("saml/idp-metadata-with-multiple-providers"));
|
|
|
|
|
this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl,
|
|
|
|
|
PREFIX + ".foo.assertingparty.entity-id=https://idp2.example.com/idp/shibboleth")
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
assertThat(server.getRequestCount()).isOne();
|
|
|
|
|
RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
|
|
|
|
|
assertThat(registration.getAssertingPartyDetails().getEntityId())
|
|
|
|
|
.isEqualTo("https://idp2.example.com/idp/shibboleth");
|
|
|
|
|
});
|
|
|
|
|
WebApplicationContextRunner contextRunner = this.contextRunner
|
|
|
|
|
.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl);
|
|
|
|
|
if (specifiedEntityId != null) {
|
|
|
|
|
contextRunner = contextRunner
|
|
|
|
|
.withPropertyValues(PREFIX + ".foo.assertingparty.entity-id=" + specifiedEntityId);
|
|
|
|
|
}
|
|
|
|
|
contextRunner.run((context) -> {
|
|
|
|
|
assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
assertThat(server.getRequestCount()).isOne();
|
|
|
|
|
RelyingPartyRegistrationRepository repository = context
|
|
|
|
|
.getBean(RelyingPartyRegistrationRepository.class);
|
|
|
|
|
RelyingPartyRegistration registration = repository.findByRegistrationId("foo");
|
|
|
|
|
assertThat(registration.getAssertingPartyDetails().getEntityId()).isEqualTo(expected);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|