Class JWTSAuthentication<A extends JWTClaimsSet>

Type Parameters:
A - the JWT claims set type
All Implemented Interfaces:
Authentication, TokenAuthentication

public class JWTSAuthentication<A extends JWTClaimsSet> extends Object implements TokenAuthentication

A token authentication that uses the compact representation of a JWTS as token value.

The authentication is considered authenticated when the underlying JWT is valid and is not using the NoAlgorithm.NONE algorithm.

Jeremy Kuhn
  • Constructor Details

    • JWTSAuthentication

      public JWTSAuthentication(JWS<A> jwt)

      Creates a JWTS authentication with the specified JWT.

      jwt - a JWTS
    • JWTSAuthentication

      public JWTSAuthentication(SecurityException cause)

      Creates a denied JWTS authentication with the specified security error.

      cause - a security error or null
  • Method Details

    • getJwt

      public JWS<A> getJwt()

      Returns the JWTS.

      a JWTS or null if unauthenticated
    • getJWTClaimsSet

      public A getJWTClaimsSet()

      Returns the JWT claims set.

      the JWT claims set or null if unauthenticated
    • getToken

      public String getToken()

      Returns the JWTS compact representation.

      Specified by:
      getToken in interface TokenAuthentication
      the JWTS compact representation or null if unauthenticated
    • isAuthenticated

      public boolean isAuthenticated()
      Description copied from interface: Authentication

      Determine whether the authentication is authenticated.

      A non-authenticated authentication might indicates that no authentication took place (i.e. anonymous access) or that the authentication failed. In case of a failed authentication, the cause is exposed by Authentication.getCause().

      Specified by:
      isAuthenticated in interface Authentication
      true if the the authentication is authenticated, false otherwise
    • getCause

      public Optional<SecurityException> getCause()
      Description copied from interface: Authentication

      Returns the cause of a failed authentication.

      A non-authenticated authentication with no cause indicates that no authentication took place (i.e. anonymous access).

      A non-authenticated authentication with a cause indicates a failed authentication.

      Specified by:
      getCause in interface Authentication
      an optional returning the cause of the failed authentication, or an empty optional if there was no authentication or if the authentication was successful