|
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;
|
@@ -117,4 +118,45 @@ public void customLogout() {
|
117 | 118 | .assertAt()
|
118 | 119 | .assertLogout();
|
119 | 120 | }
|
| 121 | + |
| 122 | + @Test |
| 123 | + public void logoutWhenCustomSecurityContextRepositoryThenLogsOut() { |
| 124 | + WebSessionServerSecurityContextRepository repository = new WebSessionServerSecurityContextRepository(); |
| 125 | + repository.setSpringSecurityContextAttrName("CUSTOM_CONTEXT_ATTR"); |
| 126 | + SecurityWebFilterChain securityWebFilter = this.http |
| 127 | + .securityContextRepository(repository) |
| 128 | + .authorizeExchange() |
| 129 | + .anyExchange().authenticated() |
| 130 | + .and() |
| 131 | + .formLogin() |
| 132 | + .and() |
| 133 | + .logout() |
| 134 | + .and() |
| 135 | + .build(); |
| 136 | + |
| 137 | + WebTestClient webTestClient = WebTestClientBuilder |
| 138 | + .bindToWebFilters(securityWebFilter) |
| 139 | + .build(); |
| 140 | + |
| 141 | + WebDriver driver = WebTestClientHtmlUnitDriverBuilder |
| 142 | + .webTestClientSetup(webTestClient) |
| 143 | + .build(); |
| 144 | + |
| 145 | + FormLoginTests.DefaultLoginPage loginPage = FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
| 146 | + .assertAt(); |
| 147 | + |
| 148 | + FormLoginTests.HomePage homePage = loginPage.loginForm() |
| 149 | + .username("user") |
| 150 | + .password("password") |
| 151 | + .submit(FormLoginTests.HomePage.class); |
| 152 | + |
| 153 | + homePage.assertAt(); |
| 154 | + |
| 155 | + FormLoginTests.DefaultLogoutPage.to(driver) |
| 156 | + .assertAt() |
| 157 | + .logout(); |
| 158 | + |
| 159 | + FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
| 160 | + .assertAt(); |
| 161 | + } |
120 | 162 | }
|
0 commit comments