Class DefaultBroadleafClientRegistrationRepository
java.lang.Object
com.broadleafcommerce.auth.client.registration.DefaultBroadleafClientRegistrationRepository
- All Implemented Interfaces:
BroadleafClientRegistrationRepository,org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
public class DefaultBroadleafClientRegistrationRepository
extends Object
implements BroadleafClientRegistrationRepository
Provides
ClientRegistration objects to the OAuth2 Client beans.
This class relies on the ContextHelperService to get the current tenant id from request
attributes. This enables us to allow tenant tracking while preserving the
ClientRegistrationRepository interface from the OAuth2 Client library.
This class has the ability to incorporate OAuthClientRegistrationWrapper data built from
application properties. The OAuthClientRegistrationPersistenceService will always be
checked first. If a registration is not found there then this will check the
ClientRegistrationPropertiesService. If a registration is found with the
ClientRegistrationPropertiesService, it will be saved with
OAuthClientRegistrationPersistenceService.
Despite the name, this is not a repository in the usual sense. Its name is based on the Spring
interface ClientRegistrationRepository that this class implements. Actual persistence
operations are handled by OAuthClientRegistrationPersistenceService.- Author:
- Cade Rea (cade-rea)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultBroadleafClientRegistrationRepository(OAuthClientRegistrationPersistenceService<OAuthClientRegistrationWrapper> clientRegistrationService, ContextHelperService contextHelperService, ClientRegistrationPropertiesService<OAuthClientRegistrationWrapper> clientRegistrationPropertiesService) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.security.oauth2.client.registration.ClientRegistrationConverts anOAuthClientRegistrationWrapperto aClientRegistration.protected org.springframework.security.oauth2.client.registration.ClientRegistrationconsolidateRepresentation(OAuthClientRegistrationWrapper dbEntry, OAuthClientRegistrationWrapper propsEntry, String tenantId) Return a Map of all available 3rd party OAuth providers.org.springframework.security.oauth2.client.registration.ClientRegistrationfindByRegistrationId(String registrationId) Looks up aClientRegistrationby its registration id.org.springframework.security.oauth2.client.registration.ClientRegistrationfindByRegistrationIdAndTenantId(String registrationId, String tenantId) Looks up aClientRegistrationby its registration id and the given tenant ID.protected ClientIdentityProviderPropertiesgetClientProps(@NonNull AuthorizedClient client) protected ContextHelperServicegetOauth2IdentityProviders(@NonNull AuthorizedClient client) Looks at theClientRegistrationsto determine which providers are configured and then cross-checks that with theClientIdentityProviderProperties.ClientPropertiesfor the appropriate type ofAuthorizedClientthat is making a request, either admin or commerce, to filter the registered identity providers that are appropriate to show the user.protected com.broadleafcommerce.common.extension.TypeFactoryprotected OAuthClientRegistrationWrapperloadFromProperties(String registrationId, String tenantId) voidsetClientProperties(ClientIdentityProviderProperties clientProperties) voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Field Details
-
CACHE_OAUTH2_IDENTITY_PROVIDERS
- See Also:
-
-
Constructor Details
-
DefaultBroadleafClientRegistrationRepository
public DefaultBroadleafClientRegistrationRepository(OAuthClientRegistrationPersistenceService<OAuthClientRegistrationWrapper> clientRegistrationService, ContextHelperService contextHelperService, ClientRegistrationPropertiesService<OAuthClientRegistrationWrapper> clientRegistrationPropertiesService)
-
-
Method Details
-
findByRegistrationId
@Nullable public org.springframework.security.oauth2.client.registration.ClientRegistration findByRegistrationId(String registrationId) Looks up aClientRegistrationby its registration id. This will first check theOAuthClientRegistrationPersistenceService. If not found there, this will checkClientRegistrationPropertiesService.- Specified by:
findByRegistrationIdin interfaceorg.springframework.security.oauth2.client.registration.ClientRegistrationRepository- Parameters:
registrationId- The registration id, e.g. "google" or "facebook".- Returns:
- The
ClientRegistrationthat corresponds to the given registration id.
-
findByRegistrationIdAndTenantId
@Nullable public org.springframework.security.oauth2.client.registration.ClientRegistration findByRegistrationIdAndTenantId(String registrationId, String tenantId) Description copied from interface:BroadleafClientRegistrationRepositoryLooks up a
ClientRegistrationby its registration id and the given tenant ID. This will first check theOAuthClientRegistrationPersistenceService. If not found there, this will checkClientRegistrationPropertiesService.This method differs from
ClientRegistrationRepository.findByRegistrationId(String), as that method implicitly retrieves the tenant ID viaContextHelperService.getTenantId(). In this method, the tenant ID is explicitly provided by the caller.- Specified by:
findByRegistrationIdAndTenantIdin interfaceBroadleafClientRegistrationRepository- Parameters:
registrationId- The registration id, e.g. "google" or "facebook".tenantId- the tenant ID in which to find the registration- Returns:
- The
ClientRegistrationthat corresponds to the given registration id.
-
consolidateRepresentation
protected org.springframework.security.oauth2.client.registration.ClientRegistration consolidateRepresentation(@Nullable OAuthClientRegistrationWrapper dbEntry, @Nullable OAuthClientRegistrationWrapper propsEntry, String tenantId) -
findAllClientRegistrations
Return a Map of all available 3rd party OAuth providers. The map key is the registration id from theOAuthClientRegistrationWrapper.- Specified by:
findAllClientRegistrationsin interfaceBroadleafClientRegistrationRepository- Returns:
- A tenant-discriminated Map of
OAuthClientRegistrationWrapper
-
loadFromProperties
-
buildClientRegistration
@Nullable protected org.springframework.security.oauth2.client.registration.ClientRegistration buildClientRegistration(OAuthClientRegistrationWrapper wrapper) Converts anOAuthClientRegistrationWrapperto aClientRegistration. Returns null if there are any exceptions in the conversion process.- Parameters:
wrapper-- Returns:
-
getOauth2IdentityProviders
@Cacheable(value="oauth2IdentityProviders", keyGenerator="oauth2IdentityProviders", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public List<OAuth2IdentityProvider> getOauth2IdentityProviders(@NonNull @NonNull AuthorizedClient client) Description copied from interface:BroadleafClientRegistrationRepositoryLooks at theClientRegistrationsto determine which providers are configured and then cross-checks that with theClientIdentityProviderProperties.ClientPropertiesfor the appropriate type ofAuthorizedClientthat is making a request, either admin or commerce, to filter the registered identity providers that are appropriate to show the user.- Specified by:
getOauth2IdentityProvidersin interfaceBroadleafClientRegistrationRepository- Parameters:
client- The requestingAuthorizedClient.- Returns:
- A list of
OAuth2IdentityProviderto add to the request model.
-
getClientProps
protected ClientIdentityProviderProperties.ClientProperties getClientProps(@NonNull @NonNull AuthorizedClient client) -
getClientRegistrationService
protected OAuthClientRegistrationPersistenceService<OAuthClientRegistrationWrapper> getClientRegistrationService() -
getContextHelperService
-
getClientRegistrationPropertiesService
protected ClientRegistrationPropertiesService<OAuthClientRegistrationWrapper> getClientRegistrationPropertiesService() -
getClientProperties
-
setClientProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-