Class JwtTokenGenerator

java.lang.Object
io.micronaut.security.token.jwt.generator.JwtTokenGenerator
All Implemented Interfaces:
TokenGenerator

@Singleton public class JwtTokenGenerator extends Object implements TokenGenerator
JWT Token Generation.
Since:
1.0
Author:
Sergio del Amo
  • Field Details

  • Constructor Details

    • JwtTokenGenerator

      public JwtTokenGenerator(@Nullable @Named("generator") @Nullable SignatureGeneratorConfiguration signatureConfiguration, @Nullable @Named("generator") @Nullable EncryptionConfiguration encryptionConfiguration, ClaimsGenerator claimsGenerator)
      Parameters:
      signatureConfiguration - JWT Generator signature configuration
      encryptionConfiguration - JWT Generator encryption configuration
      claimsGenerator - Claims generator
  • Method Details

    • getSignatureConfiguration

      public SignatureGeneratorConfiguration getSignatureConfiguration()
      signatureConfiguration getter.
      Returns:
      Instance of SignatureGeneratorConfiguration
    • getEncryptionConfiguration

      public EncryptionConfiguration getEncryptionConfiguration()
      encryptionConfiguration getter.
      Returns:
      Instance of EncryptionConfiguration
    • internalGenerate

      protected String internalGenerate(com.nimbusds.jwt.JWTClaimsSet claimsSet) throws com.nimbusds.jose.JOSEException, ParseException
      Generate a JWT from a claims set.
      Parameters:
      claimsSet - the claims set
      Returns:
      the JWT
      Throws:
      com.nimbusds.jose.JOSEException - thrown in the JWT generation
      ParseException - thrown in the JWT generation
    • generate

      protected String generate(Map<String,Object> claims) throws com.nimbusds.jose.JOSEException, ParseException
      Generate a JWT from a map of claims.
      Parameters:
      claims - the map of claims
      Returns:
      the created JWT
      Throws:
      com.nimbusds.jose.JOSEException - thrown in the JWT generation
      ParseException - thrown in the JWT generation
    • generateToken

      public Optional<String> generateToken(Authentication authentication, @Nullable @Nullable Integer expiration)
      Specified by:
      generateToken in interface TokenGenerator
      Parameters:
      authentication - Authenticated user's representation.
      expiration - The amount of time in seconds until the token expires
      Returns:
      JWT token
    • generateToken

      public Optional<String> generateToken(Map<String,Object> claims)
      Specified by:
      generateToken in interface TokenGenerator
      Parameters:
      claims - JWT claims
      Returns:
      JWT token