use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class ExceptionHandlingSpecTests method defaultAuthenticationEntryPoint.
@Test
public void defaultAuthenticationEntryPoint() {
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.csrf().disable().authorizeExchange().anyExchange().authenticated().and().exceptionHandling().and().build();
WebTestClient client = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
client.get().uri("/test").exchange().expectStatus().isUnauthorized().expectHeader().valueMatches("WWW-Authenticate", "Basic.*");
// @formatter:on
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class LogoutSpecTests method defaultLogout.
@Test
public void defaultLogout() {
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange().anyExchange().authenticated().and().formLogin().and().build();
WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
// @formatter:on
FormLoginTests.DefaultLoginPage loginPage = FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class).assertAt();
// @formatter:off
loginPage = loginPage.loginForm().username("user").password("invalid").submit(FormLoginTests.DefaultLoginPage.class).assertError();
FormLoginTests.HomePage homePage = loginPage.loginForm().username("user").password("password").submit(FormLoginTests.HomePage.class);
// @formatter:on
homePage.assertAt();
loginPage = FormLoginTests.DefaultLogoutPage.to(driver).assertAt().logout();
loginPage.assertAt().assertLogout();
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class LogoutSpecTests method logoutWhenCustomLogoutInLambdaThenCustomLogoutUsed.
@Test
public void logoutWhenCustomLogoutInLambdaThenCustomLogoutUsed() {
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange((exchange) -> exchange.anyExchange().authenticated()).formLogin(withDefaults()).logout((logout) -> logout.requiresLogout(ServerWebExchangeMatchers.pathMatchers("/custom-logout"))).build();
WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
// @formatter:on
FormLoginTests.DefaultLoginPage loginPage = FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class).assertAt();
// @formatter:off
loginPage = loginPage.loginForm().username("user").password("invalid").submit(FormLoginTests.DefaultLoginPage.class).assertError();
FormLoginTests.HomePage homePage = loginPage.loginForm().username("user").password("password").submit(FormLoginTests.HomePage.class);
// @formatter:on
homePage.assertAt();
driver.get("http://localhost/custom-logout");
FormLoginTests.DefaultLoginPage.create(driver).assertAt().assertLogout();
}
Aggregations