@Immutable public final class VerifiedJwt extends Object
A new instance of this class is returned as the result of a sucessfully verification of a MACed or signed compact JWT.
It gives read-only access all payload claims and a subset of the headers. It does not contain any headers that depend on the key, such as "alg" or "kid". These headers are checked when the signature is verified and should not be read by the user. This ensures that the key can be changed without any changes to the user code.
| Modifier and Type | Method and Description |
|---|---|
Set<String> |
customClaimNames()
Returns all non-registered claim names.
|
List<String> |
getAudiences()
Returns the
aud claim identifying the principals that are the audience of the JWT. |
Boolean |
getBooleanClaim(String name)
Returns the non-registered claim of name
name and type Boolean. |
Instant |
getExpiration()
Returns the expiration time claim
exp that identifies the instant on or after which the
token MUST NOT be accepted for processing. |
Instant |
getIssuedAt()
Returns the issued at time claim
iat that identifies the instant at which the JWT was
issued. |
String |
getIssuer()
Returns the
iss claim that identifies the principal that issued the JWT. |
String |
getJsonArrayClaim(String name)
Returns the non-registered claim of name
name and type JSON Array encoded in a string. |
String |
getJsonObjectClaim(String name)
Returns the non-registered claim of name
name and type JSON Object encoded in a string. |
String |
getJwtId()
Returns the
jti claim that provides a unique identifier for the JWT. |
Instant |
getNotBefore()
Returns the not before claim
nbf that identifies the instant before which the token
MUST NOT be accepted for processing. |
Double |
getNumberClaim(String name)
Returns the non-registered claim of name
name and type Number. |
String |
getStringClaim(String name)
Returns the non-registered claim of name
name and type String. |
String |
getSubject()
Returns the
sub claim identifying the principal that is the subject of the JWT. |
String |
getTypeHeader()
Returns the
typ header value. |
boolean |
hasAudiences()
Returns true iff the
aud claim is present. |
boolean |
hasBooleanClaim(String name)
Returns true iff a non-registered claim of name
name and type boolean is present. |
boolean |
hasExpiration()
Returns true iff the
exp claim is present. |
boolean |
hasIssuedAt()
Returns true iff the
iat claim is present. |
boolean |
hasIssuer()
Returns true iff the
iss claim is present. |
boolean |
hasJsonArrayClaim(String name)
Returns true iff a non-registered claim of name
name and type JsonArray is present. |
boolean |
hasJsonObjectClaim(String name)
Returns true iff a non-registered claim of name
name and type JsonObject is present. |
boolean |
hasJwtId()
Returns true iff the
jti claim is present. |
boolean |
hasNotBefore()
Returns true iff the
nbf claim is present. |
boolean |
hasNumberClaim(String name)
Returns true iff a non-registered claim of name
name and type number is present. |
boolean |
hasStringClaim(String name)
Returns true iff a non-registered claim of name
name and type string is present. |
boolean |
hasSubject()
Returns true iff the
sub claim is present. |
boolean |
hasTypeHeader()
Returns true iff the
typ header is present. |
boolean |
isNullClaim(String name)
Returns true iff there is a non-registered claim of name
name and type NULL. |
String |
toString()
Returns a brief description of a VerifiedJwt object.
|
public String getTypeHeader() throws JwtInvalidException
typ header value. Throws a JwtInvalidException if header is not present.JwtInvalidExceptionpublic boolean hasTypeHeader()
typ header is present.public String getIssuer() throws JwtInvalidException
iss claim that identifies the principal that issued the JWT. Throws a
JwtInvalidException if no such claim is present.JwtInvalidExceptionpublic boolean hasIssuer()
iss claim is present.public String getSubject() throws JwtInvalidException
sub claim identifying the principal that is the subject of the JWT. Throws
a JwtInvalidException if no such claim is present.JwtInvalidExceptionpublic boolean hasSubject()
sub claim is present.public List<String> getAudiences() throws JwtInvalidException
aud claim identifying the principals that are the audience of the JWT.
Throws a JwtInvalidException if no such claim is present.JwtInvalidExceptionpublic boolean hasAudiences()
aud claim is present.public String getJwtId() throws JwtInvalidException
jti claim that provides a unique identifier for the JWT. Throws a
JwtInvalidException if no such claim is present.JwtInvalidExceptionpublic boolean hasJwtId()
jti claim is present.public Instant getExpiration() throws JwtInvalidException
exp that identifies the instant on or after which the
token MUST NOT be accepted for processing. Throws a JwtInvalidException if no such claim is
present.
This API requires Instant which is unavailable on Android until API level
26. To use it on older Android devices, enable API desugaring as shown in
https://developer.android.com/studio/write/java8-support#library-desugaring.
JwtInvalidExceptionpublic boolean hasExpiration()
exp claim is present.public Instant getNotBefore() throws JwtInvalidException
nbf that identifies the instant before which the token
MUST NOT be accepted for processing. Throws a JwtInvalidException if no such claim is
present.
This API requires Instant which is unavailable on Android until API level
26. To use it on older Android devices, enable API desugaring as shown in
https://developer.android.com/studio/write/java8-support#library-desugaring.
JwtInvalidExceptionpublic boolean hasNotBefore()
nbf claim is present.public Instant getIssuedAt() throws JwtInvalidException
iat that identifies the instant at which the JWT was
issued. Throws a JwtInvalidException if no such claim is present.
This API requires Instant which is unavailable on Android until API level
26. To use it on older Android devices, enable API desugaring as shown in
https://developer.android.com/studio/write/java8-support#library-desugaring.
JwtInvalidExceptionpublic boolean hasIssuedAt()
iat claim is present.public Boolean getBooleanClaim(String name) throws JwtInvalidException
name and type Boolean. Throws a
JwtInvalidException if no such claim is present or the claim has another type.JwtInvalidExceptionpublic Double getNumberClaim(String name) throws JwtInvalidException
name and type Number. Throws a
JwtInvalidException if no such claim is present or the claim has another type.JwtInvalidExceptionpublic String getStringClaim(String name) throws JwtInvalidException
name and type String. Throws a
JwtInvalidException if no such claim is present or the claim has another type.JwtInvalidExceptionpublic boolean isNullClaim(String name)
name and type NULL.public String getJsonObjectClaim(String name) throws JwtInvalidException
name and type JSON Object encoded in a string.
Throws a JwtInvalidException if no such claim is present or the claim has another type.JwtInvalidExceptionpublic String getJsonArrayClaim(String name) throws JwtInvalidException
name and type JSON Array encoded in a string.
Throws a JwtInvalidException if no such claim is present or the claim has another type.JwtInvalidExceptionpublic boolean hasBooleanClaim(String name)
name and type boolean is present.public boolean hasNumberClaim(String name)
name and type number is present.public boolean hasStringClaim(String name)
name and type string is present.public boolean hasJsonObjectClaim(String name)
name and type JsonObject is present.public boolean hasJsonArrayClaim(String name)
name and type JsonArray is present.