|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.security.saml2;
|
18 | 18 |
|
| 19 | +import java.io.IOException; |
19 | 20 | import java.io.InputStream;
|
20 | 21 | import java.util.List;
|
21 | 22 |
|
|
55 | 56 | *
|
56 | 57 | * @author Madhura Bhave
|
57 | 58 | * @author Moritz Halbritter
|
| 59 | + * @author Lasse Lindqvist |
58 | 60 | */
|
59 | 61 | class Saml2RelyingPartyAutoConfigurationTests {
|
60 | 62 |
|
@@ -402,41 +404,37 @@ void samlLogoutShouldBeConfigured() {
|
402 | 404 | this.contextRunner.withPropertyValues(getPropertyValues(false))
|
403 | 405 | .run((context) -> assertThat(hasFilter(context, Saml2LogoutRequestFilter.class)).isTrue());
|
404 | 406 | }
|
405 |
| - |
| 407 | + |
406 | 408 | @Test
|
407 |
| - void autoconfigurationShouldWorkWithMultipleProvidersWithNoEntityId() throws Exception { |
408 |
| - try (MockWebServer server = new MockWebServer()) { |
409 |
| - server.start(); |
410 |
| - String metadataUrl = server.url("").toString(); |
411 |
| - setupMockResponse(server, new ClassPathResource("saml/idp-metadata-with-multiple-providers")); |
412 |
| - this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl) |
413 |
| - .run((context) -> { |
414 |
| - assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class); |
415 |
| - assertThat(server.getRequestCount()).isOne(); |
416 |
| - RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class); |
417 |
| - RelyingPartyRegistration registration = repository.findByRegistrationId("foo"); |
418 |
| - assertThat(registration.getAssertingPartyDetails().getEntityId()) |
419 |
| - .isEqualTo("https://idp.example.com/idp/shibboleth"); |
420 |
| - }); |
421 |
| - } |
| 409 | + void autoconfigurationWhenMultipleProvidersAndNoSpecifiedEntityId() throws Exception { |
| 410 | + testMultipleProviders(null, "https://idp.example.com/idp/shibboleth"); |
422 | 411 | }
|
423 |
| - |
| 412 | + |
424 | 413 | @Test
|
425 |
| - void autoconfigurationShouldWorkWithMultipleProviders() throws Exception { |
| 414 | + void autoconfigurationWhenMultipleProvidersAndSpecifiedEntityId() throws Exception { |
| 415 | + testMultipleProviders("https://idp.example.com/idp/shibboleth", "https://idp.example.com/idp/shibboleth"); |
| 416 | + testMultipleProviders("https://idp2.example.com/idp/shibboleth", "https://idp2.example.com/idp/shibboleth"); |
| 417 | + } |
| 418 | + |
| 419 | + private void testMultipleProviders(String specifiedEntityId, String expected) throws IOException, Exception { |
426 | 420 | try (MockWebServer server = new MockWebServer()) {
|
427 | 421 | server.start();
|
428 | 422 | String metadataUrl = server.url("").toString();
|
429 | 423 | setupMockResponse(server, new ClassPathResource("saml/idp-metadata-with-multiple-providers"));
|
430 |
| - this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl, |
431 |
| - PREFIX + ".foo.assertingparty.entity-id=https://idp2.example.com/idp/shibboleth") |
432 |
| - .run((context) -> { |
433 |
| - assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class); |
434 |
| - assertThat(server.getRequestCount()).isOne(); |
435 |
| - RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class); |
436 |
| - RelyingPartyRegistration registration = repository.findByRegistrationId("foo"); |
437 |
| - assertThat(registration.getAssertingPartyDetails().getEntityId()) |
438 |
| - .isEqualTo("https://idp2.example.com/idp/shibboleth"); |
439 |
| - }); |
| 424 | + WebApplicationContextRunner contextRunner = this.contextRunner |
| 425 | + .withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl); |
| 426 | + if (specifiedEntityId != null) { |
| 427 | + contextRunner = contextRunner |
| 428 | + .withPropertyValues(PREFIX + ".foo.assertingparty.entity-id=" + specifiedEntityId); |
| 429 | + } |
| 430 | + contextRunner.run((context) -> { |
| 431 | + assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class); |
| 432 | + assertThat(server.getRequestCount()).isOne(); |
| 433 | + RelyingPartyRegistrationRepository repository = context |
| 434 | + .getBean(RelyingPartyRegistrationRepository.class); |
| 435 | + RelyingPartyRegistration registration = repository.findByRegistrationId("foo"); |
| 436 | + assertThat(registration.getAssertingPartyDetails().getEntityId()).isEqualTo(expected); |
| 437 | + }); |
440 | 438 | }
|
441 | 439 | }
|
442 | 440 |
|
|
0 commit comments