Package iu.crypt

Class JwtBuilder<B extends JwtBuilder<B>>

Type Parameters:
B - Concrete builder type
All Implemented Interfaces:
WebTokenBuilder
Direct Known Subclasses:
SessionJwtBuilder

public class JwtBuilder<B extends JwtBuilder<B>> extends IuJsonBuilder<B> implements WebTokenBuilder
Mutable builder implementation for programmatically constructing new Jwt instances.

Modules that provide a subclass of Jwt SHOULD also provide a subclass of this class that overrides build().

  • Constructor Details

    • JwtBuilder

      public JwtBuilder()
      Default constructor
  • Method Details

    • jti

      public B jti()
      Description copied from interface: WebTokenBuilder
      Generates a unique token identifier.
      Specified by:
      jti in interface WebTokenBuilder
      Returns:
      this
    • jti

      public B jti(String tokenId)
      Description copied from interface: WebTokenBuilder
      Provides a specific token identifier.
      Specified by:
      jti in interface WebTokenBuilder
      Parameters:
      tokenId - token identifier
      Returns:
      this
    • iss

      public B iss(URI issuer)
      Description copied from interface: WebTokenBuilder
      Sets the token issuer URI.
      Specified by:
      iss in interface WebTokenBuilder
      Parameters:
      issuer - URI
      Returns:
      this
    • aud

      public B aud(URI... audience)
      Description copied from interface: WebTokenBuilder
      Sets the token audience URIs.
      Specified by:
      aud in interface WebTokenBuilder
      Parameters:
      audience - at least one URI
      Returns:
      this
    • sub

      public B sub(String subject)
      Description copied from interface: WebTokenBuilder
      Sets the subject of the JWT.
      Specified by:
      sub in interface WebTokenBuilder
      Parameters:
      subject - (sub claim)
      Returns:
      this
    • iat

      public B iat()
      Description copied from interface: WebTokenBuilder
      Indicates that WebTokenBuilder.build() should set the issued at time to the current time.
      Specified by:
      iat in interface WebTokenBuilder
      Returns:
      this
    • nbf

      public B nbf(Instant notBefore)
      Description copied from interface: WebTokenBuilder
      Sets the time before which the JWT should not be accepted.
      Specified by:
      nbf in interface WebTokenBuilder
      Parameters:
      notBefore - not before time (nbf claim)
      Returns:
      this
    • exp

      public B exp(Instant expires)
      Description copied from interface: WebTokenBuilder
      Sets the time after which the JWT should not be accepted.
      Specified by:
      exp in interface WebTokenBuilder
      Parameters:
      expires - token expiration time (exp claim)
      Returns:
      this
    • nonce

      public B nonce(String nonce)
      Description copied from interface: WebTokenBuilder
      Sets the nonce claim.
      Specified by:
      nonce in interface WebTokenBuilder
      Parameters:
      nonce - nonce claim value
      Returns:
      this
      See Also:
    • prepare

      protected void prepare()
      Applies state just prior to building the token.

      Call this method when overriding build() to apply any final state, e.g., setting the iat claim value.

    • build

      public WebToken build()
      Description copied from interface: WebTokenBuilder
      Builds a WebToken instance based on provided claim values.
      Specified by:
      build in interface WebTokenBuilder
      Returns:
      WebToken