Class DefaultApiKeyGenerator

java.lang.Object
com.broadleafcommerce.auth.server.service.apikey.DefaultApiKeyGenerator
All Implemented Interfaces:
ApiKeyGenerator

public class DefaultApiKeyGenerator extends Object implements ApiKeyGenerator
Default implementation of ApiKeyGenerator that creates keys formatted with visibility and environment prefixes.
See Also:
  • Constructor Details

    • DefaultApiKeyGenerator

      public DefaultApiKeyGenerator(ApiKeyHasher apiKeyHasher, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • instantiateHexPrefixGenerator

      protected org.springframework.security.crypto.keygen.BytesKeyGenerator instantiateHexPrefixGenerator()
    • instantiateHexSuffixGenerator

      protected org.springframework.security.crypto.keygen.BytesKeyGenerator instantiateHexSuffixGenerator()
    • generate

      Uses a BytesKeyGenerator to generate a cryptographically strong API key conforming to the format {visibilityPrefix}_{env}_{8 char hex prefix}_{32 char hex}.
      Specified by:
      generate in interface ApiKeyGenerator
      Parameters:
      request - the request containing configuration details for the key
      Returns:
      the result containing the raw key, the hash, and a display-safe preview
    • determinePrefixForVisibilityType

      protected String determinePrefixForVisibilityType(AuthorizedClient authorizedClient)
    • determinePrefixForEnvironment

      protected String determinePrefixForEnvironment(AuthorizedClient authorizedClient)
    • generateHexPrefix

      protected String generateHexPrefix()
    • generateHexSuffix

      protected String generateHexSuffix()
    • buildPlaintextKey

      protected String buildPlaintextKey(String visibilityPrefix, String envPrefix, String hexPrefix, String hexSuffix)
    • buildDisplaySafeKeyPreview

      protected String buildDisplaySafeKeyPreview(String visibilityPrefix, String envPrefix, String hexPrefix, String hexSuffix)
    • buildApiKeyGenerationResult

      protected ApiKeyGenerationResult buildApiKeyGenerationResult(String plaintextKey, String displaySafeKeyPreview, String secureHash)
      Parameters:
      plaintextKey - the generated plaintext key
      displaySafeKeyPreview - the preview
      secureHash - the hash
      Returns:
      a new generation result Authentication Service 3.0.0, Release Train 3.0.0
    • getApiKeyHasher

      protected ApiKeyHasher getApiKeyHasher()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getHexPrefixGenerator

      protected org.springframework.security.crypto.keygen.BytesKeyGenerator getHexPrefixGenerator()
    • getHexSuffixGenerator

      protected org.springframework.security.crypto.keygen.BytesKeyGenerator getHexSuffixGenerator()