|
33 | 33 | import org.springframework.security.test.web.reactive.server.WebTestClientBuilder;
|
34 | 34 | import org.springframework.security.web.server.SecurityWebFilterChain;
|
35 | 35 | import org.springframework.security.web.server.WebFilterChainProxy;
|
| 36 | +import org.springframework.security.web.server.authentication.RedirectServerAuthenticationFailureHandler; |
36 | 37 | import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;
|
37 | 38 | import org.springframework.security.web.server.context.ServerSecurityContextRepository;
|
38 | 39 | import org.springframework.security.web.server.csrf.CsrfToken;
|
@@ -213,6 +214,37 @@ public void formLoginWhenCustomLoginPageInLambdaThenUsed() {
|
213 | 214 | homePage.assertAt();
|
214 | 215 | }
|
215 | 216 |
|
| 217 | + @Test |
| 218 | + public void formLoginWhenCustomAuthenticationFailureHandlerThenUsed() { |
| 219 | + SecurityWebFilterChain securityWebFilter = this.http |
| 220 | + .authorizeExchange() |
| 221 | + .pathMatchers("/login", "/failure").permitAll() |
| 222 | + .anyExchange().authenticated() |
| 223 | + .and() |
| 224 | + .formLogin() |
| 225 | + .authenticationFailureHandler(new RedirectServerAuthenticationFailureHandler("/failure")) |
| 226 | + .and() |
| 227 | + .build(); |
| 228 | + |
| 229 | + WebTestClient webTestClient = WebTestClientBuilder |
| 230 | + .bindToWebFilters(securityWebFilter) |
| 231 | + .build(); |
| 232 | + |
| 233 | + WebDriver driver = WebTestClientHtmlUnitDriverBuilder |
| 234 | + .webTestClientSetup(webTestClient) |
| 235 | + .build(); |
| 236 | + |
| 237 | + DefaultLoginPage loginPage = HomePage.to(driver, DefaultLoginPage.class) |
| 238 | + .assertAt(); |
| 239 | + |
| 240 | + loginPage.loginForm() |
| 241 | + .username("invalid") |
| 242 | + .password("invalid") |
| 243 | + .submit(HomePage.class); |
| 244 | + |
| 245 | + assertThat(driver.getCurrentUrl()).endsWith("/failure"); |
| 246 | + } |
| 247 | + |
216 | 248 | @Test
|
217 | 249 | public void authenticationSuccess() {
|
218 | 250 | SecurityWebFilterChain securityWebFilter = this.http
|
|
0 commit comments