Class DefaultOAuth2AuthorizedClientRepository
- java.lang.Object
-
- com.broadleafcommerce.auth.client.service.DefaultOAuth2AuthorizedClientRepository
-
- All Implemented Interfaces:
org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
public class DefaultOAuth2AuthorizedClientRepository extends Object implements org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
This service stores anOAuth2AuthorizedClientas a Base64 encoded value in a cookie.- Author:
- Cade Rea (cade-rea)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperThis class holds the necessary fields for saving and loadingOAuth2AuthorizedClient.
-
Field Summary
Fields Modifier and Type Field Description static StringCOOKIE_NAMEstatic longEXPIRES_IN_SECONDS
-
Constructor Summary
Constructors Constructor Description DefaultOAuth2AuthorizedClientRepository(StatelessUtil statelessUtil, ContextHelperService contextHelperService, org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.security.oauth2.client.OAuth2AuthorizedClientcreateAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapper authorizedClientWrapper)Create anOAuth2AuthorizedClientfrom anDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperprotected org.springframework.security.oauth2.client.registration.ClientRegistrationRepositorygetClientRegistrationRepository()protected ContextHelperServicegetContextHelperService()protected com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()protected OAuth2AuthorizedClientRepositoryPropertiesgetProperties()protected StringgetSavedAuthClientCookieName()protected StatelessUtilgetStatelessUtil()<T extends org.springframework.security.oauth2.client.OAuth2AuthorizedClient>
TloadAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request)protected DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperreadAuthClientWrapperFromCookie(javax.servlet.http.HttpServletRequest request)Read aDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperfrom the authorized client cookie.voidremoveAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)voidsaveAuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient authorizedClient, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected StringserializeAuthorizedClient(Object authorizedClient)Serialize the givenOAuth2AuthorizedClientinto a Base-64 encoded String.protected voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)voidsetProperties(OAuth2AuthorizedClientRepositoryProperties properties)protected DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperwrapAuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient authorizedClient)Create a newDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperfrom the givenOAuth2AuthorizedClient.
-
-
-
Field Detail
-
COOKIE_NAME
public static final String COOKIE_NAME
- See Also:
- Constant Field Values
-
EXPIRES_IN_SECONDS
public static final long EXPIRES_IN_SECONDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultOAuth2AuthorizedClientRepository
public DefaultOAuth2AuthorizedClientRepository(StatelessUtil statelessUtil, ContextHelperService contextHelperService, org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository)
-
-
Method Detail
-
loadAuthorizedClient
@Nullable public <T extends org.springframework.security.oauth2.client.OAuth2AuthorizedClient> T loadAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request)
- Specified by:
loadAuthorizedClientin interfaceorg.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
-
saveAuthorizedClient
public void saveAuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient authorizedClient, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)- Specified by:
saveAuthorizedClientin interfaceorg.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
-
removeAuthorizedClient
public void removeAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
- Specified by:
removeAuthorizedClientin interfaceorg.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
-
readAuthClientWrapperFromCookie
@Nullable protected DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapper readAuthClientWrapperFromCookie(javax.servlet.http.HttpServletRequest request)
Read aDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperfrom the authorized client cookie.- Parameters:
request-- Returns:
-
createAuthorizedClient
protected org.springframework.security.oauth2.client.OAuth2AuthorizedClient createAuthorizedClient(String clientRegistrationId, org.springframework.security.core.Authentication principal, DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapper authorizedClientWrapper)
Create anOAuth2AuthorizedClientfrom anDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapper- Parameters:
clientRegistrationId-principal-authorizedClientWrapper-- Returns:
-
wrapAuthorizedClient
protected DefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapper wrapAuthorizedClient(org.springframework.security.oauth2.client.OAuth2AuthorizedClient authorizedClient)
Create a newDefaultOAuth2AuthorizedClientRepository.TenantAwareOAuth2AuthorizedClientWrapperfrom the givenOAuth2AuthorizedClient.- Parameters:
authorizedClient-- Returns:
-
serializeAuthorizedClient
protected String serializeAuthorizedClient(Object authorizedClient)
Serialize the givenOAuth2AuthorizedClientinto a Base-64 encoded String.- Parameters:
authorizedClient-- Returns:
-
getSavedAuthClientCookieName
protected String getSavedAuthClientCookieName()
-
getStatelessUtil
protected StatelessUtil getStatelessUtil()
-
getContextHelperService
protected ContextHelperService getContextHelperService()
-
getClientRegistrationRepository
protected org.springframework.security.oauth2.client.registration.ClientRegistrationRepository getClientRegistrationRepository()
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
setObjectMapper
protected void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
getProperties
protected OAuth2AuthorizedClientRepositoryProperties getProperties()
-
setProperties
@Autowired public void setProperties(OAuth2AuthorizedClientRepositoryProperties properties)
-
-