Package tech.lastbox.jwt
Class JwtConfig
java.lang.Object
tech.lastbox.jwt.JwtConfig
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 Summary
ConstructorsConstructorDescriptionJwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, String issuer, long expirationAmount, ExpirationTimeUnit expirationTimeUnit) Constructs a JwtConfig without a token store.JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, String issuer, long expirationAmount, ExpirationTimeUnit expirationTimeUnit, TokenStore tokenStore) Constructs a JwtConfig instance with all configurations, including a token store.JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, List<String> issuers, long expirationAmount, ExpirationTimeUnit expirationTimeUnit) Constructs a JwtConfig with multiple issuers and no token store.JwtConfig(JwtAlgorithm jwtAlgorithm, String secretKey, List<String> issuers, long expirationAmount, ExpirationTimeUnit expirationTimeUnit, TokenStore tokenStore) Constructs a JwtConfig with multiple issuers and a token store. -
Method Summary
Modifier and TypeMethodDescriptionlongGets the expiration time unit used for the JWT.Gets the expiration time unit used for the JWT.Gets the JWT signing algorithm.Gets the secret key used for JWT signing.Gets the token store used for saving and retrieving token entities.Retrieves the set of trusted issuers allowed for validating JWTs.
-
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
Gets the JWT signing algorithm.- Returns:
- The JWT signing algorithm.
-
getSecretKey
Gets the secret key used for JWT signing.- Returns:
- The secret key.
-
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
Gets the expiration time unit used for the JWT.- Returns:
- The expiration time unit.
-
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.
-