Class 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 Detail

      • 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 Detail

      • issuer

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

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

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

        public JWTClaimsSet.Builder expirationTime​(Date exp)
        Sets the expiration time (exp) claim.
        Parameters:
        exp - The expiration time, null if not specified.
        Returns:
        This builder.
      • notBeforeTime

        public JWTClaimsSet.Builder notBeforeTime​(Date nbf)
        Sets the not-before (nbf) claim.
        Parameters:
        nbf - The not-before claim, null if not specified.
        Returns:
        This builder.
      • issueTime

        public JWTClaimsSet.Builder issueTime​(Date iat)
        Sets the issued-at (iat) claim.
        Parameters:
        iat - The issued-at claim, null if not specified.
        Returns:
        This builder.
      • jwtID

        public JWTClaimsSet.Builder jwtID​(String jti)
        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

        public Map<String,​ObjectgetClaims()
        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.