Search in sources :

Example 6 with ServerOAuth2AuthorizedClientRepository

use of org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository in project spring-security by spring-projects.

the class ServerOAuth2AuthorizedClientExchangeFilterFunction method createDefaultAuthorizedClientManager.

private static ReactiveOAuth2AuthorizedClientManager createDefaultAuthorizedClientManager(ReactiveClientRegistrationRepository clientRegistrationRepository, ServerOAuth2AuthorizedClientRepository authorizedClientRepository, ReactiveOAuth2AuthorizationFailureHandler authorizationFailureHandler) {
    // gh-7544
    if (authorizedClientRepository instanceof UnAuthenticatedServerOAuth2AuthorizedClientRepository) {
        UnAuthenticatedReactiveOAuth2AuthorizedClientManager unauthenticatedAuthorizedClientManager = new UnAuthenticatedReactiveOAuth2AuthorizedClientManager(clientRegistrationRepository, (UnAuthenticatedServerOAuth2AuthorizedClientRepository) authorizedClientRepository, authorizationFailureHandler);
        unauthenticatedAuthorizedClientManager.setAuthorizedClientProvider(ReactiveOAuth2AuthorizedClientProviderBuilder.builder().authorizationCode().refreshToken().clientCredentials().password().build());
        return unauthenticatedAuthorizedClientManager;
    }
    DefaultReactiveOAuth2AuthorizedClientManager authorizedClientManager = new DefaultReactiveOAuth2AuthorizedClientManager(clientRegistrationRepository, authorizedClientRepository);
    authorizedClientManager.setAuthorizationFailureHandler(authorizationFailureHandler);
    return authorizedClientManager;
}
Also used : UnAuthenticatedServerOAuth2AuthorizedClientRepository(org.springframework.security.oauth2.client.web.server.UnAuthenticatedServerOAuth2AuthorizedClientRepository) DefaultReactiveOAuth2AuthorizedClientManager(org.springframework.security.oauth2.client.web.DefaultReactiveOAuth2AuthorizedClientManager)

Aggregations

ServerOAuth2AuthorizedClientRepository (org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository)5 Test (org.junit.jupiter.api.Test)4 ReactiveClientRegistrationRepository (org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository)3 InMemoryReactiveClientRegistrationRepository (org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository)2 UnAuthenticatedServerOAuth2AuthorizedClientRepository (org.springframework.security.oauth2.client.web.server.UnAuthenticatedServerOAuth2AuthorizedClientRepository)2 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 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)1 DefaultReactiveOAuth2AuthorizedClientManager (org.springframework.security.oauth2.client.web.DefaultReactiveOAuth2AuthorizedClientManager)1 AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository (org.springframework.security.oauth2.client.web.server.AuthenticatedPrincipalServerOAuth2AuthorizedClientRepository)1 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)1 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 ServerRequestCache (org.springframework.security.web.server.savedrequest.ServerRequestCache)1 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)1