use of org.springframework.web.server.handler.FilteringWebHandler in project spring-boot by spring-projects.
the class HttpHandlerAutoConfigurationTests method shouldConfigureWebFiltersAnnotation.
@Test
public void shouldConfigureWebFiltersAnnotation() {
load(AnnotationConfigWithWebFilters.class);
HttpHandler handler = this.context.getBean(HttpHandler.class);
assertThat(handler).isInstanceOf(WebHandler.class);
WebHandler webHandler = (WebHandler) handler;
while (webHandler instanceof WebHandlerDecorator) {
if (webHandler instanceof FilteringWebHandler) {
FilteringWebHandler filteringWebHandler = (FilteringWebHandler) webHandler;
assertThat(filteringWebHandler.getFilters()).containsExactly(this.context.getBean("firstWebFilter", WebFilter.class), this.context.getBean("aWebFilter", WebFilter.class), this.context.getBean("lastWebFilter", WebFilter.class));
return;
}
webHandler = ((WebHandlerDecorator) webHandler).getDelegate();
}
fail("Did not find any FilteringWebHandler");
}
use of org.springframework.web.server.handler.FilteringWebHandler in project spring-security by spring-projects.
the class OAuth2AuthorizationRequestRedirectWebFilterTests method filterWhenExceptionThenRedirected.
@Test
public void filterWhenExceptionThenRedirected() {
given(this.clientRepository.findByRegistrationId(this.registration.getRegistrationId())).willReturn(Mono.just(this.registration));
given(this.authzRequestRepository.saveAuthorizationRequest(any(), 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();
FluxExchangeResult<String> result = this.client.get().uri("https://example.com/foo").exchange().expectStatus().is3xxRedirection().returnResult(String.class);
// @formatter:on
}
use of org.springframework.web.server.handler.FilteringWebHandler in project spring-security by spring-projects.
the class OAuth2AuthorizationRequestRedirectWebFilterTests method setup.
@BeforeEach
public void setup() {
this.filter = new OAuth2AuthorizationRequestRedirectWebFilter(this.clientRepository);
this.filter.setAuthorizationRequestRepository(this.authzRequestRepository);
FilteringWebHandler webHandler = new FilteringWebHandler((e) -> e.getResponse().setComplete(), Arrays.asList(this.filter));
this.client = WebTestClient.bindToWebHandler(webHandler).build();
}
use of org.springframework.web.server.handler.FilteringWebHandler in project spring-framework by spring-projects.
the class WebHttpHandlerBuilder method build.
/**
* Build the {@link HttpHandler}.
*/
public HttpHandler build() {
WebHandler decorated = new FilteringWebHandler(this.webHandler, this.filters);
decorated = new ExceptionHandlingWebHandler(decorated, this.exceptionHandlers);
HttpWebHandlerAdapter adapted = new HttpWebHandlerAdapter(decorated);
if (this.sessionManager != null) {
adapted.setSessionManager(this.sessionManager);
}
if (this.codecConfigurer != null) {
adapted.setCodecConfigurer(this.codecConfigurer);
}
if (this.localeContextResolver != null) {
adapted.setLocaleContextResolver(this.localeContextResolver);
}
if (this.forwardedHeaderTransformer != null) {
adapted.setForwardedHeaderTransformer(this.forwardedHeaderTransformer);
}
if (this.applicationContext != null) {
adapted.setApplicationContext(this.applicationContext);
}
adapted.afterPropertiesSet();
return (this.httpHandlerDecorator != null ? this.httpHandlerDecorator.apply(adapted) : adapted);
}
use of org.springframework.web.server.handler.FilteringWebHandler in project spring-boot by spring-projects.
the class HttpHandlerAutoConfigurationTests method shouldConfigureWebFiltersFunctional.
@Test
public void shouldConfigureWebFiltersFunctional() {
load(FunctionalConfigWithWebFilters.class);
assertThat(this.context.getBeansOfType(HttpHandler.class).size()).isEqualTo(1);
HttpHandler handler = this.context.getBean(HttpHandler.class);
assertThat(handler).isInstanceOf(WebHandler.class);
WebHandler webHandler = (WebHandler) handler;
while (webHandler instanceof WebHandlerDecorator) {
if (webHandler instanceof FilteringWebHandler) {
FilteringWebHandler filteringWebHandler = (FilteringWebHandler) webHandler;
assertThat(filteringWebHandler.getFilters()).containsExactly(this.context.getBean("customWebFilter", WebFilter.class));
return;
}
webHandler = ((WebHandlerDecorator) webHandler).getDelegate();
}
fail("Did not find any FilteringWebHandler");
}
Aggregations