Add FormLoginBuilder.serverAuthenticationSuccessHandler

Fixes: gh-4786
This commit is contained in:
Rob Winch
2017-11-03 08:47:59 -05:00
parent 1d4c7da1e1
commit 21aec19d42
2 changed files with 43 additions and 1 deletions

View File

@@ -29,8 +29,10 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder;
import org.springframework.security.test.web.reactive.server.WebTestClientBuilder;
import org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapperTests;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.WebFilterChainProxy;
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;
import org.springframework.stereotype.Controller;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.bind.annotation.GetMapping;
@@ -119,6 +121,36 @@ public class FormLoginTests {
homePage.assertAt();
}
@Test
public void authenticationSuccess() {
SecurityWebFilterChain securityWebFilter = this.http
.authorizeExchange()
.anyExchange().authenticated()
.and()
.formLogin()
.serverAuthenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler("/custom"))
.and()
.build();
WebTestClient webTestClient = WebTestClientBuilder
.bindToWebFilters(securityWebFilter)
.build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder
.webTestClientSetup(webTestClient)
.build();
DefaultLoginPage loginPage = HomePage.to(driver, DefaultLoginPage.class)
.assertAt();
HomePage homePage = loginPage.loginForm()
.username("user")
.password("password")
.submit(HomePage.class);
assertThat(driver.getCurrentUrl()).endsWith("/custom");
}
public static class CustomLoginPage {
private WebDriver driver;