|
1 | 1 | /* |
2 | | - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
37 | 37 | import org.springframework.security.oauth2.core.oidc.user.TestOidcUsers; |
38 | 38 | import org.springframework.security.oauth2.core.user.TestOAuth2Users; |
39 | 39 | import org.springframework.security.web.server.WebFilterExchange; |
| 40 | +import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler; |
40 | 41 | import org.springframework.web.server.ServerWebExchange; |
41 | 42 | import org.springframework.web.server.WebFilterChain; |
42 | 43 |
|
@@ -199,8 +200,25 @@ public void setPostLogoutRedirectUriTemplateWhenGivenNullThenThrowsException() { |
199 | 200 | assertThatIllegalArgumentException().isThrownBy(() -> this.handler.setPostLogoutRedirectUri((String) null)); |
200 | 201 | } |
201 | 202 |
|
| 203 | + @Test |
| 204 | + public void logoutWhenCustomRedirectServerLogoutSuccessHandlerSetThenRedirects() { |
| 205 | + OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), |
| 206 | + AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId()); |
| 207 | + given(this.exchange.getPrincipal()).willReturn(Mono.just(token)); |
| 208 | + WebFilterExchange filterExchange = new WebFilterExchange(this.exchange, this.chain); |
| 209 | + this.handler.setServerLogoutSuccessHandler(new TestRedirectServerLogoutSuccessHandler()); |
| 210 | + |
| 211 | + this.handler.onLogoutSuccess(filterExchange, token).block(); |
| 212 | + |
| 213 | + assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?id_token_hint=id-token"); |
| 214 | + } |
| 215 | + |
202 | 216 | private String redirectedUrl(ServerWebExchange exchange) { |
203 | 217 | return exchange.getResponse().getHeaders().getFirst("Location"); |
204 | 218 | } |
205 | 219 |
|
| 220 | + private static class TestRedirectServerLogoutSuccessHandler extends RedirectServerLogoutSuccessHandler { |
| 221 | + |
| 222 | + } |
| 223 | + |
206 | 224 | } |
0 commit comments