Search in sources :

Example 11 with DefaultWebFilterChain

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

the class ReactorContextWebFilterTests method filterWhenMainContextThenDoesNotOverride.

@Test
public // gh-4962
void filterWhenMainContextThenDoesNotOverride() {
    given(this.repository.load(any())).willReturn(this.securityContext.mono());
    String contextKey = "main";
    WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true));
    WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), List.of(mainContextWebFilter, this.filter));
    Mono<Void> filter = chain.filter(MockServerWebExchange.from(this.exchange.build()));
    StepVerifier.create(filter).expectAccessibleContext().hasKey(contextKey).then().verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) TestPublisher(reactor.test.publisher.TestPublisher) WebTestHandler(org.springframework.security.test.web.reactive.server.WebTestHandler) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StepVerifier(reactor.test.StepVerifier) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Mock(org.mockito.Mock) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Test(org.junit.jupiter.api.Test) List(java.util.List) ReactiveSecurityContextHolder(org.springframework.security.core.context.ReactiveSecurityContextHolder) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SecurityContext(org.springframework.security.core.context.SecurityContext) WebFilter(org.springframework.web.server.WebFilter) BDDMockito.given(org.mockito.BDDMockito.given) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) DefaultWebFilterChain(org.springframework.web.server.handler.DefaultWebFilterChain) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Authentication(org.springframework.security.core.Authentication) WebFilterChain(org.springframework.web.server.WebFilterChain) WebFilter(org.springframework.web.server.WebFilter) DefaultWebFilterChain(org.springframework.web.server.handler.DefaultWebFilterChain) WebFilterChain(org.springframework.web.server.WebFilterChain) DefaultWebFilterChain(org.springframework.web.server.handler.DefaultWebFilterChain) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultWebFilterChain (org.springframework.web.server.handler.DefaultWebFilterChain)11 Test (org.junit.jupiter.api.Test)10 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)10 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)9 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)6 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Authentication (org.springframework.security.core.Authentication)3 ReactiveSecurityContextHolder (org.springframework.security.core.context.ReactiveSecurityContextHolder)3 ServerWebExchange (org.springframework.web.server.ServerWebExchange)3 Mono (reactor.core.publisher.Mono)3 StepVerifier (reactor.test.StepVerifier)3 Collections (java.util.Collections)2 LinkedHashMap (java.util.LinkedHashMap)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 List (java.util.List)1 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1