|
85 | 85 | import org.springframework.test.web.servlet.MockMvc;
|
86 | 86 | import org.springframework.test.web.servlet.MvcResult;
|
87 | 87 | import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
88 |
| -import org.springframework.util.StringUtils; |
89 | 88 | import org.springframework.web.bind.annotation.GetMapping;
|
90 | 89 | import org.springframework.web.bind.annotation.PostMapping;
|
91 | 90 | import org.springframework.web.bind.annotation.RequestParam;
|
@@ -261,6 +260,22 @@ void logoutWhenCustomComponentsThenUses() throws Exception {
|
261 | 260 | verify(sessionRegistry).removeSessionInformation(any(OidcLogoutToken.class));
|
262 | 261 | }
|
263 | 262 |
|
| 263 | + @Test |
| 264 | + void logoutWhenProviderIssuerMissingThenThrowIllegalArgumentException() throws Exception { |
| 265 | + this.spring.register(WebServerConfig.class, OidcProviderConfig.class, ProviderIssuerMissingConfig.class) |
| 266 | + .autowire(); |
| 267 | + String registrationId = this.clientRegistration.getRegistrationId(); |
| 268 | + MockHttpSession session = login(); |
| 269 | + String logoutToken = this.mvc.perform(get("/token/logout").session(session)) |
| 270 | + .andExpect(status().isOk()) |
| 271 | + .andReturn() |
| 272 | + .getResponse() |
| 273 | + .getContentAsString(); |
| 274 | + assertThatIllegalArgumentException().isThrownBy( |
| 275 | + () -> this.mvc.perform(post(this.web.url("/logout/connect/back-channel/" + registrationId).toString()) |
| 276 | + .param("logout_token", logoutToken))); |
| 277 | + } |
| 278 | + |
264 | 279 | private MockHttpSession login() throws Exception {
|
265 | 280 | MockMvcDispatcher dispatcher = (MockMvcDispatcher) this.web.getDispatcher();
|
266 | 281 | this.mvc.perform(get("/token/logout")).andExpect(status().isUnauthorized());
|
@@ -412,6 +427,54 @@ LogoutHandler logoutHandler() {
|
412 | 427 |
|
413 | 428 | }
|
414 | 429 |
|
| 430 | + @Configuration |
| 431 | + static class ProviderIssuerMissingRegistrationConfig { |
| 432 | + |
| 433 | + @Autowired(required = false) |
| 434 | + MockWebServer web; |
| 435 | + |
| 436 | + @Bean |
| 437 | + ClientRegistration clientRegistration() { |
| 438 | + if (this.web == null) { |
| 439 | + return TestClientRegistrations.clientRegistration().issuerUri(null).build(); |
| 440 | + } |
| 441 | + String issuer = this.web.url("/").toString(); |
| 442 | + return TestClientRegistrations.clientRegistration() |
| 443 | + .issuerUri(null) |
| 444 | + .jwkSetUri(issuer + "jwks") |
| 445 | + .tokenUri(issuer + "token") |
| 446 | + .userInfoUri(issuer + "user") |
| 447 | + .scope("openid") |
| 448 | + .build(); |
| 449 | + } |
| 450 | + |
| 451 | + @Bean |
| 452 | + ClientRegistrationRepository clientRegistrationRepository(ClientRegistration clientRegistration) { |
| 453 | + return new InMemoryClientRegistrationRepository(clientRegistration); |
| 454 | + } |
| 455 | + |
| 456 | + } |
| 457 | + |
| 458 | + @Configuration |
| 459 | + @EnableWebSecurity |
| 460 | + @Import(ProviderIssuerMissingRegistrationConfig.class) |
| 461 | + static class ProviderIssuerMissingConfig { |
| 462 | + |
| 463 | + @Bean |
| 464 | + @Order(1) |
| 465 | + SecurityFilterChain filters(HttpSecurity http) throws Exception { |
| 466 | + // @formatter:off |
| 467 | + http |
| 468 | + .authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated()) |
| 469 | + .oauth2Login(Customizer.withDefaults()) |
| 470 | + .oidcLogout((oidc) -> oidc.backChannel(Customizer.withDefaults())); |
| 471 | + // @formatter:on |
| 472 | + |
| 473 | + return http.build(); |
| 474 | + } |
| 475 | + |
| 476 | + } |
| 477 | + |
415 | 478 | @Configuration
|
416 | 479 | @EnableWebSecurity
|
417 | 480 | @EnableWebMvc
|
@@ -650,69 +713,4 @@ private String getContentAsString(MockHttpServletResponse response) {
|
650 | 713 |
|
651 | 714 | }
|
652 | 715 |
|
653 |
| - @Test |
654 |
| - void logoutWhenProviderIssuerMissingThenThrowIllegalArgumentException() throws Exception { |
655 |
| - this.spring.register(WebServerConfig.class, OidcProviderConfig.class, ProviderIssuerMissingConfig.class).autowire(); |
656 |
| - String registrationId = this.clientRegistration.getRegistrationId(); |
657 |
| - MockHttpSession session = login(); |
658 |
| - String logoutToken = this.mvc.perform(get("/token/logout").session(session)) |
659 |
| - .andExpect(status().isOk()) |
660 |
| - .andReturn() |
661 |
| - .getResponse() |
662 |
| - .getContentAsString(); |
663 |
| - assertThatIllegalArgumentException().isThrownBy(() -> { |
664 |
| - this.mvc |
665 |
| - .perform(post(this.web.url("/logout/connect/back-channel/" + registrationId).toString()) |
666 |
| - .param("logout_token", logoutToken)); |
667 |
| - }); |
668 |
| - } |
669 |
| - |
670 |
| - @Configuration |
671 |
| - static class ProviderIssuerMissingRegistrationConfig { |
672 |
| - |
673 |
| - @Autowired(required = false) |
674 |
| - MockWebServer web; |
675 |
| - |
676 |
| - @Bean |
677 |
| - ClientRegistration clientRegistration() { |
678 |
| - if (this.web == null) { |
679 |
| - return TestClientRegistrations.clientRegistration().issuerUri(null).build(); |
680 |
| - } |
681 |
| - String issuer = this.web.url("/").toString(); |
682 |
| - return TestClientRegistrations.clientRegistration() |
683 |
| - .issuerUri(null) |
684 |
| - .jwkSetUri(issuer + "jwks") |
685 |
| - .tokenUri(issuer + "token") |
686 |
| - .userInfoUri(issuer + "user") |
687 |
| - .scope("openid") |
688 |
| - .build(); |
689 |
| - } |
690 |
| - |
691 |
| - @Bean |
692 |
| - ClientRegistrationRepository clientRegistrationRepository(ClientRegistration clientRegistration) { |
693 |
| - return new InMemoryClientRegistrationRepository(clientRegistration); |
694 |
| - } |
695 |
| - |
696 |
| - } |
697 |
| - |
698 |
| - @Configuration |
699 |
| - @EnableWebSecurity |
700 |
| - @Import(ProviderIssuerMissingRegistrationConfig.class) |
701 |
| - static class ProviderIssuerMissingConfig { |
702 |
| - |
703 |
| - @Bean |
704 |
| - @Order(1) |
705 |
| - SecurityFilterChain filters(HttpSecurity http) throws Exception { |
706 |
| - // @formatter:off |
707 |
| - http |
708 |
| - .authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated()) |
709 |
| - .oauth2Login(Customizer.withDefaults()) |
710 |
| - .oidcLogout((oidc) -> oidc.backChannel(Customizer.withDefaults())); |
711 |
| - // @formatter:on |
712 |
| - |
713 |
| - return http.build(); |
714 |
| - } |
715 |
| - |
716 |
| - } |
717 |
| - |
718 | 716 | }
|
0 commit comments