public class JWTClaimsSet extends java.lang.Object implements ReadOnlyJWTClaimsSet
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.
Constructor and Description |
---|
JWTClaimsSet()
Creates a new empty JWT claims set.
|
JWTClaimsSet(ReadOnlyJWTClaimsSet old)
Creates a copy of the specified JWT claims set.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
getAllClaims()
Gets all claims, both registered and custom, as a single map.
|
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.lang.Object |
getCustomClaim(java.lang.String name)
Gets a custom (non-registered) claim.
|
java.util.Map<java.lang.String,java.lang.Object> |
getCustomClaims()
Gets the custom (non-registered) claims.
|
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 |
getStringClaim(java.lang.String name)
Gets the specified claim (registered or custom) as
String . |
java.lang.String |
getSubject()
Gets the subject (
sub ) claim. |
java.lang.String |
getType()
Gets the type (
typ ) 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.
|
void |
setAllClaims(java.util.Map<java.lang.String,java.lang.Object> newClaims)
Sets the claims of this JWT claims set, replacing any existing ones.
|
void |
setAudience(java.util.List<java.lang.String> aud)
Sets the audience (
aud ) claim. |
void |
setAudience(java.lang.String aud)
Sets a single-valued audience (
aud ) claim. |
void |
setClaim(java.lang.String name,
java.lang.Object value)
Sets the specified claim, whether registered or custom.
|
void |
setCustomClaim(java.lang.String name,
java.lang.Object value)
Sets a custom (non-registered) claim.
|
void |
setCustomClaims(java.util.Map<java.lang.String,java.lang.Object> customClaims)
Sets the custom (non-registered) claims.
|
void |
setExpirationTime(java.util.Date exp)
Sets the expiration time (
exp ) claim. |
void |
setIssuer(java.lang.String iss)
Sets the issuer (
iss ) claim. |
void |
setIssueTime(java.util.Date iat)
Sets the issued-at (
iat ) claim. |
void |
setJWTID(java.lang.String jti)
Sets the JWT ID (
jti ) claim. |
void |
setNotBeforeTime(java.util.Date nbf)
Sets the not-before (
nbf ) claim. |
void |
setSubject(java.lang.String sub)
Sets the subject (
sub ) claim. |
void |
setType(java.lang.String typ)
Sets the type (
typ ) claim. |
net.minidev.json.JSONObject |
toJSONObject()
Returns the JSON object representation of the claims set.
|
java.lang.String |
toString() |
public JWTClaimsSet()
public JWTClaimsSet(ReadOnlyJWTClaimsSet old)
old
- The JWT claims set to copy. Must not be null
.public static java.util.Set<java.lang.String> getRegisteredNames()
public java.lang.String getIssuer()
ReadOnlyJWTClaimsSet
iss
) claim.getIssuer
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setIssuer(java.lang.String iss)
iss
) claim.iss
- The issuer claim, null
if not specified.public java.lang.String getSubject()
ReadOnlyJWTClaimsSet
sub
) claim.getSubject
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setSubject(java.lang.String sub)
sub
) claim.sub
- The subject claim, null
if not specified.public java.util.List<java.lang.String> getAudience()
ReadOnlyJWTClaimsSet
aud
) clam.getAudience
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setAudience(java.util.List<java.lang.String> aud)
aud
) claim.aud
- The audience claim, null
if not specified.public void setAudience(java.lang.String aud)
aud
) claim.aud
- The audience claim, null
if not specified.public java.util.Date getExpirationTime()
ReadOnlyJWTClaimsSet
exp
) claim.getExpirationTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setExpirationTime(java.util.Date exp)
exp
) claim.exp
- The expiration time, null
if not specified.public java.util.Date getNotBeforeTime()
ReadOnlyJWTClaimsSet
nbf
) claim.getNotBeforeTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setNotBeforeTime(java.util.Date nbf)
nbf
) claim.nbf
- The not-before claim, null
if not specified.public java.util.Date getIssueTime()
ReadOnlyJWTClaimsSet
iat
) claim.getIssueTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setIssueTime(java.util.Date iat)
iat
) claim.iat
- The issued-at claim, null
if not specified.public java.lang.String getJWTID()
ReadOnlyJWTClaimsSet
jti
) claim.getJWTID
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setJWTID(java.lang.String jti)
jti
) claim.jti
- The JWT ID claim, null
if not specified.public java.lang.String getType()
ReadOnlyJWTClaimsSet
typ
) claim.getType
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setType(java.lang.String typ)
typ
) claim.typ
- The type claim, null
if not specified.public java.lang.Object getCustomClaim(java.lang.String name)
ReadOnlyJWTClaimsSet
getCustomClaim
in interface ReadOnlyJWTClaimsSet
name
- The name of the custom claim. Must not be null
.null
if not
specified.public void setCustomClaim(java.lang.String name, java.lang.Object value)
name
- The name of the custom claim. Must not be null
.value
- The value of the custom claim, should map to a valid
JSON entity, null
if not specified.java.lang.IllegalArgumentException
- If the specified custom claim name
matches a registered claim name.public java.util.Map<java.lang.String,java.lang.Object> getCustomClaims()
ReadOnlyJWTClaimsSet
getCustomClaims
in interface ReadOnlyJWTClaimsSet
public void setCustomClaims(java.util.Map<java.lang.String,java.lang.Object> customClaims)
customClaims
- The custom claims, empty map or null
if
none.public java.lang.Object getClaim(java.lang.String name)
ReadOnlyJWTClaimsSet
getClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
String
.getStringClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Boolean
.getBooleanClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Integer
.getIntegerClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Long
.getLongClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Float
.getFloatClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Double
.getDoubleClaim
in interface ReadOnlyJWTClaimsSet
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 void setClaim(java.lang.String name, java.lang.Object value)
name
- The name of the claim to set. Must not be null
.value
- The value of the claim to set, null
if not
specified.java.lang.IllegalArgumentException
- If the claim is registered and its
value is not of the expected type.public java.util.Map<java.lang.String,java.lang.Object> getAllClaims()
ReadOnlyJWTClaimsSet
Note that the registered claims Expiration-Time (exp
),
Not-Before-Time (nbf
) and Issued-At (iat
) will be
returned as java.util.Date
instances.
getAllClaims
in interface ReadOnlyJWTClaimsSet
public void setAllClaims(java.util.Map<java.lang.String,java.lang.Object> newClaims)
newClaims
- The JWT claims. Must not be null
.public net.minidev.json.JSONObject toJSONObject()
ReadOnlyJWTClaimsSet
toJSONObject
in interface ReadOnlyJWTClaimsSet
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.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014 Connect2id Ltd.. All Rights Reserved.