Class JwtClaimsSet
- java.lang.Object
-
- org.forgerock.json.jose.jwt.JWObject
-
- org.forgerock.json.jose.jwt.JwtClaimsSet
-
-
Constructor Summary
Constructors Constructor Description JwtClaimsSet()
Constructs a new, empty JwtClaimsSet.JwtClaimsSet(Map<String,Object> claims)
Constructs a new JwtClaimsSet, with its claims set to the contents of the given Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAudience(String audience)
Adds an entry to the JWT's intended audience list, in the Claims Set.void
addAudience(URI audience)
Adds an entry to the JWT's intended audience list, in the Claims Set.String
build()
Builds the JWT's Claims Set into aString
representation of a JSON object.JwtClaimsSet
copy()
Create a copy of the current payload.List<String>
getAudience()
Gets the intended audience for the JWT from the Claims Set.Object
getClaim(String key)
Gets a claim value for the specified key.<T> T
getClaim(String key, Class<T> clazz)
Gets a claim value for the specified claim name and then casts it to the specified type.Date
getExpirationTime()
Gets the expiration time of the JWT from the Claims Set.Date
getIssuedAtTime()
Gets the time the JWT was issued at, from the Claims Set.String
getIssuer()
Gets the issuer this JWT was issued by.String
getJwtId()
Gets the unique ID of the JWT.Date
getNotBeforeTime()
Gets the time the JWT is not allowed to be processed before, from the Claims Set.String
getSubject()
Gets the subject this JWT is issued to.String
getType()
Gets the type of the contents of the Claims Set.void
setClaim(String key, Object value)
Sets a claim with the specified name and value.void
setClaims(Map<String,Object> claims)
Sets claims using the values contained in the specified map.void
setExpirationTime(Date expirationTime)
Sets the expiration time of the JWT in the Claims Set.void
setIssuedAtTime(Date issuedAtTime)
Sets the time the JWT was issued at, in the Claims Set.void
setIssuer(String issuer)
Sets the issuer this JWT was issued by.void
setIssuer(URI issuer)
Sets the issuer this JWT was issued by.void
setJwtId(String jwtId)
Sets the unique ID of the JWT.void
setNotBeforeTime(Date notBeforeTime)
Sets the time the JWT is not allowed to be processed before, in the Claims Set.void
setSubject(String subject)
Sets the subject this JWT is issued to.void
setSubject(URI subject)
Sets the subject this JWT is issued to.void
setType(String type)
Gets the type of the contents of the Claims Set.-
Methods inherited from class org.forgerock.json.jose.jwt.JWObject
checkListValuesAreOfType, checkValueIsOfType, equals, get, hashCode, isDefined, isValueOfType, keys, put, toJsonValue, toString
-
-
-
-
Method Detail
-
setType
public void setType(String type)
Gets the type of the contents of the Claims Set.The values used for this claim SHOULD come from the same value space as the JWT header parameter "typ", with the same rules applying.
- Parameters:
type
- The Claims Set content type.
-
getType
public String getType()
Gets the type of the contents of the Claims Set.The values used for this claim SHOULD come from the same value space as the JWT header parameter "typ", with the same rules applying.
- Returns:
- The Claims Set content type.
-
setJwtId
public void setJwtId(String jwtId)
Sets the unique ID of the JWT.- Parameters:
jwtId
- The JWT's ID.
-
getJwtId
public String getJwtId()
Gets the unique ID of the JWT.- Returns:
- The JWT's ID or
null
if claim not present.
-
setIssuer
public void setIssuer(String issuer)
Sets the issuer this JWT was issued by.The given issuer can be any arbitrary string without any ":" characters, if the string does contain a ":" character then it must be a valid URI.
- Parameters:
issuer
- The JWT's issuer.
-
setIssuer
public void setIssuer(URI issuer)
Sets the issuer this JWT was issued by.- Parameters:
issuer
- The JWT's issuer.
-
getIssuer
public String getIssuer()
Gets the issuer this JWT was issued by.- Returns:
- The JWT's issuer or
null
if claim not present.
-
setSubject
public void setSubject(String subject)
Sets the subject this JWT is issued to.The given subject can be any arbitrary string without any ":" characters, if the string does contain a ":" character then it must be a valid URI.
- Parameters:
subject
- The JWT's principal.- See Also:
setSubject(java.net.URI)
-
setSubject
public void setSubject(URI subject)
Sets the subject this JWT is issued to.- Parameters:
subject
- The JWT's principal.- See Also:
setSubject(String)
-
getSubject
public String getSubject()
Gets the subject this JWT is issued to.- Returns:
- The JWT's principal or
null
if claim not present.
-
addAudience
public void addAudience(String audience)
Adds an entry to the JWT's intended audience list, in the Claims Set.The given audience can be any arbitrary string without any ":" characters, if the string does contain a ":" character then it must be a valid URI.
- Parameters:
audience
- The JWT's intended audience.- See Also:
addAudience(java.net.URI)
-
addAudience
public void addAudience(URI audience)
Adds an entry to the JWT's intended audience list, in the Claims Set.- Parameters:
audience
- The JWT's intended audience.- See Also:
addAudience(String)
-
getAudience
public List<String> getAudience()
Gets the intended audience for the JWT from the Claims Set.- Returns:
- The JWT's intended audience or
null
if claim not present.
-
setIssuedAtTime
public void setIssuedAtTime(Date issuedAtTime)
Sets the time the JWT was issued at, in the Claims Set.The given date will be converted into an
IntDate
to be stored in the JWT Claims Set.- Parameters:
issuedAtTime
- The JWT's issued at time.
-
getIssuedAtTime
public Date getIssuedAtTime()
Gets the time the JWT was issued at, from the Claims Set.- Returns:
- The JWT's issued at time or
null
if claim not present.
-
setNotBeforeTime
public void setNotBeforeTime(Date notBeforeTime)
Sets the time the JWT is not allowed to be processed before, in the Claims Set.The given date will be converted into an
IntDate
to be stored in the JWT Claims Set.- Parameters:
notBeforeTime
- The JWT's not before time.
-
getNotBeforeTime
public Date getNotBeforeTime()
Gets the time the JWT is not allowed to be processed before, from the Claims Set.- Returns:
- The JWT's not before time or
null
if claim not present.
-
setExpirationTime
public void setExpirationTime(Date expirationTime)
Sets the expiration time of the JWT in the Claims Set.The given date will be converted into an
IntDate
to be stored in the JWT Claims Set.- Parameters:
expirationTime
- The JWT's expiration time.
-
getExpirationTime
public Date getExpirationTime()
Gets the expiration time of the JWT from the Claims Set.- Returns:
- The JWT's expiration time or
null
if claim not present.
-
setClaim
public void setClaim(String key, Object value)
Sets a claim with the specified name and value.If the key matches one of the reserved claim names, then the relevant
set
method is called to set that claim with the specified name and value.- Parameters:
key
- The claim name.value
- The claim value.
-
setClaims
public void setClaims(Map<String,Object> claims)
Sets claims using the values contained in the specified map.- Parameters:
claims
- The Map to use to set the claims.
-
getClaim
public Object getClaim(String key)
Gets a claim value for the specified key.If the key matches one of the reserved claim names, then the relevant
get
method is called to get that claim value.- Parameters:
key
- The claim name.- Returns:
- The value stored against the claim name.
-
getClaim
public <T> T getClaim(String key, Class<T> clazz)
Gets a claim value for the specified claim name and then casts it to the specified type.- Type Parameters:
T
- The required type for the claim value.- Parameters:
key
- The claim name.clazz
- The class of the required type.- Returns:
- The value stored against the claim name.
- See Also:
getClaim(String)
-
build
public String build()
Builds the JWT's Claims Set into aString
representation of a JSON object.- Specified by:
build
in interfacePayload
- Returns:
- A JSON string.
- See Also:
- JSON Web Token Specification, JSON Web Signature Specification, JSON Web Encryption Specification
-
copy
public JwtClaimsSet copy()
Description copied from interface:Payload
Create a copy of the current payload.
-
-