Class DefaultApiKeyService<P extends ApiKey>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService<P>
com.broadleafcommerce.auth.server.service.apikey.DefaultApiKeyService<P>
- Type Parameters:
P- the business domain type
- All Implemented Interfaces:
ApiKeyService<P>,com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityService<P>
public class DefaultApiKeyService<P extends ApiKey>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService<P>
implements ApiKeyService<P>
Default implementation of
ApiKeyService.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultApiKeyService(ApiKeyRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityHelper helper, AuthorizedClientService<AuthorizedClient> authorizedClientService, AuthorizationServerService<AuthorizationServer> authorizationServerService, ApiKeyGenerator apiKeyGenerator, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) -
Method Summary
Modifier and TypeMethodDescriptionprotected PbuildApiKey(String authorizedClientId, ApiKeyCreateRequest request, ApiKeyGenerationResult genResult) protected ApiKeyCreateResponsebuildApiKeyCreateResponse(P savedKey, ApiKeyGenerationResult genResult) protected ApiKeyGenerationRequestcreateApiKey(String authorizedClientId, ApiKeyCreateRequest request, boolean validateClientAccessibility) Creates a new API key for the given client.voiddeleteApiKey(String authorizedClientId, String id, boolean validateClientAccessibility) Deletes an API key.protected PfindByIdAndAuthorizedClientId(String id, String authorizedClientId) protected ApiKeyGeneratorprotected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsprotected AuthorizationServerService<AuthorizationServer>protected AuthorizedClientService<AuthorizedClient>protected AuthorizedClientgetClientAndValidateAccess(String authorizedClientId, boolean validateClientAccessibility) protected ApiKeyRepository<com.broadleafcommerce.data.tracking.core.Identifiable>protected com.broadleafcommerce.common.extension.TypeFactoryorg.springframework.data.domain.Page<P>internalReadAllByAuthorizedClientId(String authorizedClientId, org.springframework.data.domain.Pageable pageable, cz.jirutka.rsql.parser.ast.Node filters) This method is intended for internal system usage in trusted flows, and bypasses the standard client existence/accessibility validations from the external-facingApiKeyService.readAllByAuthorizedClientId(String, Pageable, Node, boolean).protected voidmapUpdatesToApiKey(P existing, ApiKeyUpdateRequest request) org.springframework.data.domain.Page<P>readAllByAuthorizedClientId(String authorizedClientId, org.springframework.data.domain.Pageable pageable, cz.jirutka.rsql.parser.ast.Node filters, boolean validateClientAccessibility) Retrieves all API keys belonging to the specified client.readByAuthorizedClientIdAndApiKeyId(String authorizedClientId, String id, boolean validateClientAccessibility) Retrieves a specific API key belonging to the specified client.readByHashedKey(String hashedKey) Finds an API key by its hashed value.updateApiKey(String authorizedClientId, String id, ApiKeyUpdateRequest request, boolean validateClientAccessibility) Updates an existing API key.protected voidvalidateClientAccessibility(AuthorizedClient targetClient, AuthorizationServer targetServer) Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService
convertFromPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, readAll, readAll, readAll, readAllByIds, readById, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccessMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByIds, readById, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess
-
Constructor Details
-
DefaultApiKeyService
public DefaultApiKeyService(ApiKeyRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityHelper helper, AuthorizedClientService<AuthorizedClient> authorizedClientService, AuthorizationServerService<AuthorizationServer> authorizationServerService, ApiKeyGenerator apiKeyGenerator, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
-
-
Method Details
-
readByHashedKey
Description copied from interface:ApiKeyServiceFinds an API key by its hashed value.- Specified by:
readByHashedKeyin interfaceApiKeyService<P extends ApiKey>- Parameters:
hashedKey- the hashed key- Returns:
- an Optional containing the API key if found, or empty otherwise
-
readAllByAuthorizedClientId
public org.springframework.data.domain.Page<P> readAllByAuthorizedClientId(String authorizedClientId, org.springframework.data.domain.Pageable pageable, cz.jirutka.rsql.parser.ast.Node filters, boolean validateClientAccessibility) Description copied from interface:ApiKeyServiceRetrieves all API keys belonging to the specified client.- Specified by:
readAllByAuthorizedClientIdin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()pageable- the pagination parametersfilters- additional filters used to restrict results. Cannot be null - useEmptyNodeif no additional filters should be applied.validateClientAccessibility- whether to perform authentication context and tenant checks- Returns:
- a page of API keys
-
internalReadAllByAuthorizedClientId
public org.springframework.data.domain.Page<P> internalReadAllByAuthorizedClientId(String authorizedClientId, org.springframework.data.domain.Pageable pageable, cz.jirutka.rsql.parser.ast.Node filters) Description copied from interface:ApiKeyServiceThis method is intended for internal system usage in trusted flows, and bypasses the standard client existence/accessibility validations from the external-facing
ApiKeyService.readAllByAuthorizedClientId(String, Pageable, Node, boolean).Retrieves all API keys belonging to the specified client.
- Specified by:
internalReadAllByAuthorizedClientIdin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()pageable- the pagination parametersfilters- additional filters used to restrict results. Cannot be null - useEmptyNodeif no additional filters should be applied.- Returns:
- a page of API keys
-
readByAuthorizedClientIdAndApiKeyId
public P readByAuthorizedClientIdAndApiKeyId(String authorizedClientId, String id, boolean validateClientAccessibility) Description copied from interface:ApiKeyServiceRetrieves a specific API key belonging to the specified client.- Specified by:
readByAuthorizedClientIdAndApiKeyIdin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()id- the API key IDvalidateClientAccessibility- whether to perform authentication context and tenant checks- Returns:
- the API key
-
createApiKey
public ApiKeyCreateResponse createApiKey(String authorizedClientId, ApiKeyCreateRequest request, boolean validateClientAccessibility) Description copied from interface:ApiKeyServiceCreates a new API key for the given client.- Specified by:
createApiKeyin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()request- the create request containing configurationvalidateClientAccessibility- whether to perform authentication context and tenant checks- Returns:
- the create response containing the one-time plaintext key
-
buildApiKey
protected P buildApiKey(String authorizedClientId, ApiKeyCreateRequest request, ApiKeyGenerationResult genResult) -
buildApiKeyCreateResponse
protected ApiKeyCreateResponse buildApiKeyCreateResponse(P savedKey, ApiKeyGenerationResult genResult) -
updateApiKey
public P updateApiKey(String authorizedClientId, String id, ApiKeyUpdateRequest request, boolean validateClientAccessibility) Description copied from interface:ApiKeyServiceUpdates an existing API key.- Specified by:
updateApiKeyin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()id- the API key IDrequest- the update request containing the updated fieldsvalidateClientAccessibility- whether to perform authentication context and tenant checks- Returns:
- the updated API key
-
mapUpdatesToApiKey
-
deleteApiKey
Description copied from interface:ApiKeyServiceDeletes an API key.- Specified by:
deleteApiKeyin interfaceApiKeyService<P extends ApiKey>- Parameters:
authorizedClientId- theAuthorizedClient.getId()id- the API key IDvalidateClientAccessibility- whether to perform authentication context and tenant checks
-
findByIdAndAuthorizedClientId
-
buildApiKeyGenerationRequest
-
getClientAndValidateAccess
protected AuthorizedClient getClientAndValidateAccess(String authorizedClientId, boolean validateClientAccessibility) -
validateClientAccessibility
protected void validateClientAccessibility(AuthorizedClient targetClient, AuthorizationServer targetServer) -
getRepository
-
getAuthorizedClientService
-
getAuthorizationServerService
-
getApiKeyGenerator
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
-