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-01-15)
Author:
Vladimir Dzhuvinov

Constructor Summary
JWTClaimsSet()
          Creates a new empty JWT claims set.
 
Method Summary
 String[] getAudienceClaim()
          Gets the audience (aud) clam.
 Object getCustomClaim(String name)
          Gets a custom (non-reserved) claim.
 Map<String,Object> getCustomClaims()
          Gets the custom (non-reserved) claims.
 long getExpirationTimeClaim()
          Gets the expiration time (exp) claim.
 long getIssuedAtClaim()
          Gets the issued-at (iat) claim.
 String getIssuerClaim()
          Gets the issuer (iss) claim.
 String getJWTIDClaim()
          Gets the JWT ID (jti) claim.
 long getNotBeforeClaim()
          Gets the not-before (nbf) claim.
static Set<String> getReservedNames()
          Gets the reserved JWT claim names.
 String getSubjectClaim()
          Gets the subject (sub) claim.
 String getTypeClaim()
          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 setAudienceClaim(String[] aud)
          Sets the audience (aud) clam.
 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 setExpirationTimeClaim(long exp)
          Sets the expiration time (exp) claim.
 void setIssuedAtClaim(long iat)
          Sets the issued-at (iat) claim.
 void setIssuerClaim(String iss)
          Sets the issuer (iss) claim.
 void setJWTIDClaim(String jti)
          Sets the JWT ID (jti) claim.
 void setNotBeforeClaim(long nbf)
          Sets the not-before (nbf) claim.
 void setSubjectClaim(String sub)
          Sets the subject (sub) claim.
 void setTypeClaim(String typ)
          Sets the type (typ) claim.
 net.minidev.json.JSONObject toJSONObject()
          Returns the JSON object representation of the claims set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JWTClaimsSet

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

Method Detail

getReservedNames

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

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

getIssuerClaim

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

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

setIssuerClaim

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

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

getSubjectClaim

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

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

setSubjectClaim

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

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

getAudienceClaim

public String[] getAudienceClaim()
Description copied from interface: ReadOnlyJWTClaimsSet
Gets the audience (aud) clam.

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

setAudienceClaim

public void setAudienceClaim(String[] aud)
Sets the audience (aud) clam.

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

getExpirationTimeClaim

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

Specified by:
getExpirationTimeClaim in interface ReadOnlyJWTClaimsSet
Returns:
The expiration time, -1 if not specified.

setExpirationTimeClaim

public void setExpirationTimeClaim(long exp)
Sets the expiration time (exp) claim.

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

getNotBeforeClaim

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

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

setNotBeforeClaim

public void setNotBeforeClaim(long nbf)
Sets the not-before (nbf) claim.

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

getIssuedAtClaim

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

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

setIssuedAtClaim

public void setIssuedAtClaim(long iat)
Sets the issued-at (iat) claim.

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

getJWTIDClaim

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

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

setJWTIDClaim

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

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

getTypeClaim

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

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

setTypeClaim

public void setTypeClaim(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.

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.


Copyright © 2013 NimbusDS. All Rights Reserved.