Class JWTClaimsSet.Builder

java.lang.Object
com.nimbusds.jwt.JWTClaimsSet.Builder
Enclosing class:
JWTClaimsSet

public static class JWTClaimsSet.Builder extends Object
Builder for constructing JSON Web Token (JWT) claims sets.

Example usage:

 JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
     .subject("joe")
     .expirationDate(new Date(1300819380 * 1000l)
     .claim("http://example.com/is_root", true)
     .build();
 
  • Constructor Details

    • Builder

      public Builder()
      Creates a new builder.
    • Builder

      public Builder(JWTClaimsSet jwtClaimsSet)
      Creates a new builder with the claims from the specified set.
      Parameters:
      jwtClaimsSet - The JWT claims set to use. Must not be null.
  • Method Details

    • serializeNullClaims

      public JWTClaimsSet.Builder serializeNullClaims(boolean enable)
      Controls the serialisation of claims with null values when JWTClaimsSet.toPayload() / JWTClaimsSet.toJSONObject() / Object.toString() is called. Disabled by default.
      Parameters:
      enable - true to serialise claims with null values, false to omit them.
      Returns:
      This builder.
    • issuer

      Sets the issuer (iss) claim.
      Parameters:
      iss - The issuer claim, null if not specified.
      Returns:
      This builder.
    • subject

      Sets the subject (sub) claim.
      Parameters:
      sub - The subject claim, null if not specified.
      Returns:
      This builder.
    • audience

      Sets the audience (aud) claim.
      Parameters:
      aud - The audience claim, null if not specified.
      Returns:
      This builder.
    • audience

      Sets a single-valued audience (aud) claim.
      Parameters:
      aud - The audience claim, null if not specified.
      Returns:
      This builder.
    • expirationTime

      Sets the expiration time (exp) claim.
      Parameters:
      exp - The expiration time, null if not specified.
      Returns:
      This builder.
    • notBeforeTime

      Sets the not-before (nbf) claim.
      Parameters:
      nbf - The not-before claim, null if not specified.
      Returns:
      This builder.
    • issueTime

      Sets the issued-at (iat) claim.
      Parameters:
      iat - The issued-at claim, null if not specified.
      Returns:
      This builder.
    • jwtID

      Sets the JWT ID (jti) claim.
      Parameters:
      jti - The JWT ID claim, null if not specified.
      Returns:
      This builder.
    • claim

      public JWTClaimsSet.Builder claim(String name, Object value)
      Sets the specified claim (registered or custom).
      Parameters:
      name - The name of the claim to set. Must not be null.
      value - The value of the claim to set, null if not specified. Should map to a JSON entity.
      Returns:
      This builder.
    • getClaims

      Gets the claims (registered and custom).

      Note that the registered claims Expiration-Time (exp), Not-Before-Time (nbf) and Issued-At (iat) will be returned as java.util.Date instances.

      Returns:
      The claims, as an unmodifiable map, empty map if none.
    • build

      public JWTClaimsSet build()
      Builds a new JWT claims set.
      Returns:
      The JWT claims set.