@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")
.expirationDate(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 |
|---|---|
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. |
net.minidev.json.JSONObject |
getJSONObjectClaim(String name)
Gets the specified claim (registered or custom) as a
JSONObject. |
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. |
static JWTClaimsSet |
parse(net.minidev.json.JSONObject 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.
|
net.minidev.json.JSONObject |
toJSONObject()
Returns the JSON object representation of the claims set.
|
String |
toString() |
<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 net.minidev.json.JSONObject getJSONObjectClaim(String name) throws ParseException
JSONObject.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 net.minidev.json.JSONObject toJSONObject()
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(net.minidev.json.JSONObject 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 © 2017 Connect2id Ltd.. All rights reserved.