|
21 | 21 | import org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfigurationBuilder;
|
22 | 22 | import org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder;
|
23 | 23 | import org.springframework.security.web.server.SecurityWebFilterChain;
|
| 24 | +import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository; |
24 | 25 | import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
|
25 | 26 | import org.springframework.test.web.reactive.server.WebTestClient;
|
26 | 27 | import org.springframework.security.test.web.reactive.server.WebTestClientBuilder;
|
@@ -200,4 +201,46 @@ public void logoutWhenDisabledThenPostToLogoutDoesNothing() {
|
200 | 201 | homePage
|
201 | 202 | .assertAt();
|
202 | 203 | }
|
| 204 | + |
| 205 | + |
| 206 | + @Test |
| 207 | + public void logoutWhenCustomSecurityContextRepositoryThenLogsOut() { |
| 208 | + WebSessionServerSecurityContextRepository repository = new WebSessionServerSecurityContextRepository(); |
| 209 | + repository.setSpringSecurityContextAttrName("CUSTOM_CONTEXT_ATTR"); |
| 210 | + SecurityWebFilterChain securityWebFilter = this.http |
| 211 | + .securityContextRepository(repository) |
| 212 | + .authorizeExchange() |
| 213 | + .anyExchange().authenticated() |
| 214 | + .and() |
| 215 | + .formLogin() |
| 216 | + .and() |
| 217 | + .logout() |
| 218 | + .and() |
| 219 | + .build(); |
| 220 | + |
| 221 | + WebTestClient webTestClient = WebTestClientBuilder |
| 222 | + .bindToWebFilters(securityWebFilter) |
| 223 | + .build(); |
| 224 | + |
| 225 | + WebDriver driver = WebTestClientHtmlUnitDriverBuilder |
| 226 | + .webTestClientSetup(webTestClient) |
| 227 | + .build(); |
| 228 | + |
| 229 | + FormLoginTests.DefaultLoginPage loginPage = FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
| 230 | + .assertAt(); |
| 231 | + |
| 232 | + FormLoginTests.HomePage homePage = loginPage.loginForm() |
| 233 | + .username("user") |
| 234 | + .password("password") |
| 235 | + .submit(FormLoginTests.HomePage.class); |
| 236 | + |
| 237 | + homePage.assertAt(); |
| 238 | + |
| 239 | + FormLoginTests.DefaultLogoutPage.to(driver) |
| 240 | + .assertAt() |
| 241 | + .logout(); |
| 242 | + |
| 243 | + FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
| 244 | + .assertAt(); |
| 245 | + } |
203 | 246 | }
|
0 commit comments