public interface Claims extends Map<String,Object>, Identifiable
This is an immutable JSON map with convenient type-safe getters for JWT standard claim names.
Additionally, this interface also extends Map<String, Object>, so you can use standard
Map accessor/iterator methods as desired, for example:
claims.get("someKey");
However, because Claims instances are immutable, calling any of the map mutation methods
(such as Map.put, etc) will result in a runtime exception. The
Map interface is implemented specifically for the convenience of working with existing Map-based utilities
and APIs.
| Modifier and Type | Field and Description |
|---|---|
static String |
AUDIENCE
JWT
Audience claims parameter name: "aud" |
static String |
EXPIRATION
JWT
Expiration claims parameter name: "exp" |
static String |
ID
JWT
JWT ID claims parameter name: "jti" |
static String |
ISSUED_AT
JWT
Issued At claims parameter name: "iat" |
static String |
ISSUER
JWT
Issuer claims parameter name: "iss" |
static String |
NOT_BEFORE
JWT
Not Before claims parameter name: "nbf" |
static String |
SUBJECT
JWT
Subject claims parameter name: "sub" |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
get(String claimName,
Class<T> requiredType)
Returns the JWTs claim (
claimName) value as a requiredType instance, or null if not
present. |
Set<String> |
getAudience()
Returns the JWT
aud (audience) value or null if not present. |
Date |
getExpiration()
Returns the JWT
exp (expiration) timestamp or null if not present. |
String |
getId()
Returns the JWTs
jti (JWT ID) value or null if not present. |
Date |
getIssuedAt()
Returns the JWT
iat (issued at) timestamp or null if not present. |
String |
getIssuer()
Returns the JWT
iss (issuer) value or null if not present. |
Date |
getNotBefore()
Returns the JWT
nbf (not before) timestamp or null if not present. |
String |
getSubject()
Returns the JWT
sub (subject) value or null if not present. |
static final String ISSUER
Issuer claims parameter name: "iss"static final String SUBJECT
Subject claims parameter name: "sub"static final String AUDIENCE
Audience claims parameter name: "aud"static final String EXPIRATION
Expiration claims parameter name: "exp"static final String NOT_BEFORE
Not Before claims parameter name: "nbf"static final String ISSUED_AT
Issued At claims parameter name: "iat"static final String ID
JWT ID claims parameter name: "jti"String getIssuer()
iss (issuer) value or null if not present.iss value or null if not present.String getSubject()
sub (subject) value or null if not present.sub value or null if not present.Set<String> getAudience()
aud (audience) value or null if not present.aud value or null if not present.Date getExpiration()
exp (expiration) timestamp or null if not present.
A JWT obtained after this timestamp should not be used.
exp value or null if not present.Date getNotBefore()
nbf (not before) timestamp or null if not present.
A JWT obtained before this timestamp should not be used.
nbf value or null if not present.Date getIssuedAt()
iat (issued at) timestamp or null if not present.
If present, this value is the timestamp when the JWT was created.
iat value or null if not present.String getId()
jti (JWT ID) value or null if not present.
This value is a CaSe-SenSiTiVe unique identifier for the JWT. If available, this value is expected to be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object. The ID can be used to prevent the JWT from being replayed.
getId in interface Identifiablejti value or null if not present.<T> T get(String claimName, Class<T> requiredType)
claimName) value as a requiredType instance, or null if not
present.
JJWT only converts simple String, Date, Long, Integer, Short and Byte types automatically. Anything more
complex is expected to be already converted to your desired type by the JSON parser. You may specify a custom
JSON processor using the JwtParserBuilder's
json(Deserializer) method. See the JJWT
documentation on custom JSON processors for more
information. If using Jackson, you can specify custom claim POJO types as described in
custom claim types.
T - the type of the value expected to be returnedclaimName - name of claimrequiredType - the type of the value expected to be returnedclaimName value or null if not present.RequiredTypeException - throw if the claim value is not null and not of type requiredTypeCopyright © 2014–2023 jsonwebtoken.io. All rights reserved.