Package com.nimbusds.jwt
Class JWTClaimsSet.Builder
java.lang.Object
com.nimbusds.jwt.JWTClaimsSet.Builder
- Enclosing class:
- JWTClaimsSet
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 Summary
ConstructorsConstructorDescriptionBuilder()
Creates a new builder.Builder
(JWTClaimsSet jwtClaimsSet) Creates a new builder with the claims from the specified set. -
Method Summary
Modifier and TypeMethodDescriptionSets a single-valued audience (aud
) claim.Sets the audience (aud
) claim.build()
Builds a new JWT claims set.Sets the specified claim (registered or custom).expirationTime
(Date exp) Sets the expiration time (exp
) claim.Gets the claims (registered and custom).Sets the issuer (iss
) claim.Sets the issued-at (iat
) claim.Sets the JWT ID (jti
) claim.notBeforeTime
(Date nbf) Sets the not-before (nbf
) claim.serializeNullClaims
(boolean enable) Controls the serialisation of claims withnull
values whenJWTClaimsSet.toPayload()
/JWTClaimsSet.toJSONObject()
/Object.toString()
is called.Sets the subject (sub
) claim.
-
Constructor Details
-
Builder
public Builder()Creates a new builder. -
Builder
Creates a new builder with the claims from the specified set.- Parameters:
jwtClaimsSet
- The JWT claims set to use. Must not benull
.
-
-
Method Details
-
serializeNullClaims
Controls the serialisation of claims withnull
values whenJWTClaimsSet.toPayload()
/JWTClaimsSet.toJSONObject()
/Object.toString()
is called. Disabled by default.- Parameters:
enable
-true
to serialise claims withnull
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
Sets the specified claim (registered or custom).- Parameters:
name
- The name of the claim to set. Must not benull
.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 asjava.util.Date
instances.- Returns:
- The claims, as an unmodifiable map, empty map if none.
-
build
Builds a new JWT claims set.- Returns:
- The JWT claims set.
-