Search in sources :

Example 6 with FilteringWebHandler

use of org.springframework.web.server.handler.FilteringWebHandler in project spring-security by spring-projects.

the class OAuth2AuthorizationRequestRedirectWebFilterTests method filterWhenExceptionThenSaveRequestSessionAttribute.

@Test
public void filterWhenExceptionThenSaveRequestSessionAttribute() {
    given(this.clientRepository.findByRegistrationId(this.registration.getRegistrationId())).willReturn(Mono.just(this.registration));
    given(this.authzRequestRepository.saveAuthorizationRequest(any(), any())).willReturn(Mono.empty());
    this.filter.setRequestCache(this.requestCache);
    given(this.requestCache.saveRequest(any())).willReturn(Mono.empty());
    FilteringWebHandler webHandler = new FilteringWebHandler((e) -> Mono.error(new ClientAuthorizationRequiredException(this.registration.getRegistrationId())), Arrays.asList(this.filter));
    // @formatter:off
    this.client = WebTestClient.bindToWebHandler(webHandler).build();
    this.client.get().uri("https://example.com/foo").exchange().expectStatus().is3xxRedirection().returnResult(String.class);
    // @formatter:on
    verify(this.requestCache).saveRequest(any());
}
Also used : FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) ClientAuthorizationRequiredException(org.springframework.security.oauth2.client.ClientAuthorizationRequiredException) Test(org.junit.jupiter.api.Test)

Example 7 with FilteringWebHandler

use of org.springframework.web.server.handler.FilteringWebHandler 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");
}
Also used : PathPatternParserServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) Test(org.junit.jupiter.api.Test)

Example 8 with FilteringWebHandler

use of org.springframework.web.server.handler.FilteringWebHandler 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();
}
Also used : PathPatternParserServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) Test(org.junit.jupiter.api.Test)

Aggregations

FilteringWebHandler (org.springframework.web.server.handler.FilteringWebHandler)8 Test (org.junit.jupiter.api.Test)4 WebHandler (org.springframework.web.server.WebHandler)3 Test (org.junit.Test)2 HttpHandler (org.springframework.http.server.reactive.HttpHandler)2 ClientAuthorizationRequiredException (org.springframework.security.oauth2.client.ClientAuthorizationRequiredException)2 PathPatternParserServerWebExchangeMatcher (org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher)2 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)2 WebFilter (org.springframework.web.server.WebFilter)2 WebHandlerDecorator (org.springframework.web.server.handler.WebHandlerDecorator)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ExceptionHandlingWebHandler (org.springframework.web.server.handler.ExceptionHandlingWebHandler)1