@Immutable public final class JWTClaimsSet extends java.lang.Object
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 |
---|---|
java.util.List<java.lang.String> |
getAudience()
Gets the audience (
aud ) clam. |
java.lang.Boolean |
getBooleanClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Boolean . |
java.lang.Object |
getClaim(java.lang.String name)
Gets the specified claim (registered or custom).
|
java.util.Map<java.lang.String,java.lang.Object> |
getClaims()
Gets the claims (registered and custom).
|
java.util.Date |
getDateClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Date . |
java.lang.Double |
getDoubleClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Double . |
java.util.Date |
getExpirationTime()
Gets the expiration time (
exp ) claim. |
java.lang.Float |
getFloatClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Float . |
java.lang.Integer |
getIntegerClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Integer . |
java.lang.String |
getIssuer()
Gets the issuer (
iss ) claim. |
java.util.Date |
getIssueTime()
Gets the issued-at (
iat ) claim. |
java.lang.String |
getJWTID()
Gets the JWT ID (
jti ) claim. |
java.lang.Long |
getLongClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
Long . |
java.util.Date |
getNotBeforeTime()
Gets the not-before (
nbf ) claim. |
static java.util.Set<java.lang.String> |
getRegisteredNames()
Gets the registered JWT claim names.
|
java.lang.String[] |
getStringArrayClaim(java.lang.String name)
Gets the specified claims (registered or custom) as a
String array. |
java.lang.String |
getStringClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
String . |
java.util.List<java.lang.String> |
getStringListClaim(java.lang.String name)
Gets the specified claims (registered or custom) as a
List list of strings. |
java.lang.String |
getSubject()
Gets the subject (
sub ) claim. |
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(java.lang.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.
|
java.lang.String |
toString() |
<T> T |
toType(JWTClaimsSetTransformer<T> transformer)
Returns a transformation of this JWT claims set.
|
public static java.util.Set<java.lang.String> getRegisteredNames()
public java.lang.String getIssuer()
iss
) claim.null
if not specified.public java.lang.String getSubject()
sub
) claim.null
if not specified.public java.util.List<java.lang.String> getAudience()
aud
) clam.null
if not specified.public java.util.Date getExpirationTime()
exp
) claim.null
if not specified.public java.util.Date getNotBeforeTime()
nbf
) claim.null
if not specified.public java.util.Date getIssueTime()
iat
) claim.null
if not specified.public java.lang.String getJWTID()
jti
) claim.null
if not specified.public java.lang.Object getClaim(java.lang.String name)
name
- The name of the claim. Must not be null
.null
if not specified.public java.lang.String getStringClaim(java.lang.String name) throws java.text.ParseException
String
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.String[] getStringArrayClaim(java.lang.String name) throws java.text.ParseException
String
array.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.util.List<java.lang.String> getStringListClaim(java.lang.String name) throws java.text.ParseException
List
list of strings.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.Boolean getBooleanClaim(java.lang.String name) throws java.text.ParseException
Boolean
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.Integer getIntegerClaim(java.lang.String name) throws java.text.ParseException
Integer
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.Long getLongClaim(java.lang.String name) throws java.text.ParseException
Long
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.util.Date getDateClaim(java.lang.String name) throws java.text.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.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.Float getFloatClaim(java.lang.String name) throws java.text.ParseException
Float
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.lang.Double getDoubleClaim(java.lang.String name) throws java.text.ParseException
Double
.name
- The name of the claim. Must not be null
.null
if not specified.java.text.ParseException
- If the claim value is not of the required
type.public java.util.Map<java.lang.String,java.lang.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 java.lang.String toString()
toString
in class java.lang.Object
public <T> T toType(JWTClaimsSetTransformer<T> transformer)
transformer
- The JWT claims set transformer. Must not be
null
.public static JWTClaimsSet parse(net.minidev.json.JSONObject json) throws java.text.ParseException
json
- The JSON object to parse. Must not be null
.java.text.ParseException
- If the specified JSON object doesn't
represent a valid JWT claims set.public static JWTClaimsSet parse(java.lang.String s) throws java.text.ParseException
s
- The JSON object string to parse. Must not be null
.java.text.ParseException
- If the specified JSON object string doesn't
represent a valid JWT claims set.Copyright © 2015 Connect2id Ltd.. All Rights Reserved.