Package com.nimbusds.jwt
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 Summary
Constructors Constructor Description Builder()
Creates a new builder.Builder(JWTClaimsSet jwtClaimsSet)
Creates a new builder with the claims from the specified set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JWTClaimsSet.Builder
audience(String aud)
Sets a single-valued audience (aud
) claim.JWTClaimsSet.Builder
audience(List<String> aud)
Sets the audience (aud
) claim.JWTClaimsSet
build()
Builds a new JWT claims set.JWTClaimsSet.Builder
claim(String name, Object value)
Sets the specified claim (registered or custom).JWTClaimsSet.Builder
expirationTime(Date exp)
Sets the expiration time (exp
) claim.Map<String,Object>
getClaims()
Gets the claims (registered and custom).JWTClaimsSet.Builder
issuer(String iss)
Sets the issuer (iss
) claim.JWTClaimsSet.Builder
issueTime(Date iat)
Sets the issued-at (iat
) claim.JWTClaimsSet.Builder
jwtID(String jti)
Sets the JWT ID (jti
) claim.JWTClaimsSet.Builder
notBeforeTime(Date nbf)
Sets the not-before (nbf
) claim.JWTClaimsSet.Builder
subject(String sub)
Sets the subject (sub
) claim.
-
-
-
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 benull
.
-
-
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(List<String> aud)
Sets the audience (aud
) claim.- Parameters:
aud
- The audience 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 benull
.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,Object> 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
public JWTClaimsSet build()
Builds a new JWT claims set.- Returns:
- The JWT claims set.
-
-