com.nimbusds.jwt
Class JWTClaimsSet

java.lang.Object
  extended by com.nimbusds.jwt.JWTClaimsSet
All Implemented Interfaces:
ReadOnlyJWTClaimsSet

public class JWTClaimsSet
extends Object
implements ReadOnlyJWTClaimsSet

JSON Web Token (JWT) claims set.

Supports all reserved claims of the JWT specification:

The set may also carry custom claims; these will be serialised and parsed along the reserved ones.

Version:
$version$ (2013-04-08)
Author:
Vladimir Dzhuvinov, Justin Richer

Constructor Summary
JWTClaimsSet()
          Creates a new empty JWT claims set.
JWTClaimsSet(ReadOnlyJWTClaimsSet old)
          Creates a copy of the specified JWT claims set.
 
Method Summary
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.
 Object getClaim(String name)
          Gets a single claim by name, whether reserved or custom.
 Object getCustomClaim(String name)
          Gets a custom (non-reserved) claim.
 Map<String,Object> getCustomClaims()
          Gets the custom (non-reserved) claims.
 Date getExpirationTime()
          Gets the expiration time (exp) claim.
 String getIssuer()
          Gets the issuer (iss) claim.
 Date getIssueTime()
          Gets the issued-at (iat) claim.
 String getJWTID()
          Gets the JWT ID (jti) claim.
 Date getNotBeforeTime()
          Gets the not-before (nbf) claim.
static Set<String> getReservedNames()
          Gets the reserved JWT claim names.
 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.
 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) clam.
 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()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JWTClaimsSet

public JWTClaimsSet()
Creates a new empty JWT claims set.


JWTClaimsSet

public JWTClaimsSet(ReadOnlyJWTClaimsSet old)
Creates a copy of the specified JWT claims set.

Parameters:
old - The JWT claims set to copy. Must not be null.
Method Detail

clone

protected Object clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getReservedNames

public static Set<String> getReservedNames()
Gets the reserved JWT claim names.

Returns:
The reserved claim names, as an unmodifiable set.

getIssuer

public String getIssuer()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the issuer (iss) claim.

Specified by:
getIssuer in interface ReadOnlyJWTClaimsSet
Returns:
The issuer claim, null if not specified.

setIssuer

public void setIssuer(String iss)
Sets the issuer (iss) claim.

Parameters:
iss - The issuer claim, null if not specified.

getSubject

public String getSubject()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the subject (sub) claim.

Specified by:
getSubject in interface ReadOnlyJWTClaimsSet
Returns:
The subject claim, null if not specified.

setSubject

public void setSubject(String sub)
Sets the subject (sub) claim.

Parameters:
sub - The subject claim, null if not specified.

getAudience

public List<String> getAudience()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the audience (aud) clam.

Specified by:
getAudience in interface ReadOnlyJWTClaimsSet
Returns:
The audience claim, null if not specified.

setAudience

public void setAudience(List<String> aud)
Sets the audience (aud) clam.

Parameters:
aud - The audience claim, null if not specified.

getExpirationTime

public Date getExpirationTime()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the expiration time (exp) claim.

Specified by:
getExpirationTime in interface ReadOnlyJWTClaimsSet
Returns:
The expiration time, null if not specified.

setExpirationTime

public void setExpirationTime(Date exp)
Sets the expiration time (exp) claim.

Parameters:
exp - The expiration time, null if not specified.

getNotBeforeTime

public Date getNotBeforeTime()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the not-before (nbf) claim.

Specified by:
getNotBeforeTime in interface ReadOnlyJWTClaimsSet
Returns:
The not-before claim, null if not specified.

setNotBeforeTime

public void setNotBeforeTime(Date nbf)
Sets the not-before (nbf) claim.

Parameters:
nbf - The not-before claim, null if not specified.

getIssueTime

public Date getIssueTime()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the issued-at (iat) claim.

Specified by:
getIssueTime in interface ReadOnlyJWTClaimsSet
Returns:
The issued-at claim, null if not specified.

setIssueTime

public void setIssueTime(Date iat)
Sets the issued-at (iat) claim.

Parameters:
iat - The issued-at claim, null if not specified.

getJWTID

public String getJWTID()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the JWT ID (jti) claim.

Specified by:
getJWTID in interface ReadOnlyJWTClaimsSet
Returns:
The JWT ID claim, null if not specified.

setJWTID

public void setJWTID(String jti)
Sets the JWT ID (jti) claim.

Parameters:
jti - The JWT ID claim, null if not specified.

getType

public String getType()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the type (typ) claim.

Specified by:
getType in interface ReadOnlyJWTClaimsSet
Returns:
The type claim, null if not specified.

setType

public void setType(String typ)
Sets the type (typ) claim.

Parameters:
typ - The type claim, null if not specified.

getCustomClaim

public Object getCustomClaim(String name)
Description copied from interface: ReadOnlyJWTClaimsSet
Gets a custom (non-reserved) claim.

Specified by:
getCustomClaim in interface ReadOnlyJWTClaimsSet
Parameters:
name - The name of the custom claim. Must not be null.
Returns:
The value of the custom claim, null if not specified.

setCustomClaim

public void setCustomClaim(String name,
                           Object value)
Sets a custom (non-reserved) claim.

Parameters:
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.
Throws:
IllegalArgumentException - If the specified custom claim name matches a reserved claim name.

getCustomClaims

public Map<String,Object> getCustomClaims()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the custom (non-reserved) claims.

Specified by:
getCustomClaims in interface ReadOnlyJWTClaimsSet
Returns:
The custom claims, as a unmodifiable map, empty map if none.

setCustomClaims

public void setCustomClaims(Map<String,Object> customClaims)
Sets the custom (non-reserved) claims. The values must be serialisable to a JSON entity, otherwise will be ignored.

Parameters:
customClaims - The custom claims, empty map or null if none.

getClaim

public Object getClaim(String name)
Description copied from interface: ReadOnlyJWTClaimsSet
Gets a single claim by name, whether reserved or custom.

Specified by:
getClaim in interface ReadOnlyJWTClaimsSet
Parameters:
name - The name of the claim to get. Must not be null.
Returns:
The value of the claim, null if not specified.

setClaim

public void setClaim(String name,
                     Object value)
Sets the specified claim, whether reserved or custom.

Parameters:
name - The name of the claim to set. Must not be null.
value - The value of the claim to set. May be null.
Throws:
IllegalArgumentException - If the claim is reserved and its value is not of the expected type.

getAllClaims

public Map<String,Object> getAllClaims()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets all claims, both reserved and custom, as a single map.

Note that the reserved claims Expiration-Time (exp), Not-Before-Time (nbf) and Issued-At (iat) will be returned as java.util.Date instances.

Specified by:
getAllClaims in interface ReadOnlyJWTClaimsSet
Returns:
All claims, as an unmodifiable map, empty map if none.

setAllClaims

public void setAllClaims(Map<String,Object> newClaims)
Sets the claims of this JWT claims set, replacing any existing ones.

Parameters:
newClaims - The JWT claims. Must not be null.

toJSONObject

public net.minidev.json.JSONObject toJSONObject()
Description copied from interface: ReadOnlyJWTClaimsSet
Returns the JSON object representation of the claims set.

Specified by:
toJSONObject in interface ReadOnlyJWTClaimsSet
Returns:
The JSON object representation.

parse

public static JWTClaimsSet parse(net.minidev.json.JSONObject json)
                          throws ParseException
Parses a JSON Web Token (JWT) claims set from the specified JSON object representation.

Parameters:
json - The JSON object to parse. Must not be null.
Returns:
The JWT claims set.
Throws:
ParseException - If the specified JSON object doesn't represent a valid JWT claims set.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 NimbusDS. All Rights Reserved.