use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class FormLoginTests method customAuthenticationManager.
@Test
public void customAuthenticationManager() {
ReactiveAuthenticationManager defaultAuthenticationManager = mock(ReactiveAuthenticationManager.class);
ReactiveAuthenticationManager customAuthenticationManager = mock(ReactiveAuthenticationManager.class);
given(defaultAuthenticationManager.authenticate(any())).willThrow(new RuntimeException("should not interact with default auth manager"));
given(customAuthenticationManager.authenticate(any())).willReturn(Mono.just(new TestingAuthenticationToken("user", "password", "ROLE_USER", "ROLE_ADMIN")));
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.authenticationManager(defaultAuthenticationManager).formLogin().authenticationManager(customAuthenticationManager).and().build();
WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
// @formatter:on
DefaultLoginPage loginPage = DefaultLoginPage.to(driver).assertAt();
// @formatter:off
HomePage homePage = loginPage.loginForm().username("user").password("password").submit(HomePage.class);
// @formatter:on
homePage.assertAt();
verifyZeroInteractions(defaultAuthenticationManager);
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class FormLoginTests method authenticationSuccess.
@Test
public void authenticationSuccess() {
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange().anyExchange().authenticated().and().formLogin().authenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler("/custom")).and().build();
WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
// @formatter:on
DefaultLoginPage loginPage = DefaultLoginPage.to(driver).assertAt();
// @formatter:off
HomePage homePage = loginPage.loginForm().username("user").password("password").submit(HomePage.class);
// @formatter:on
assertThat(driver.getCurrentUrl()).endsWith("/custom");
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class FormLoginTests method formLoginWhenCustomRequiresAuthenticationMatcherThenUsed.
@Test
public void formLoginWhenCustomRequiresAuthenticationMatcherThenUsed() {
// @formatter:off
SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange().pathMatchers("/login", "/sign-in").permitAll().anyExchange().authenticated().and().formLogin().requiresAuthenticationMatcher(new PathPatternParserServerWebExchangeMatcher("/sign-in")).and().build();
WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build();
WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
// @formatter:on
driver.get("http://localhost/sign-in");
assertThat(driver.getCurrentUrl()).endsWith("/login?error");
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class ServerHttpSecurityTests method postWhenCsrfDisabledThenPermitted.
@Test
public void postWhenCsrfDisabledThenPermitted() {
SecurityWebFilterChain securityFilterChain = this.http.csrf((csrf) -> csrf.disable()).build();
WebFilterChainProxy springSecurityFilterChain = new WebFilterChainProxy(securityFilterChain);
WebTestClient client = WebTestClientBuilder.bindToWebFilters(springSecurityFilterChain).build();
client.post().uri("/").exchange().expectStatus().isOk();
}
use of org.springframework.security.web.server.SecurityWebFilterChain in project spring-security by spring-projects.
the class ServerHttpSecurityTests method x509WhenDefaultsThenAddsX509Filter.
@Test
public void x509WhenDefaultsThenAddsX509Filter() {
this.http.x509(withDefaults());
SecurityWebFilterChain securityWebFilterChain = this.http.build();
WebFilter x509WebFilter = securityWebFilterChain.getWebFilters().filter(this::isX509Filter).blockFirst();
assertThat(x509WebFilter).isNotNull();
}
Aggregations