Class DefaultOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
java.lang.Object
com.broadleafcommerce.auth.client.service.DefaultOAuthClientRegistrationPersistenceService<P,D>
- Type Parameters:
P- Projection,OAuthClientRegistrationWrapperD- Domain,JpaOAuthClientRegistration
- All Implemented Interfaces:
OAuthClientRegistrationPersistenceService<P>
public class DefaultOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable>
extends Object
implements OAuthClientRegistrationPersistenceService<P>
Interacts with the
OAuthClientRegistrationRepository to read domain objects and map them
to the projection OAuthClientRegistrationWrapper- Author:
- Cade Rea (cade-rea)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOAuthClientRegistrationPersistenceService(OAuthClientRegistrationRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator entityValidator, ClientRegistrationPropertiesService<P> clientRegistrationPropertiesService, OAuthClientRegistrationUtils clientRegistrationUtils) -
Method Summary
Modifier and TypeMethodDescriptionThis implementation can enhance the given clientRegistration in a few ways.voidDelete a client registrationvoiddeleteById(String id) Delete a client registrationbooleanexistsById(String id) Check if a client registration exists by its system IDorg.springframework.data.domain.Page<P>findAll(org.springframework.data.domain.Pageable pageable) Find all client registrations.org.springframework.data.domain.Page<P>findAllByTenantId(String tenantId, org.springframework.data.domain.Pageable pageable) Find allOAuthClientRegistrationWrapperobjects for the current tenantFind a client registration by its system IDFind a client registration by its system ID and tenant ID.findByRegistrationId(String registrationId, String tenantId) Find aOAuthClientRegistrationWrapperby registration id and tenant idFind the repository domain by ID without converting to business domain.fromRepositoryDomain(Optional<D> optionalDomain) protected org.springframework.data.domain.Page<P>fromRepositoryDomain(org.springframework.data.domain.Page<D> page) protected org.springframework.security.oauth2.client.registration.ClientRegistration.BuildergetBuilder(P clientRegistration, org.springframework.security.oauth2.client.registration.ClientRegistration.Builder builder) Populates the user-overrides and user-specific values (e.g., client id and secret) onto the builder produced bygetBuilderFromIssuerUri(OAuthClientRegistrationWrapper).protected org.springframework.security.oauth2.client.registration.ClientRegistration.BuildergetBuilderFromIssuerUri(P clientRegistration) protected ClientRegistrationPropertiesService<P>protected OAuthClientRegistrationUtilsprotected Optional<org.springframework.security.config.oauth2.client.CommonOAuth2Provider>getCommonOAuth2Provider(String registrationId) Use the global ApplicationConversionService to find theCommonOAuth2Providerenum that corresponds to the given registrationId.protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorprotected SimplePayloadMapperprotected OAuthClientRegistrationRepository<D>protected PpopulateCommonProvider(P clientRegistration) Populate the ProviderDetails from built-in values for providers listed inCommonOAuth2Provider, e.g.protected PpopulateFromCommonProvider(P clientRegistration, @NonNull org.springframework.security.oauth2.client.registration.ClientRegistration commonClientRegistration) Uses a ModelMapper to populate aOAuthClientRegistrationProviderDetailsfrom aClientRegistration.protected PpopulateRegistrationFromProvider(P clientRegistration) If anissuerUriis provided when creating aOAuthClientRegistrationWrapper, then this method should be invoked in order to populate theclientRegistrationwith the details from the issuer.Replace a client registrationSave theOAuthClientRegistrationWrapperto the databaseprotected voidprotected voidvalidateProviderDetails(P clientRegistration)
-
Field Details
-
CACHE_BY_CLIENT_REGISTRATION_ID
- See Also:
-
-
Constructor Details
-
DefaultOAuthClientRegistrationPersistenceService
public DefaultOAuthClientRegistrationPersistenceService(OAuthClientRegistrationRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator entityValidator, ClientRegistrationPropertiesService<P> clientRegistrationPropertiesService, OAuthClientRegistrationUtils clientRegistrationUtils)
-
-
Method Details
-
findAll
public org.springframework.data.domain.Page<P> findAll(@Nullable org.springframework.data.domain.Pageable pageable) Description copied from interface:OAuthClientRegistrationPersistenceServiceFind all client registrations.- Specified by:
findAllin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
pageable- the pageable- Returns:
- A page of client registrations
-
findAllByTenantId
public org.springframework.data.domain.Page<P> findAllByTenantId(String tenantId, @Nullable org.springframework.data.domain.Pageable pageable) Description copied from interface:OAuthClientRegistrationPersistenceServiceFind allOAuthClientRegistrationWrapperobjects for the current tenant- Specified by:
findAllByTenantIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
tenantId- the tenant IDpageable- the pageable- Returns:
- All registrations for the tenant
-
findById
@Cacheable(cacheNames="authCacheByClientRegistrationId", key="#a0", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public Optional<P> findById(String id) Description copied from interface:OAuthClientRegistrationPersistenceServiceFind a client registration by its system ID- Specified by:
findByIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
id- The client registration system ID- Returns:
- An optional of client registration
-
findById
@Cacheable(cacheNames="authCacheByClientRegistrationId", key="#a0.concat(#a1)", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public Optional<P> findById(String id, String tenantId) Description copied from interface:OAuthClientRegistrationPersistenceServiceFind a client registration by its system ID and tenant ID.- Specified by:
findByIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
id- The client registration system IDtenantId- ID of the owning tenant.- Returns:
- An optional of client registration
-
findByRegistrationId
Description copied from interface:OAuthClientRegistrationPersistenceServiceFind aOAuthClientRegistrationWrapperby registration id and tenant id- Specified by:
findByRegistrationIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
registrationId- TheOAuthClientRegistrationWrapper.getRegistrationId()to filter bytenantId- The tenant ID to filter by- Returns:
- The matching registration or empty
-
existsById
Description copied from interface:OAuthClientRegistrationPersistenceServiceCheck if a client registration exists by its system ID- Specified by:
existsByIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
id- The client registration system ID- Returns:
- whether or not the client registration exists
-
replace
@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P replace(String id, @NonNull P clientRegistration) Description copied from interface:OAuthClientRegistrationPersistenceServiceReplace a client registration- Specified by:
replacein interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
id- The id of the server to replaceclientRegistration- The replacement- Returns:
- The replaced client registration
-
create
@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P create(@NonNull P clientRegistration) This implementation can enhance the given clientRegistration in a few ways. - If theOAuthClientRegistrationProviderDetailsare empty, check to see if there is provider data included inCommonOAuth2Provider, based on theOAuthClientRegistrationWrapper.getRegistrationId(). - If aissuerUriis supplied, send a request to it and populate theOAuthClientRegistrationProviderDetailsfrom the response. - PopulateOAuthClientRegistrationProviderDetails.registrationIdfromOAuthClientRegistrationWrapper.registrationId.- Specified by:
createin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
clientRegistration- The client registration to create- Returns:
- The persisted registration.
-
save
@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P save(@NonNull P clientRegistration) Description copied from interface:OAuthClientRegistrationPersistenceServiceSave theOAuthClientRegistrationWrapperto the database- Specified by:
savein interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
clientRegistration- Instance to persist- Returns:
- Persited client registration
-
delete
@CacheEvict(cacheNames="authCacheByClientRegistrationId",key="#a0.id") @CacheEvict(cacheNames="authCacheByClientRegistrationId",key="#a0.id.concat(#a0.tenantId)") public void delete(@NonNull P clientRegistration) Description copied from interface:OAuthClientRegistrationPersistenceServiceDelete a client registration- Specified by:
deletein interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
clientRegistration- The client registration to delete.
-
deleteById
@CacheEvict(cacheNames="authCacheByClientRegistrationId", allEntries=true) public void deleteById(String id) Description copied from interface:OAuthClientRegistrationPersistenceServiceDelete a client registration- Specified by:
deleteByIdin interfaceOAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>- Parameters:
id- The id of the client registration to delete.
-
validate
-
validateProviderDetails
-
fromRepositoryDomain
-
fromRepositoryDomain
-
findRepositoryDomainById
Find the repository domain by ID without converting to business domain.- Parameters:
id- The entity ID- Returns:
- Optional of the entity.
-
populateRegistrationFromProvider
If anissuerUriis provided when creating aOAuthClientRegistrationWrapper, then this method should be invoked in order to populate theclientRegistrationwith the details from the issuer. This means the caller does not need to know all of the details themselves—in some cases the provider will not even provide the details except through theissuerUri.The approach taken here is based on
OAuth2ClientPropertiesRegistrationAdapter.Note: This method does not mutate the given
clientRegistrationbut creates a copy of it with the details populated there on.- Parameters:
clientRegistration- TheOAuthClientRegistrationWrapperto populate with provider details using a configuredissuerUri.- Returns:
- A copy of
clientRegistrationwith the provider details populated.
-
getBuilderFromIssuerUri
protected org.springframework.security.oauth2.client.registration.ClientRegistration.Builder getBuilderFromIssuerUri(@NonNull P clientRegistration) Gets aClientRegistration.Builderbased on theissuerUriof theclientRegistration. This takes advantage ofClientRegistrations.fromIssuerLocation(String)to fetch the provider details and hydrate them onto the builder, which can then be used to populate a finalOAuthClientRegistrationWrapper.- Parameters:
clientRegistration- TheOAuthClientRegistrationWrapperto populate with provider details using a configuredissuerUri.- Returns:
- A
ClientRegistration.Builderbased on theissuerUri
-
getBuilder
protected org.springframework.security.oauth2.client.registration.ClientRegistration.Builder getBuilder(@NonNull P clientRegistration, @NonNull org.springframework.security.oauth2.client.registration.ClientRegistration.Builder builder) Populates the user-overrides and user-specific values (e.g., client id and secret) onto the builder produced bygetBuilderFromIssuerUri(OAuthClientRegistrationWrapper).- Parameters:
clientRegistration- TheOAuthClientRegistrationWrapperto be populated. This is used to glean any user overrides of the default provider data and provide any user-specific details like the client ID and secret.builder- TheClientRegistration.Builderbuilt from the results of the request to theissuerUriconfigured on theclientRegistration.- Returns:
- The fully hydrated
ClientRegistration.Builder.
-
populateCommonProvider
Populate the ProviderDetails from built-in values for providers listed inCommonOAuth2Provider, e.g.CommonOAuth2Provider.GOOGLE,CommonOAuth2Provider.OKTA.- Parameters:
clientRegistration-
-
getCommonOAuth2Provider
protected Optional<org.springframework.security.config.oauth2.client.CommonOAuth2Provider> getCommonOAuth2Provider(String registrationId) Use the global ApplicationConversionService to find theCommonOAuth2Providerenum that corresponds to the given registrationId.- Parameters:
registrationId-- Returns:
-
populateFromCommonProvider
protected P populateFromCommonProvider(@NonNull P clientRegistration, @NonNull @NonNull org.springframework.security.oauth2.client.registration.ClientRegistration commonClientRegistration) Uses a ModelMapper to populate aOAuthClientRegistrationProviderDetailsfrom aClientRegistration.- Parameters:
clientRegistration-commonClientRegistration-- Returns:
-
getRepository
-
getMapper
-
getEntityValidator
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator getEntityValidator() -
getClientRegistrationPropertiesService
-
getClientRegistrationUtils
-