use of org.springframework.web.server.WebFilter in project spring-boot by spring-projects.
the class ReactiveOAuth2ResourceServerAutoConfigurationTests method assertFilterConfiguredWithJwtAuthenticationManager.
private void assertFilterConfiguredWithJwtAuthenticationManager(AssertableReactiveWebApplicationContext context) {
MatcherSecurityWebFilterChain filterChain = (MatcherSecurityWebFilterChain) context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN);
Stream<WebFilter> filters = filterChain.getWebFilters().toStream();
AuthenticationWebFilter webFilter = (AuthenticationWebFilter) filters.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null);
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils.getField(webFilter, "authenticationManagerResolver");
Object authenticationManager = authenticationManagerResolver.resolve(null).block();
assertThat(authenticationManager).isInstanceOf(JwtReactiveAuthenticationManager.class);
}
use of org.springframework.web.server.WebFilter in project spring-boot by spring-projects.
the class ReactiveOAuth2ResourceServerAutoConfigurationTests method assertFilterConfiguredWithOpaqueTokenAuthenticationManager.
private void assertFilterConfiguredWithOpaqueTokenAuthenticationManager(AssertableReactiveWebApplicationContext context) {
MatcherSecurityWebFilterChain filterChain = (MatcherSecurityWebFilterChain) context.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN);
Stream<WebFilter> filters = filterChain.getWebFilters().toStream();
AuthenticationWebFilter webFilter = (AuthenticationWebFilter) filters.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null);
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils.getField(webFilter, "authenticationManagerResolver");
Object authenticationManager = authenticationManagerResolver.resolve(null).block();
assertThat(authenticationManager).isInstanceOf(OpaqueTokenReactiveAuthenticationManager.class);
}
use of org.springframework.web.server.WebFilter in project spring-security by spring-projects.
the class ServerHttpSecurityTests method addFilterBeforeIsApplied.
@Test
@SuppressWarnings("unchecked")
public void addFilterBeforeIsApplied() {
SecurityWebFilterChain securityWebFilterChain = this.http.addFilterBefore(new TestWebFilter(), SecurityWebFiltersOrder.SECURITY_CONTEXT_SERVER_WEB_EXCHANGE).build();
// @formatter:off
List filters = securityWebFilterChain.getWebFilters().map(WebFilter::getClass).collectList().block();
// @formatter:on
assertThat(filters).isNotNull().isNotEmpty().containsSequence(TestWebFilter.class, SecurityContextServerWebExchangeWebFilter.class);
}
use of org.springframework.web.server.WebFilter in project spring-security by spring-projects.
the class ServerHttpSecurityTests method x509WhenCustomizedThenAddsX509Filter.
@Test
public void x509WhenCustomizedThenAddsX509Filter() {
X509PrincipalExtractor mockExtractor = mock(X509PrincipalExtractor.class);
ReactiveAuthenticationManager mockAuthenticationManager = mock(ReactiveAuthenticationManager.class);
this.http.x509((x509) -> x509.principalExtractor(mockExtractor).authenticationManager(mockAuthenticationManager));
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-security by spring-projects.
the class EnableWebFluxSecurityTests method defaultPopulatesReactorContext.
@Test
public void defaultPopulatesReactorContext() {
this.spring.register(Config.class).autowire();
Authentication currentPrincipal = new TestingAuthenticationToken("user", "password", "ROLE_USER");
WebSessionServerSecurityContextRepository contextRepository = new WebSessionServerSecurityContextRepository();
SecurityContext context = new SecurityContextImpl(currentPrincipal);
// @formatter:off
WebFilter contextRepositoryWebFilter = (exchange, chain) -> contextRepository.save(exchange, context).switchIfEmpty(chain.filter(exchange)).flatMap((e) -> chain.filter(exchange));
WebTestClient client = WebTestClientBuilder.bindToWebFilters(contextRepositoryWebFilter, this.springSecurityFilterChain, writePrincipalWebFilter()).build();
client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).consumeWith((result) -> assertThat(result.getResponseBody()).isEqualTo(currentPrincipal.getName()));
// @formatter:on
}
Aggregations