Class JwtBuilderFactory


  • public class JwtBuilderFactory
    extends Object
    A factory for getting builders for plaintext, signed and encrypted JWTs and reconstructing JWT strings back into their relevant JWT objects.
    Since:
    2.0.0
    • Constructor Detail

      • JwtBuilderFactory

        public JwtBuilderFactory()
    • Method Detail

      • recognizedHeaders

        public JwtBuilderFactory recognizedHeaders​(String... headers)
        Configures additional application-specific header values that are understood and processed by the application. Any non-standard critical headers that are not in this list will cause reconstruct(String, Class) to fail.
        Parameters:
        headers - the set of headers to add to the recognized set.
        Returns:
        the updated JwtBuilderFactory object.
      • jwt

        @Deprecated
        public SignedJwtBuilderImpl jwt()
        Deprecated.
        This method provides no security at all and shouldn't be used.
        Creates a builder for building a plaintext JWT into base64url UTF-8 encoded JWT string.
        Returns:
        The JwtBuilder instance that will build the plaintext JWT.
      • jws

        public SignedJwtBuilderImpl jws​(SigningHandler signingHandler)
        Creates a builder for building a signed JWT into a base64url UTF-8 encoded JWT string.
        Parameters:
        signingHandler - The SigningHandler instance used to sign the JWS.
        Returns:
        The JwtBuilder instance that will build the signed JWT.
      • jwe

        @Deprecated
        public EncryptedJwtBuilder jwe​(Key publicKey)
        Deprecated.
        Prefer jwe(EncryptionKey) instead.
        Creates a builder for building an encrypted JWT into a base64url UTF-8 encoded JWT string.
        Parameters:
        publicKey - The public key that will be used to encrypted the JWT.
        Returns:
        The JwtBuilder instance that will build the encrypted JWT.
      • jwe

        public EncryptedJwtBuilder jwe​(EncryptionKey<?> key)
        Creates a builder for building an encrypted JWT using the given encryption key.
        Parameters:
        key - the encryption key. Must not be null.
        Returns:
        A builder for constructing an encrypted JWT.
      • claims

        public JwtClaimsSetBuilder claims()
        Creates a builder for building a JWT Claims Set to be used in the building of JWTs.
        Returns:
        The JwtClaimsSetBuilder instance that will build the claims set.
      • reconstruct

        public <T extends Jwt> T reconstruct​(String jwtString,
                                             Class<T> jwtClass)
        Reconstructs the given JWT string into a JWT object of the specified type.
        Type Parameters:
        T - The type of JWT the JWT string represents.
        Parameters:
        jwtString - The JWT string.
        jwtClass - The JWT class to reconstruct the JWT string to.
        Returns:
        The reconstructed JWT object.