Class JwtClaimsSet
- All Implemented Interfaces:
Payload
Provides methods to set claims for all the reserved claim names as well as custom claims.
- Since:
- 2.0.0
-
Constructor Summary
ConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionvoid
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.build()
Builds the JWT's Claims Set into aString
representation of a JSON object.copy()
Create a copy of the current payload.Gets the intended audience for the JWT from the Claims Set.Gets a claim value for the specified key.<T> T
Gets a claim value for the specified claim name and then casts it to the specified type.Gets the expiration time of the JWT from the Claims Set.Gets the time the JWT was issued at, from the Claims Set.Gets the issuer this JWT was issued by.getJwtId()
Gets the unique ID of the JWT.Gets the time the JWT is not allowed to be processed before, from the Claims Set.Gets the subject this JWT is issued to.getType()
Gets the type of the contents of the Claims Set.void
Sets a claim with the specified name and value.void
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
Sets the issuer this JWT was issued by.void
Sets the issuer this JWT was issued by.void
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
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
-
Constructor Details
-
JwtClaimsSet
public JwtClaimsSet()Constructs a new, empty JwtClaimsSet. -
JwtClaimsSet
Constructs a new JwtClaimsSet, with its claims set to the contents of the given Map.- Parameters:
claims
- A Map containing the claims to be set in the Claims Set.
-
-
Method Details
-
setType
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
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
Sets the unique ID of the JWT.- Parameters:
jwtId
- The JWT's ID.
-
getJwtId
Gets the unique ID of the JWT.- Returns:
- The JWT's ID or
null
if claim not present.
-
setIssuer
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
Sets the issuer this JWT was issued by.- Parameters:
issuer
- The JWT's issuer.
-
getIssuer
Gets the issuer this JWT was issued by.- Returns:
- The JWT's issuer or
null
if claim not present.
-
setSubject
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
Sets the subject this JWT is issued to.- Parameters:
subject
- The JWT's principal.- See Also:
-
getSubject
Gets the subject this JWT is issued to.- Returns:
- The JWT's principal or
null
if claim not present.
-
addAudience
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
Adds an entry to the JWT's intended audience list, in the Claims Set.- Parameters:
audience
- The JWT's intended audience.- See Also:
-
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
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
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
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
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
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
Gets the expiration time of the JWT from the Claims Set.- Returns:
- The JWT's expiration time or
null
if claim not present.
-
setClaim
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
Sets claims using the values contained in the specified map.- Parameters:
claims
- The Map to use to set the claims.
-
getClaim
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
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:
-
build
Builds the JWT's Claims Set into aString
representation of a JSON object. -
copy
Description copied from interface:Payload
Create a copy of the current payload.
-