Search in sources :

Example 1 with InMemoryReactiveOAuth2AuthorizedClientService

use of org.springframework.security.oauth2.client.InMemoryReactiveOAuth2AuthorizedClientService in project spring-security by spring-projects.

the class ServerOAuth2AuthorizedClientExchangeFilterFunctionITests method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.clientRegistrationRepository = mock(ReactiveClientRegistrationRepository.class);
    final ServerOAuth2AuthorizedClientRepository delegate = new AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository(new InMemoryReactiveOAuth2AuthorizedClientService(this.clientRegistrationRepository));
    this.authorizedClientRepository = spy(new ServerOAuth2AuthorizedClientRepository() {

        @Override
        public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, Authentication principal, ServerWebExchange exchange) {
            return delegate.loadAuthorizedClient(clientRegistrationId, principal, exchange);
        }

        @Override
        public Mono<Void> saveAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal, ServerWebExchange exchange) {
            return delegate.saveAuthorizedClient(authorizedClient, principal, exchange);
        }

        @Override
        public Mono<Void> removeAuthorizedClient(String clientRegistrationId, Authentication principal, ServerWebExchange exchange) {
            return delegate.removeAuthorizedClient(clientRegistrationId, principal, exchange);
        }
    });
    this.authorizedClientFilter = new ServerOAuth2AuthorizedClientExchangeFilterFunction(this.clientRegistrationRepository, this.authorizedClientRepository);
    this.server = new MockWebServer();
    this.server.start();
    this.serverUrl = this.server.url("/").toString();
    // @formatter:off
    this.webClient = WebClient.builder().filter(this.authorizedClientFilter).build();
    // @formatter:on
    this.authentication = new TestingAuthenticationToken("principal", "password");
    this.exchange = MockServerWebExchange.builder(MockServerHttpRequest.get("/").build()).build();
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository(org.springframework.security.oauth2.client.web.server.AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository) ServerOAuth2AuthorizedClientRepository(org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository(org.springframework.security.oauth2.client.web.server.AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository) ReactiveClientRegistrationRepository(org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository) InMemoryReactiveOAuth2AuthorizedClientService(org.springframework.security.oauth2.client.InMemoryReactiveOAuth2AuthorizedClientService) Authentication(org.springframework.security.core.Authentication) MockWebServer(okhttp3.mockwebserver.MockWebServer) OAuth2AuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MockWebServer (okhttp3.mockwebserver.MockWebServer)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 InMemoryReactiveOAuth2AuthorizedClientService (org.springframework.security.oauth2.client.InMemoryReactiveOAuth2AuthorizedClientService)1 OAuth2AuthorizedClient (org.springframework.security.oauth2.client.OAuth2AuthorizedClient)1 ReactiveClientRegistrationRepository (org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository)1 AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository (org.springframework.security.oauth2.client.web.server.AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository)1 ServerOAuth2AuthorizedClientRepository (org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1