Search in sources :

Example 16 with WebFilterExchange

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

the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenOidcRedirectUrlConfiguredThenRedirects.

@Test
public void logoutWhenOidcRedirectUrlConfiguredThenRedirects() {
    OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.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.onLogoutSuccess(f, token).block();
    assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?id_token_hint=id-token");
}
Also used : OAuth2AuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) Test(org.junit.jupiter.api.Test)

Example 17 with WebFilterExchange

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

the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenNotOAuth2AuthenticationThenDefaults.

@Test
public void logoutWhenNotOAuth2AuthenticationThenDefaults() {
    Authentication token = mock(Authentication.class);
    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 : Authentication(org.springframework.security.core.Authentication) 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