use of org.springframework.web.server.WebFilter 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();
}
use of org.springframework.web.server.WebFilter in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerWebFilter.
@Test
public void toHttpHandlerWebFilter() {
AtomicBoolean filterInvoked = new AtomicBoolean();
WebFilter webFilter = (exchange, chain) -> {
filterInvoked.set(true);
return chain.filter(exchange);
};
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HandlerStrategies handlerStrategies = HandlerStrategies.builder().webFilter(webFilter).build();
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, handlerStrategies);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("https://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
assertThat(filterInvoked.get()).isTrue();
}
use of org.springframework.web.server.WebFilter in project spring-boot by spring-projects.
the class ReactiveOAuth2ClientAutoConfigurationTests method hasFilter.
@SuppressWarnings("unchecked")
private boolean hasFilter(AssertableReactiveWebApplicationContext context, Class<? extends WebFilter> filter) {
SecurityWebFilterChain filterChain = (SecurityWebFilterChain) context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN);
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(filterChain, "filters");
return filters.stream().anyMatch(filter::isInstance);
}
use of org.springframework.web.server.WebFilter in project spring-boot by spring-projects.
the class WebTestClientAutoConfigurationTests method shouldApplySpringSecurityConfigurer.
@Test
@SuppressWarnings("unchecked")
void shouldApplySpringSecurityConfigurer() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient, "builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils.getField(builder, "httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder, "filters");
assertThat(filters.get(0).getClass().getName()).isEqualTo("org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers$MutatorFilter");
});
}
use of org.springframework.web.server.WebFilter in project spring-boot by spring-projects.
the class WebTestClientAutoConfigurationTests method shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath.
@Test
@SuppressWarnings("unchecked")
void shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath() {
FilteredClassLoader classLoader = new FilteredClassLoader(SecurityMockServerConfigurers.class);
this.contextRunner.withUserConfiguration(BaseConfiguration.class).withClassLoader(classLoader).run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient, "builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils.getField(builder, "httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder, "filters");
assertThat(filters).isEmpty();
});
}
Aggregations