com.nimbusds.jwt
Class ClaimsSet

java.lang.Object
  extended by com.nimbusds.jwt.ClaimsSet
All Implemented Interfaces:
ReadOnlyClaimsSet

public class ClaimsSet
extends Object
implements ReadOnlyClaimsSet

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

Constructor Summary
ClaimsSet()
          Creates a new empty claims set.
 
Method Summary
 String[] getAudienceClaim()
          Gets the audience (aud) clam.
 Object getCustomClaim(String name)
          Gets a custom (public or private) 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 claim names.
 String getSubjectClaim()
          Gets the subject (sub) claim.
 String getTypeClaim()
          Gets the type (typ) claim.
static ClaimsSet 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 (public or private) 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

ClaimsSet

public ClaimsSet()
Creates a new empty claims set.

Method Detail

getReservedNames

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

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

getIssuerClaim

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

Specified by:
getIssuerClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the subject (sub) claim.

Specified by:
getSubjectClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the audience (aud) clam.

Specified by:
getAudienceClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the expiration time (exp) claim.

Specified by:
getExpirationTimeClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the not-before (nbf) claim.

Specified by:
getNotBeforeClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the issued-at (iat) claim.

Specified by:
getIssuedAtClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the JWT ID (jti) claim.

Specified by:
getJWTIDClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets the type (typ) claim.

Specified by:
getTypeClaim in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Gets a custom (public or private) claim.

Specified by:
getCustomClaim in interface ReadOnlyClaimsSet
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 (public or private) 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: ReadOnlyClaimsSet
Gets the custom (non-reserved) claims.

Specified by:
getCustomClaims in interface ReadOnlyClaimsSet
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: ReadOnlyClaimsSet
Returns the JSON object representation of the claims set.

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

parse

public static ClaimsSet 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 claims set.
Throws:
ParseException - If the specified JSON object doesn't represent a valid JWT claims set.


Copyright © 2013 NimbusDS. All Rights Reserved.