@Immutable public final class JWTClaimsSet extends Object implements Serializable
Supports all getRegisteredNames() registered claims} of the JWT
specification:
The set may also contain custom claims; these will be serialised and parsed along the registered ones.
Example JWT claims set:
{
"sub" : "joe",
"exp" : 1300819380,
"http://example.com/is_root" : true
}
Example usage:
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
.subject("joe")
.expirationTime(new Date(1300819380 * 1000l)
.claim("http://example.com/is_root", true)
.build();
| Modifier and Type | Class and Description |
|---|---|
static class |
JWTClaimsSet.Builder
Builder for constructing JSON Web Token (JWT) claims sets.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
List<String> |
getAudience()
Gets the audience (
aud) claim. |
Boolean |
getBooleanClaim(String name)
Gets the specified claim (registered or custom) as
Boolean. |
Object |
getClaim(String name)
Gets the specified claim (registered or custom).
|
Map<String,Object> |
getClaims()
Gets the claims (registered and custom).
|
Date |
getDateClaim(String name)
Gets the specified claim (registered or custom) as
Date. |
Double |
getDoubleClaim(String name)
Gets the specified claim (registered or custom) as
Double. |
Date |
getExpirationTime()
Gets the expiration time (
exp) claim. |
Float |
getFloatClaim(String name)
Gets the specified claim (registered or custom) as
Float. |
Integer |
getIntegerClaim(String name)
Gets the specified claim (registered or custom) as
Integer. |
String |
getIssuer()
Gets the issuer (
iss) claim. |
Date |
getIssueTime()
Gets the issued-at (
iat) claim. |
Map<String,Object> |
getJSONObjectClaim(String name)
Gets the specified claim (registered or custom) as a JSON object.
|
String |
getJWTID()
Gets the JWT ID (
jti) claim. |
Long |
getLongClaim(String name)
Gets the specified claim (registered or custom) as
Long. |
Date |
getNotBeforeTime()
Gets the not-before (
nbf) claim. |
static Set<String> |
getRegisteredNames()
Gets the registered JWT claim names.
|
String[] |
getStringArrayClaim(String name)
Gets the specified claims (registered or custom) as a
String array. |
String |
getStringClaim(String name)
Gets the specified claim (registered or custom) as
String. |
List<String> |
getStringListClaim(String name)
Gets the specified claims (registered or custom) as a
List list of strings. |
String |
getSubject()
Gets the subject (
sub) claim. |
URI |
getURIClaim(String name)
Gets the specified claim (registered or custom) as a
URI. |
int |
hashCode() |
static JWTClaimsSet |
parse(Map<String,Object> json)
Parses a JSON Web Token (JWT) claims set from the specified JSON
object representation.
|
static JWTClaimsSet |
parse(String s)
Parses a JSON Web Token (JWT) claims set from the specified JSON
object string representation.
|
Map<String,Object> |
toJSONObject()
Returns the JSON object representation of this claims set.
|
Map<String,Object> |
toJSONObject(boolean includeClaimsWithNullValues)
Returns the JSON object representation of this claims set.
|
Payload |
toPayload()
Returns a JOSE object payload representation of this claims set.
|
String |
toString()
Returns a JSON object string representation of this claims set.
|
String |
toString(boolean includeClaimsWithNullValues)
Returns a JSON object string representation of this claims set.
|
<T> T |
toType(JWTClaimsSetTransformer<T> transformer)
Returns a transformation of this JWT claims set.
|
public static Set<String> getRegisteredNames()
public String getIssuer()
iss) claim.null if not specified.public String getSubject()
sub) claim.null if not specified.public List<String> getAudience()
aud) claim.public Date getExpirationTime()
exp) claim.null if not specified.public Date getNotBeforeTime()
nbf) claim.null if not specified.public Date getIssueTime()
iat) claim.null if not specified.public String getJWTID()
jti) claim.null if not specified.public Object getClaim(String name)
name - The name of the claim. Must not be null.null if not specified.public String getStringClaim(String name) throws ParseException
String.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public String[] getStringArrayClaim(String name) throws ParseException
String array.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public List<String> getStringListClaim(String name) throws ParseException
List list of strings.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public URI getURIClaim(String name) throws ParseException
URI.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim couldn't be parsed to a URI.public Boolean getBooleanClaim(String name) throws ParseException
Boolean.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Integer getIntegerClaim(String name) throws ParseException
Integer.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Long getLongClaim(String name) throws ParseException
Long.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Date getDateClaim(String name) throws ParseException
Date. The claim may be represented by a Date
object or a number of a seconds since the Unix epoch.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Float getFloatClaim(String name) throws ParseException
Float.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Double getDoubleClaim(String name) throws ParseException
Double.name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Map<String,Object> getJSONObjectClaim(String name) throws ParseException
name - The name of the claim. Must not be null.null if not specified.ParseException - If the claim value is not of the required
type.public Map<String,Object> getClaims()
Note that the registered claims Expiration-Time (exp),
Not-Before-Time (nbf) and Issued-At (iat) will be
returned as java.util.Date instances.
public Payload toPayload()
public Map<String,Object> toJSONObject()
null values are not output.public Map<String,Object> toJSONObject(boolean includeClaimsWithNullValues)
includeClaimsWithNullValues - If true claims with
null values will also be
output.public String toString()
null values are not output.public String toString(boolean includeClaimsWithNullValues)
includeClaimsWithNullValues - If true claims with
null values will also be
output.public <T> T toType(JWTClaimsSetTransformer<T> transformer)
T - Type of the result.transformer - The JWT claims set transformer. Must not be
null.public static JWTClaimsSet parse(Map<String,Object> json) throws ParseException
json - The JSON object to parse. Must not be null.ParseException - If the specified JSON object doesn't
represent a valid JWT claims set.public static JWTClaimsSet parse(String s) throws ParseException
s - The JSON object string to parse. Must not be null.ParseException - If the specified JSON object string doesn't
represent a valid JWT claims set.Copyright © 2021 Connect2id Ltd.. All rights reserved.