Class AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
- java.lang.Object
-
- org.springframework.security.oauth2.client.AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
-
- All Implemented Interfaces:
ReactiveOAuth2AuthorizedClientManager
public final class AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager extends java.lang.Object implements ReactiveOAuth2AuthorizedClientManager
An implementation of aReactiveOAuth2AuthorizedClientManagerthat is capable of operating outside of the context of aServerWebExchange, e.g. in a scheduled/background thread and/or in the service-tier.(When operating within the context of a
ServerWebExchange, useDefaultReactiveOAuth2AuthorizedClientManagerinstead.)This is a reactive equivalent of
AuthorizedClientServiceOAuth2AuthorizedClientManager.Authorized Client Persistence
This client manager utilizes a
ReactiveOAuth2AuthorizedClientServiceto persistOAuth2AuthorizedClients.By default, when an authorization attempt succeeds, the
OAuth2AuthorizedClientwill be saved in the authorized client service. This functionality can be changed by configuring a customReactiveOAuth2AuthorizationSuccessHandlerviasetAuthorizationSuccessHandler(ReactiveOAuth2AuthorizationSuccessHandler).By default, when an authorization attempt fails due to an "invalid_grant" error, the previously saved
OAuth2AuthorizedClientwill be removed from the authorized client service. (The "invalid_grant" error generally occurs when a refresh token that is no longer valid is used to retrieve a new access token.) This functionality can be changed by configuring a customReactiveOAuth2AuthorizationFailureHandlerviasetAuthorizationFailureHandler(ReactiveOAuth2AuthorizationFailureHandler).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.DefaultContextAttributesMapperThe default implementation of thecontextAttributesMapper.
-
Constructor Summary
Constructors Constructor Description AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(ReactiveClientRegistrationRepository clientRegistrationRepository, ReactiveOAuth2AuthorizedClientService authorizedClientService)Constructs anAuthorizedClientServiceReactiveOAuth2AuthorizedClientManagerusing the provided parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description reactor.core.publisher.Mono<OAuth2AuthorizedClient>authorize(OAuth2AuthorizeRequest authorizeRequest)Attempt to authorize or re-authorize (if required) theclientidentified by the providedclientRegistrationId.voidsetAuthorizationFailureHandler(ReactiveOAuth2AuthorizationFailureHandler authorizationFailureHandler)Sets the handler that handles authorization failures.voidsetAuthorizationSuccessHandler(ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler)Sets the handler that handles successful authorizations.voidsetAuthorizedClientProvider(ReactiveOAuth2AuthorizedClientProvider authorizedClientProvider)Sets theReactiveOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client.voidsetContextAttributesMapper(java.util.function.Function<OAuth2AuthorizeRequest,reactor.core.publisher.Mono<java.util.Map<java.lang.String,java.lang.Object>>> contextAttributesMapper)Sets theFunctionused for mapping attribute(s) from theOAuth2AuthorizeRequestto aMapof attributes to be associated to theauthorization context.
-
-
-
Constructor Detail
-
AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
public AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(ReactiveClientRegistrationRepository clientRegistrationRepository, ReactiveOAuth2AuthorizedClientService authorizedClientService)
Constructs anAuthorizedClientServiceReactiveOAuth2AuthorizedClientManagerusing the provided parameters.- Parameters:
clientRegistrationRepository- the repository of client registrationsauthorizedClientService- the authorized client service
-
-
Method Detail
-
authorize
public reactor.core.publisher.Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizeRequest authorizeRequest)
Description copied from interface:ReactiveOAuth2AuthorizedClientManagerAttempt to authorize or re-authorize (if required) theclientidentified by the providedclientRegistrationId. Implementations must return an emptyMonoif authorization is not supported for the specified client, e.g. the associatedReactiveOAuth2AuthorizedClientProvider(s) does not support theauthorization granttype configured for the client.In the case of re-authorization, implementations must return the provided
authorized clientif re-authorization is not supported for the client OR is not required, e.g. arefresh tokenis not available OR theaccess tokenis not expired.- Specified by:
authorizein interfaceReactiveOAuth2AuthorizedClientManager- Parameters:
authorizeRequest- the authorize request- Returns:
- the
OAuth2AuthorizedClientor an emptyMonoif authorization is not supported for the specified client
-
setAuthorizedClientProvider
public void setAuthorizedClientProvider(ReactiveOAuth2AuthorizedClientProvider authorizedClientProvider)
Sets theReactiveOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client.- Parameters:
authorizedClientProvider- theReactiveOAuth2AuthorizedClientProviderused for authorizing (or re-authorizing) an OAuth 2.0 Client
-
setContextAttributesMapper
public void setContextAttributesMapper(java.util.function.Function<OAuth2AuthorizeRequest,reactor.core.publisher.Mono<java.util.Map<java.lang.String,java.lang.Object>>> contextAttributesMapper)
Sets theFunctionused for mapping attribute(s) from theOAuth2AuthorizeRequestto aMapof attributes to be associated to theauthorization context.- Parameters:
contextAttributesMapper- theFunctionused for supplying theMapof attributes to theauthorization context
-
setAuthorizationSuccessHandler
public void setAuthorizationSuccessHandler(ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler)
Sets the handler that handles successful authorizations. The default savesOAuth2AuthorizedClients in theReactiveOAuth2AuthorizedClientService.- Parameters:
authorizationSuccessHandler- the handler that handles successful authorizations.- Since:
- 5.3
-
setAuthorizationFailureHandler
public void setAuthorizationFailureHandler(ReactiveOAuth2AuthorizationFailureHandler authorizationFailureHandler)
Sets the handler that handles authorization failures.A
RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandleris used by default.- Parameters:
authorizationFailureHandler- the handler that handles authorization failures.- Since:
- 5.3
- See Also:
RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler
-
-