public class JWTClaimsSet extends Object implements ReadOnlyJWTClaimsSet
Supports all reserved claims
of the JWT
specification:
The set may also contain custom claims
; these
will be serialised and parsed along the reserved 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 |
---|---|
protected Object |
clone() |
Map<String,Object> |
getAllClaims()
Gets all claims, both reserved and custom, as a single map.
|
List<String> |
getAudience()
Gets the audience (
aud ) clam. |
Boolean |
getBooleanClaim(String name)
Gets the specified claim (reserved or custom) as
Boolean . |
Object |
getClaim(String name)
Gets the specified claim (reserved or custom).
|
Object |
getCustomClaim(String name)
Gets a custom (non-reserved) claim.
|
Map<String,Object> |
getCustomClaims()
Gets the custom (non-reserved) claims.
|
Double |
getDoubleClaim(String name)
Gets the specified claim (reserved or custom) as
Double . |
Date |
getExpirationTime()
Gets the expiration time (
exp ) claim. |
Float |
getFloatClaim(String name)
Gets the specified claim (reserved or custom) as
Float . |
Integer |
getIntegerClaim(String name)
Gets the specified claim (reserved or custom) as
Integer . |
String |
getIssuer()
Gets the issuer (
iss ) claim. |
Date |
getIssueTime()
Gets the issued-at (
iat ) claim. |
String |
getJWTID()
Gets the JWT ID (
jti ) claim. |
Long |
getLongClaim(String name)
Gets the specified claim (reserved or custom) as
Long . |
Date |
getNotBeforeTime()
Gets the not-before (
nbf ) claim. |
static Set<String> |
getReservedNames()
Gets the reserved JWT claim names.
|
String |
getStringClaim(String name)
Gets the specified claim (reserved or custom) as
String . |
String |
getSubject()
Gets the subject (
sub ) claim. |
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(String s)
Parses a JSON Web Token (JWT) claims set from the specified JSON
object string representation.
|
void |
setAllClaims(Map<String,Object> newClaims)
Sets the claims of this JWT claims set, replacing any existing ones.
|
void |
setAudience(List<String> aud)
Sets the audience (
aud ) claim. |
void |
setClaim(String name,
Object value)
Sets the specified claim, whether reserved or custom.
|
void |
setCustomClaim(String name,
Object value)
Sets a custom (non-reserved) claim.
|
void |
setCustomClaims(Map<String,Object> customClaims)
Sets the custom (non-reserved) claims.
|
void |
setExpirationTime(Date exp)
Sets the expiration time (
exp ) claim. |
void |
setIssuer(String iss)
Sets the issuer (
iss ) claim. |
void |
setIssueTime(Date iat)
Sets the issued-at (
iat ) claim. |
void |
setJWTID(String jti)
Sets the JWT ID (
jti ) claim. |
void |
setNotBeforeTime(Date nbf)
Sets the not-before (
nbf ) claim. |
void |
setSubject(String sub)
Sets the subject (
sub ) claim. |
void |
setType(String typ)
Sets the type (
typ ) claim. |
net.minidev.json.JSONObject |
toJSONObject()
Returns the JSON object representation of the claims set.
|
String |
toString() |
public JWTClaimsSet()
public JWTClaimsSet(ReadOnlyJWTClaimsSet old)
old
- The JWT claims set to copy. Must not be null
.protected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public static Set<String> getReservedNames()
public String getIssuer()
ReadOnlyJWTClaimsSet
iss
) claim.getIssuer
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setIssuer(String iss)
iss
) claim.iss
- The issuer claim, null
if not specified.public String getSubject()
ReadOnlyJWTClaimsSet
sub
) claim.getSubject
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setSubject(String sub)
sub
) claim.sub
- The subject claim, null
if not specified.public List<String> getAudience()
ReadOnlyJWTClaimsSet
aud
) clam.getAudience
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setAudience(List<String> aud)
aud
) claim.aud
- The audience claim, null
if not specified.public Date getExpirationTime()
ReadOnlyJWTClaimsSet
exp
) claim.getExpirationTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setExpirationTime(Date exp)
exp
) claim.exp
- The expiration time, null
if not specified.public Date getNotBeforeTime()
ReadOnlyJWTClaimsSet
nbf
) claim.getNotBeforeTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setNotBeforeTime(Date nbf)
nbf
) claim.nbf
- The not-before claim, null
if not specified.public Date getIssueTime()
ReadOnlyJWTClaimsSet
iat
) claim.getIssueTime
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setIssueTime(Date iat)
iat
) claim.iat
- The issued-at claim, null
if not specified.public String getJWTID()
ReadOnlyJWTClaimsSet
jti
) claim.getJWTID
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setJWTID(String jti)
jti
) claim.jti
- The JWT ID claim, null
if not specified.public String getType()
ReadOnlyJWTClaimsSet
typ
) claim.getType
in interface ReadOnlyJWTClaimsSet
null
if not specified.public void setType(String typ)
typ
) claim.typ
- The type claim, null
if not specified.public Object getCustomClaim(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(String name, 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.IllegalArgumentException
- If the specified custom claim name
matches a reserved claim name.public Map<String,Object> getCustomClaims()
ReadOnlyJWTClaimsSet
getCustomClaims
in interface ReadOnlyJWTClaimsSet
public void setCustomClaims(Map<String,Object> customClaims)
customClaims
- The custom claims, empty map or null
if
none.public Object getClaim(String name)
ReadOnlyJWTClaimsSet
getClaim
in interface ReadOnlyJWTClaimsSet
name
- The name of the claim. Must not be null
.null
if not specified.public String getStringClaim(String name) throws ParseException
ReadOnlyJWTClaimsSet
String
.getStringClaim
in interface ReadOnlyJWTClaimsSet
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 Boolean getBooleanClaim(String name) throws ParseException
ReadOnlyJWTClaimsSet
Boolean
.getBooleanClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Integer
.getIntegerClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Long
.getLongClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Float
.getFloatClaim
in interface ReadOnlyJWTClaimsSet
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
ReadOnlyJWTClaimsSet
Double
.getDoubleClaim
in interface ReadOnlyJWTClaimsSet
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 void setClaim(String name, 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.IllegalArgumentException
- If the claim is reserved and its
value is not of the expected type.public Map<String,Object> getAllClaims()
ReadOnlyJWTClaimsSet
Note that the reserved 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(Map<String,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 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 © 2013 NimbusDS. All Rights Reserved.