Class JwtAuthenticator

  • All Implemented Interfaces:
    Authenticator

    @Service("authenticator#jwt")
    public class JwtAuthenticator
    extends AbstractAuthenticator
    implements Authenticator
    Authenticator for JWT tokens. This authenticator needs a secret key or keypair depending on the used algorithm for signing and verification. The key can be either volatile in memory, which means a new one is created, with each start of the service. Or it can be stored in a file. If this service is running in a cluster, you need a shared filesystem (NFS) for storing the key file otherwise different keys will be used in each instance.

    You can renew the used key (renewSigningKey()). The authenticator keeps a fixed sized list of the last keys used and stores the key identifier in the JWT header.

    The default algorithm used for the JWT is currently UserConfigurationKeys.AUTHENTICATION_JWT_SIGALG_ES384 If the plainfile keystore is used, only the most recent key is saved to the file. Not the complete list. The JWT tokens have a lifetime set (14400 seconds - 4 hours). The following configuration keys are used to setup this authenticator:

    "authentication.jwt.keystoreType"
    The type of the keystore, either "memory" (key is lost, if the jvm stops) or "plainfile"
    "authentication.jwt.signatureAlgorithm"
    The signature algorithm for the JWT.
    • HS256: HMAC using SHA-256
    • HS384: HMAC using SHA-384
    • HS512: HMAC using SHA-512
    • ES256: ECDSA using P-256 and SHA-256
    • ES384: ECDSA using P-384 and SHA-384
    • ES512: ECDSA using P-521 and SHA-512
    • RS256: RSASSA-PKCS-v1_5 using SHA-256
    • RS384: RSASSA-PKCS-v1_5 using SHA-384
    • RS512: RSASSA-PKCS-v1_5 using SHA-512
    • PS256: RSASSA-PSS using SHA-256 and MGF1 with SHA-256
    • PS384: RSASSA-PSS using SHA-384 and MGF1 with SHA-384
    • PS512: RSASSA-PSS using SHA-512 and MGF1 with SHA-512
    "authentication.jwt.maxInMemoryKeys"
    The maximum number of signature keys to keep in memory for verification
    "authentication.jwt.keyfile"
    The key file. Either a full path to the file, or a single filename, which means it is stored in the working directory
    "authentication.jwt.lifetimeMs"
    The default token lifetime in milliseconds