use of org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher 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.util.matcher.PathPatternParserServerWebExchangeMatcher in project spring-security by spring-projects.
the class ServerWebExchangeDelegatingReactiveAuthenticationManagerResolverTests method resolveWhenDoesNotMatchThenReturnsDefaultReactiveAuthenticationManager.
@Test
public void resolveWhenDoesNotMatchThenReturnsDefaultReactiveAuthenticationManager() {
ServerWebExchangeDelegatingReactiveAuthenticationManagerResolver resolver = ServerWebExchangeDelegatingReactiveAuthenticationManagerResolver.builder().add(new PathPatternParserServerWebExchangeMatcher("/one/**"), this.one).add(new PathPatternParserServerWebExchangeMatcher("/two/**"), this.two).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/wrong/location").build();
ReactiveAuthenticationManager authenticationManager = resolver.resolve(MockServerWebExchange.from(request)).block();
Authentication authentication = new TestingAuthenticationToken("principal", "creds");
assertThatExceptionOfType(AuthenticationServiceException.class).isThrownBy(() -> authenticationManager.authenticate(authentication).block());
}
use of org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher in project spring-security by spring-projects.
the class ServerWebExchangeDelegatingReactiveAuthenticationManagerResolverTests method resolveWhenMatchesThenReturnsReactiveAuthenticationManager.
@Test
public void resolveWhenMatchesThenReturnsReactiveAuthenticationManager() {
ServerWebExchangeDelegatingReactiveAuthenticationManagerResolver resolver = ServerWebExchangeDelegatingReactiveAuthenticationManagerResolver.builder().add(new PathPatternParserServerWebExchangeMatcher("/one/**"), this.one).add(new PathPatternParserServerWebExchangeMatcher("/two/**"), this.two).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/one/location").build();
assertThat(resolver.resolve(MockServerWebExchange.from(request)).block()).isEqualTo(this.one);
}
use of org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher in project spring-security by spring-projects.
the class ExchangeMatcherRedirectWebFilterTests method filterWhenRequestMatchThenRedirectToSpecifiedUrl.
@Test
public void filterWhenRequestMatchThenRedirectToSpecifiedUrl() {
ExchangeMatcherRedirectWebFilter filter = new ExchangeMatcherRedirectWebFilter(new PathPatternParserServerWebExchangeMatcher("/context"), "/test");
FilteringWebHandler handler = new FilteringWebHandler((e) -> e.getResponse().setComplete(), Collections.singletonList(filter));
WebTestClient client = WebTestClient.bindToWebHandler(handler).build();
client.get().uri("/context").exchange().expectStatus().isFound().expectHeader().valueEquals(HttpHeaders.LOCATION, "/test");
}
use of org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher in project spring-security by spring-projects.
the class ExchangeMatcherRedirectWebFilterTests method filterWhenRequestNotMatchThenNextFilter.
@Test
public void filterWhenRequestNotMatchThenNextFilter() {
ExchangeMatcherRedirectWebFilter filter = new ExchangeMatcherRedirectWebFilter(new PathPatternParserServerWebExchangeMatcher("/context"), "/test");
FilteringWebHandler handler = new FilteringWebHandler((e) -> e.getResponse().setComplete(), Collections.singletonList(filter));
WebTestClient client = WebTestClient.bindToWebHandler(handler).build();
client.get().uri("/test").exchange().expectStatus().isOk();
}
Aggregations