Class JwtConfig

java.lang.Object
tech.lastbox.jwt.JwtConfig

public class JwtConfig extends Object
Configuration class for JWT (JSON Web Token) settings.

This class provides the configurations required for JWT creation and validation. It supports customization of algorithms, secret keys, issuers, expiration settings, and an optional token store for persistence. The preset of trusted issuers contains: "Google", "GitHub", "Facebook", "Microsoft", "Twitter", "LinkedIn" and "Spotify"

  • Constructor Details

    • JwtConfig

      public JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, String issuer, long expirationAmount, ExpirationTimeUnit expirationTimeUnit, TokenStore tokenStore)
      Constructs a JwtConfig instance with all configurations, including a token store.
      Parameters:
      jwtAlgorithm - Algorithm used for JWT signing.
      secretKey - Secret key for JWT signing.
      issuer - The main issuer for JWTs.
      expirationAmount - Duration before token expiration.
      expirationTimeUnit - Unit of time for expiration duration.
      tokenStore - Store for saving and retrieving tokens.
      Throws:
      tech.lastbox.jwt.AlgorithmException - If the algorithm or secretKey is invalid.
    • JwtConfig

      public JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, String issuer, long expirationAmount, ExpirationTimeUnit expirationTimeUnit)
      Constructs a JwtConfig without a token store.
      Parameters:
      jwtAlgorithm - Algorithm used for JWT signing.
      secretKey - Secret key for JWT signing.
      issuer - The main issuer for JWTs.
      expirationAmount - Duration before token expiration.
      expirationTimeUnit - Unit of time for expiration duration.
      Throws:
      tech.lastbox.jwt.AlgorithmException - If the algorithm or secretKey is invalid.
    • JwtConfig

      public JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, List<String> issuers, long expirationAmount, ExpirationTimeUnit expirationTimeUnit, TokenStore tokenStore)
      Constructs a JwtConfig with multiple issuers and a token store.
      Parameters:
      jwtAlgorithm - Algorithm used for JWT signing.
      secretKey - Secret key for JWT signing.
      issuers - List of trusted issuers for JWTs.
      expirationAmount - Duration before token expiration.
      expirationTimeUnit - Unit of time for expiration duration.
      tokenStore - Store for saving and retrieving tokens.
      Throws:
      tech.lastbox.jwt.AlgorithmException - If the algorithm or secretKey is invalid.
    • JwtConfig

      public JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, List<String> issuers, long expirationAmount, ExpirationTimeUnit expirationTimeUnit)
      Constructs a JwtConfig with multiple issuers and no token store.
      Parameters:
      jwtAlgorithm - Algorithm used for JWT signing.
      secretKey - Secret key for JWT signing.
      issuers - List of trusted issuers for JWTs.
      expirationAmount - Duration before token expiration.
      expirationTimeUnit - Unit of time for expiration duration.
      Throws:
      tech.lastbox.jwt.AlgorithmException - If the algorithm or secretKey is invalid.
  • Method Details

    • getJwtAlgorithm

      public JwtAlgorithm getJwtAlgorithm()
      Gets the JWT signing algorithm.
      Returns:
      The JWT signing algorithm.
    • getSecretKey

      public String getSecretKey()
      Gets the secret key used for JWT signing.
      Returns:
      The secret key.
    • getTrustedIssuers

      public HashSet<String> getTrustedIssuers()
      Retrieves the set of trusted issuers allowed for validating JWTs.
      Returns:
      A HashSet of trusted issuer names.
    • getExpirationAmount

      public long getExpirationAmount()
      Gets the expiration time unit used for the JWT.
      Returns:
      The expiration time unit.
    • getExpirationTimeUnit

      public ExpirationTimeUnit getExpirationTimeUnit()
      Gets the expiration time unit used for the JWT.
      Returns:
      The expiration time unit.
    • getTokenStore

      public TokenStore getTokenStore()
      Gets the token store used for saving and retrieving token entities. If no token store is configured, this returns null.
      Returns:
      The token store, or null if not configured.