P
- Projection, OAuthClientRegistrationWrapper
D
- Domain, JpaOAuthClientRegistration
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>
OAuthClientRegistrationRepository
to read domain objects and map them
to the projection OAuthClientRegistrationWrapper
Modifier and Type | Field and Description |
---|---|
static String |
CACHE_BY_CLIENT_REGISTRATION_ID |
Constructor and Description |
---|
DefaultOAuthClientRegistrationPersistenceService(OAuthClientRegistrationRepository<D> repository,
SimplePayloadMapper mapper,
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator entityValidator,
ClientRegistrationPropertiesService<P> clientRegistrationPropertiesService,
OAuthClientRegistrationUtils clientRegistrationUtils) |
Modifier and Type | Method and Description |
---|---|
P |
create(P clientRegistration)
This implementation can enhance the given clientRegistration in a few ways.
|
void |
delete(P clientRegistration)
Delete a client registration
|
void |
deleteById(String id)
Delete a client registration
|
boolean |
existsById(String id)
Check if a client registration exists by its system ID
|
org.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 all
OAuthClientRegistrationWrapper objects for the current tenant |
Optional<P> |
findById(String id)
Find a client registration by its system ID
|
Optional<P> |
findById(String id,
String tenantId)
Find a client registration by its system ID and tenant ID.
|
Optional<P> |
findByRegistrationId(String registrationId,
String tenantId)
Find a
OAuthClientRegistrationWrapper by registration id and tenant id |
protected Optional<D> |
findRepositoryDomainById(String id)
Find the repository domain by ID without converting to business domain.
|
protected Optional<P> |
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.Builder |
getBuilder(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 by
getBuilderFromIssuerUri(OAuthClientRegistrationWrapper) . |
protected org.springframework.security.oauth2.client.registration.ClientRegistration.Builder |
getBuilderFromIssuerUri(P clientRegistration)
|
protected ClientRegistrationPropertiesService<P> |
getClientRegistrationPropertiesService() |
protected OAuthClientRegistrationUtils |
getClientRegistrationUtils() |
protected Optional<org.springframework.security.config.oauth2.client.CommonOAuth2Provider> |
getCommonOAuth2Provider(String registrationId)
Use the global ApplicationConversionService to find the
CommonOAuth2Provider enum
that corresponds to the given registrationId. |
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator |
getEntityValidator() |
protected SimplePayloadMapper |
getMapper() |
protected OAuthClientRegistrationRepository<D> |
getRepository() |
protected P |
populateCommonProvider(P clientRegistration)
Populate the ProviderDetails from built-in values for providers listed in
CommonOAuth2Provider , e.g. |
protected P |
populateFromCommonProvider(P clientRegistration,
@NonNull org.springframework.security.oauth2.client.registration.ClientRegistration commonClientRegistration)
Uses a ModelMapper to populate a
OAuthClientRegistrationProviderDetails from a
ClientRegistration . |
protected P |
populateRegistrationFromProvider(P clientRegistration)
If an
issuerUri is provided
when creating a OAuthClientRegistrationWrapper , then this method should be invoked in
order to populate the clientRegistration with the details from the issuer. |
P |
replace(String id,
P clientRegistration)
Replace a client registration
|
P |
save(P clientRegistration)
Save the
OAuthClientRegistrationWrapper to the database |
protected void |
validate(P clientRegistration) |
protected void |
validateProviderDetails(P clientRegistration) |
public static final String CACHE_BY_CLIENT_REGISTRATION_ID
public DefaultOAuthClientRegistrationPersistenceService(OAuthClientRegistrationRepository<D> repository, SimplePayloadMapper mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator entityValidator, ClientRegistrationPropertiesService<P> clientRegistrationPropertiesService, OAuthClientRegistrationUtils clientRegistrationUtils)
public org.springframework.data.domain.Page<P> findAll(@Nullable org.springframework.data.domain.Pageable pageable)
OAuthClientRegistrationPersistenceService
findAll
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
pageable
- the pageablepublic org.springframework.data.domain.Page<P> findAllByTenantId(String tenantId, @Nullable org.springframework.data.domain.Pageable pageable)
OAuthClientRegistrationPersistenceService
OAuthClientRegistrationWrapper
objects for the current tenantfindAllByTenantId
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
tenantId
- the tenant IDpageable
- the pageable@Cacheable(cacheNames="authCacheByClientRegistrationId", key="#a0", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public Optional<P> findById(String id)
OAuthClientRegistrationPersistenceService
findById
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
id
- The client registration system ID@Cacheable(cacheNames="authCacheByClientRegistrationId", key="#a0.concat(#a1)", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public Optional<P> findById(String id, String tenantId)
OAuthClientRegistrationPersistenceService
findById
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
id
- The client registration system IDtenantId
- ID of the owning tenant.public Optional<P> findByRegistrationId(String registrationId, String tenantId)
OAuthClientRegistrationPersistenceService
OAuthClientRegistrationWrapper
by registration id and tenant idfindByRegistrationId
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
registrationId
- The OAuthClientRegistrationWrapper.getRegistrationId()
to
filter bytenantId
- The tenant ID to filter bypublic boolean existsById(String id)
OAuthClientRegistrationPersistenceService
existsById
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
id
- The client registration system ID@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P replace(String id, @NonNull P clientRegistration)
OAuthClientRegistrationPersistenceService
replace
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
id
- The id of the server to replaceclientRegistration
- The replacement@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P create(@NonNull P clientRegistration)
OAuthClientRegistrationProviderDetails
are empty, check to see if there is
provider data included in CommonOAuth2Provider
, based on the
OAuthClientRegistrationWrapper.getRegistrationId()
.
- If a issuerUri
is supplied,
send a request to it and populate the OAuthClientRegistrationProviderDetails
from the
response.
- Populate OAuthClientRegistrationProviderDetails.registrationId
from
OAuthClientRegistrationWrapper.registrationId
.create
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
clientRegistration
- The client registration to create@CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id") @CachePut(cacheNames="authCacheByClientRegistrationId",key="#result.id.concat(#result.tenantId)") public P save(@NonNull P clientRegistration)
OAuthClientRegistrationPersistenceService
OAuthClientRegistrationWrapper
to the databasesave
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
clientRegistration
- Instance to persist@CacheEvict(cacheNames="authCacheByClientRegistrationId",key="#a0.id") @CacheEvict(cacheNames="authCacheByClientRegistrationId",key="#a0.id.concat(#a0.tenantId)") public void delete(@NonNull P clientRegistration)
OAuthClientRegistrationPersistenceService
delete
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
clientRegistration
- The client registration to delete.@CacheEvict(cacheNames="authCacheByClientRegistrationId", allEntries=true) public void deleteById(String id)
OAuthClientRegistrationPersistenceService
deleteById
in interface OAuthClientRegistrationPersistenceService<P extends OAuthClientRegistrationWrapper>
id
- The id of the client registration to delete.protected void validate(@NonNull P clientRegistration)
protected void validateProviderDetails(@NonNull P clientRegistration)
protected org.springframework.data.domain.Page<P> fromRepositoryDomain(org.springframework.data.domain.Page<D> page)
protected Optional<D> findRepositoryDomainById(String id)
id
- The entity IDprotected P populateRegistrationFromProvider(@NonNull P clientRegistration)
issuerUri
is provided
when creating a OAuthClientRegistrationWrapper
, then this method should be invoked in
order to populate the clientRegistration
with 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 the issuerUri
.
The approach taken here is based on OAuth2ClientPropertiesRegistrationAdapter
.
Note: This method does not mutate the given clientRegistration
but
creates a copy of it with the details populated there on.
clientRegistration
- The OAuthClientRegistrationWrapper
to populate with
provider details using a configured
issuerUri
.clientRegistration
with the provider details populated.protected org.springframework.security.oauth2.client.registration.ClientRegistration.Builder getBuilderFromIssuerUri(@NonNull P clientRegistration)
ClientRegistration.Builder
based on the
issuerUri
of the
clientRegistration
. This takes advantage of
ClientRegistrations.fromIssuerLocation(String)
to fetch the provider details and
hydrate them onto the builder, which can then be used to populate a final
OAuthClientRegistrationWrapper
.clientRegistration
- The OAuthClientRegistrationWrapper
to populate with
provider details using a configured
issuerUri
.ClientRegistration.Builder
based on the
issuerUri
protected org.springframework.security.oauth2.client.registration.ClientRegistration.Builder getBuilder(@NonNull P clientRegistration, @NonNull org.springframework.security.oauth2.client.registration.ClientRegistration.Builder builder)
getBuilderFromIssuerUri(OAuthClientRegistrationWrapper)
.clientRegistration
- The OAuthClientRegistrationWrapper
to 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
- The ClientRegistration.Builder
built from the results of the request
to the issuerUri
configured on the clientRegistration
.ClientRegistration.Builder
.protected P populateCommonProvider(@NonNull P clientRegistration)
CommonOAuth2Provider
, e.g. CommonOAuth2Provider.GOOGLE
,
CommonOAuth2Provider.OKTA
.clientRegistration
- protected Optional<org.springframework.security.config.oauth2.client.CommonOAuth2Provider> getCommonOAuth2Provider(String registrationId)
CommonOAuth2Provider
enum
that corresponds to the given registrationId.registrationId
- protected P populateFromCommonProvider(@NonNull P clientRegistration, @NonNull @NonNull org.springframework.security.oauth2.client.registration.ClientRegistration commonClientRegistration)
OAuthClientRegistrationProviderDetails
from a
ClientRegistration
.clientRegistration
- commonClientRegistration
- protected OAuthClientRegistrationRepository<D> getRepository()
protected SimplePayloadMapper getMapper()
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator getEntityValidator()
protected ClientRegistrationPropertiesService<P> getClientRegistrationPropertiesService()
protected OAuthClientRegistrationUtils getClientRegistrationUtils()
Copyright © 2021. All rights reserved.