Search in sources :

Example 11 with WebFilterExchange

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

the class HttpStatusReturningServerLogoutSuccessHandlerTests method customHttpStatusBeingReturned.

@Test
public void customHttpStatusBeingReturned() {
    WebFilterExchange filterExchange = buildFilterExchange();
    new HttpStatusReturningServerLogoutSuccessHandler(HttpStatus.NO_CONTENT).onLogoutSuccess(filterExchange, mock(Authentication.class)).block();
    assertThat(filterExchange.getExchange().getResponse().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
Also used : WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) Test(org.junit.jupiter.api.Test)

Example 12 with WebFilterExchange

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

the class HeaderWriterServerLogoutHandlerTests method logoutWhenInvokedThenWritesResponseHeaders.

@Test
public void logoutWhenInvokedThenWritesResponseHeaders() {
    ServerHttpHeadersWriter headersWriter = mock(ServerHttpHeadersWriter.class);
    HeaderWriterServerLogoutHandler handler = new HeaderWriterServerLogoutHandler(headersWriter);
    ServerWebExchange serverWebExchange = mock(ServerWebExchange.class);
    WebFilterExchange filterExchange = mock(WebFilterExchange.class);
    given(filterExchange.getExchange()).willReturn(serverWebExchange);
    Authentication authentication = mock(Authentication.class);
    handler.logout(filterExchange, authentication);
    verify(headersWriter).writeHttpHeaders(serverWebExchange);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) Authentication(org.springframework.security.core.Authentication) ServerHttpHeadersWriter(org.springframework.security.web.server.header.ServerHttpHeadersWriter) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) Test(org.junit.jupiter.api.Test)

Example 13 with WebFilterExchange

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

the class CsrfServerLogoutHandlerTests method setup.

@BeforeEach
public void setup() {
    this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
    this.filterExchange = new WebFilterExchange(this.exchange, this.filterChain);
    this.handler = new CsrfServerLogoutHandler(this.csrfTokenRepository);
}
Also used : WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with WebFilterExchange

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

the class HttpStatusReturningServerLogoutSuccessHandlerTests method buildFilterExchange.

private static WebFilterExchange buildFilterExchange() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    return new WebFilterExchange(exchange, mock(WebFilterChain.class));
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) WebFilterChain(org.springframework.web.server.WebFilterChain) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange)

Example 15 with WebFilterExchange

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

the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenNotOidcUserThenDefaults.

@Test
public void logoutWhenNotOidcUserThenDefaults() {
    OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOAuth2Users.create(), AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
    given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
    WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
    this.handler.setLogoutSuccessUrl(URI.create("https://default"));
    this.handler.onLogoutSuccess(f, token).block();
    assertThat(redirectedUrl(this.exchange)).isEqualTo("https://default");
}
Also used : OAuth2AuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) Test(org.junit.jupiter.api.Test)

Aggregations

WebFilterExchange (org.springframework.security.web.server.WebFilterExchange)17 Test (org.junit.jupiter.api.Test)13 OAuth2AuthenticationToken (org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken)8 Authentication (org.springframework.security.core.Authentication)6 ServerWebExchange (org.springframework.web.server.ServerWebExchange)5 WebFilterChain (org.springframework.web.server.WebFilterChain)5 Map (java.util.Map)4 ReactiveAuthenticationManager (org.springframework.security.authentication.ReactiveAuthenticationManager)4 AuthenticationException (org.springframework.security.core.AuthenticationException)4 AuthorityUtils (org.springframework.security.core.authority.AuthorityUtils)4 SecurityContext (org.springframework.security.core.context.SecurityContext)4 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 BDDMockito.given (org.mockito.BDDMockito.given)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.spy (org.mockito.Mockito.spy)3 Mockito.verify (org.mockito.Mockito.verify)3