Class AuthenticatedPrincipalOAuth2AuthorizedClientRepository
java.lang.Object
org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository
- All Implemented Interfaces:
OAuth2AuthorizedClientRepository
public final class AuthenticatedPrincipalOAuth2AuthorizedClientRepository
extends Object
implements OAuth2AuthorizedClientRepository
An implementation of an
OAuth2AuthorizedClientRepository
that delegates to the
provided OAuth2AuthorizedClientService
if the current Principal
is
authenticated, otherwise, to the default (or provided)
OAuth2AuthorizedClientRepository
if the current request is unauthenticated (or
anonymous). The default OAuth2AuthorizedClientRepository
is
HttpSessionOAuth2AuthorizedClientRepository
.-
Constructor Summary
ConstructorDescriptionAuthenticatedPrincipalOAuth2AuthorizedClientRepository
(OAuth2AuthorizedClientService authorizedClientService) Constructs aAuthenticatedPrincipalOAuth2AuthorizedClientRepository
using the provided parameters. -
Method Summary
Modifier and TypeMethodDescription<T extends OAuth2AuthorizedClient>
TloadAuthorizedClient
(String clientRegistrationId, Authentication principal, jakarta.servlet.http.HttpServletRequest request) Returns theOAuth2AuthorizedClient
associated to the provided client registration identifier and End-UserAuthentication
(Resource Owner) ornull
if not available.void
removeAuthorizedClient
(String clientRegistrationId, Authentication principal, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Removes theOAuth2AuthorizedClient
associated to the provided client registration identifier and End-UserAuthentication
(Resource Owner).void
saveAuthorizedClient
(OAuth2AuthorizedClient authorizedClient, Authentication principal, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Saves theOAuth2AuthorizedClient
associating it to the provided End-UserAuthentication
(Resource Owner).void
setAnonymousAuthorizedClientRepository
(OAuth2AuthorizedClientRepository anonymousAuthorizedClientRepository) Sets theOAuth2AuthorizedClientRepository
used for requests that are unauthenticated (or anonymous).
-
Constructor Details
-
AuthenticatedPrincipalOAuth2AuthorizedClientRepository
public AuthenticatedPrincipalOAuth2AuthorizedClientRepository(OAuth2AuthorizedClientService authorizedClientService) Constructs aAuthenticatedPrincipalOAuth2AuthorizedClientRepository
using the provided parameters.- Parameters:
authorizedClientService
- the authorized client service
-
-
Method Details
-
setAnonymousAuthorizedClientRepository
public void setAnonymousAuthorizedClientRepository(OAuth2AuthorizedClientRepository anonymousAuthorizedClientRepository) Sets theOAuth2AuthorizedClientRepository
used for requests that are unauthenticated (or anonymous). The default isHttpSessionOAuth2AuthorizedClientRepository
.- Parameters:
anonymousAuthorizedClientRepository
- the repository used for requests that are unauthenticated (or anonymous)
-
loadAuthorizedClient
public <T extends OAuth2AuthorizedClient> T loadAuthorizedClient(String clientRegistrationId, Authentication principal, jakarta.servlet.http.HttpServletRequest request) Description copied from interface:OAuth2AuthorizedClientRepository
Returns theOAuth2AuthorizedClient
associated to the provided client registration identifier and End-UserAuthentication
(Resource Owner) ornull
if not available.- Specified by:
loadAuthorizedClient
in interfaceOAuth2AuthorizedClientRepository
- Type Parameters:
T
- a type of OAuth2AuthorizedClient- Parameters:
clientRegistrationId
- the identifier for the client's registrationprincipal
- the End-UserAuthentication
(Resource Owner)request
- theHttpServletRequest
- Returns:
- the
OAuth2AuthorizedClient
ornull
if not available
-
saveAuthorizedClient
public void saveAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Description copied from interface:OAuth2AuthorizedClientRepository
Saves theOAuth2AuthorizedClient
associating it to the provided End-UserAuthentication
(Resource Owner).- Specified by:
saveAuthorizedClient
in interfaceOAuth2AuthorizedClientRepository
- Parameters:
authorizedClient
- the authorized clientprincipal
- the End-UserAuthentication
(Resource Owner)request
- theHttpServletRequest
response
- theHttpServletResponse
-
removeAuthorizedClient
public void removeAuthorizedClient(String clientRegistrationId, Authentication principal, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Description copied from interface:OAuth2AuthorizedClientRepository
Removes theOAuth2AuthorizedClient
associated to the provided client registration identifier and End-UserAuthentication
(Resource Owner).- Specified by:
removeAuthorizedClient
in interfaceOAuth2AuthorizedClientRepository
- Parameters:
clientRegistrationId
- the identifier for the client's registrationprincipal
- the End-UserAuthentication
(Resource Owner)request
- theHttpServletRequest
response
- theHttpServletResponse
-