Class VerifiedJwt
- java.lang.Object
-
- com.google.crypto.tink.jwt.VerifiedJwt
-
@Immutable public final class VerifiedJwt extends java.lang.ObjectA decoded and verified JSON Web Token (JWT).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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<java.lang.String>customClaimNames()Returns all non-registered claim names.java.util.List<java.lang.String>getAudiences()Returns theaudclaim identifying the principals that are the audience of the JWT.java.lang.BooleangetBooleanClaim(java.lang.String name)Returns the non-registered claim of namenameand type Boolean.java.time.InstantgetExpiration()Returns the expiration time claimexpthat identifies the instant on or after which the token MUST NOT be accepted for processing.java.time.InstantgetIssuedAt()Returns the issued at time claimiatthat identifies the instant at which the JWT was issued.java.lang.StringgetIssuer()Returns theissclaim that identifies the principal that issued the JWT.java.lang.StringgetJsonArrayClaim(java.lang.String name)Returns the non-registered claim of namenameand type JSON Array encoded in a string.java.lang.StringgetJsonObjectClaim(java.lang.String name)Returns the non-registered claim of namenameand type JSON Object encoded in a string.java.lang.StringgetJwtId()Returns thejticlaim that provides a unique identifier for the JWT.java.time.InstantgetNotBefore()Returns the not before claimnbfthat identifies the instant before which the token MUST NOT be accepted for processing.java.lang.DoublegetNumberClaim(java.lang.String name)Returns the non-registered claim of namenameand type Number.java.lang.StringgetStringClaim(java.lang.String name)Returns the non-registered claim of namenameand type String.java.lang.StringgetSubject()Returns thesubclaim identifying the principal that is the subject of the JWT.java.lang.StringgetTypeHeader()Returns thetypheader value.booleanhasAudiences()Returns true iff theaudclaim is present.booleanhasBooleanClaim(java.lang.String name)Returns true iff a non-registered claim of namenameand type boolean is present.booleanhasExpiration()Returns true iff theexpclaim is present.booleanhasIssuedAt()Returns true iff theiatclaim is present.booleanhasIssuer()Returns true iff theissclaim is present.booleanhasJsonArrayClaim(java.lang.String name)Returns true iff a non-registered claim of namenameand type JsonArray is present.booleanhasJsonObjectClaim(java.lang.String name)Returns true iff a non-registered claim of namenameand type JsonObject is present.booleanhasJwtId()Returns true iff thejticlaim is present.booleanhasNotBefore()Returns true iff thenbfclaim is present.booleanhasNumberClaim(java.lang.String name)Returns true iff a non-registered claim of namenameand type number is present.booleanhasStringClaim(java.lang.String name)Returns true iff a non-registered claim of namenameand type string is present.booleanhasSubject()Returns true iff thesubclaim is present.booleanhasTypeHeader()Returns true iff thetypheader is present.booleanisNullClaim(java.lang.String name)Returns true iff there is a non-registered claim of namenameand type NULL.java.lang.StringtoString()Returns a brief description of a VerifiedJwt object.
-
-
-
Method Detail
-
getTypeHeader
public java.lang.String getTypeHeader() throws JwtInvalidExceptionReturns thetypheader value. Throws a JwtInvalidException if header is not present.- Throws:
JwtInvalidException
-
hasTypeHeader
public boolean hasTypeHeader()
Returns true iff thetypheader is present.
-
getIssuer
public java.lang.String getIssuer() throws JwtInvalidExceptionReturns theissclaim that identifies the principal that issued the JWT. Throws a JwtInvalidException if no such claim is present.- Throws:
JwtInvalidException
-
hasIssuer
public boolean hasIssuer()
Returns true iff theissclaim is present.
-
getSubject
public java.lang.String getSubject() throws JwtInvalidExceptionReturns thesubclaim identifying the principal that is the subject of the JWT. Throws a JwtInvalidException if no such claim is present.- Throws:
JwtInvalidException
-
hasSubject
public boolean hasSubject()
Returns true iff thesubclaim is present.
-
getAudiences
public java.util.List<java.lang.String> getAudiences() throws JwtInvalidExceptionReturns theaudclaim identifying the principals that are the audience of the JWT. Throws a JwtInvalidException if no such claim is present.- Throws:
JwtInvalidException
-
hasAudiences
public boolean hasAudiences()
Returns true iff theaudclaim is present.
-
getJwtId
public java.lang.String getJwtId() throws JwtInvalidExceptionReturns thejticlaim that provides a unique identifier for the JWT. Throws a JwtInvalidException if no such claim is present.- Throws:
JwtInvalidException
-
hasJwtId
public boolean hasJwtId()
Returns true iff thejticlaim is present.
-
getExpiration
public java.time.Instant getExpiration() throws JwtInvalidExceptionReturns the expiration time claimexpthat 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
Instantwhich 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.- Throws:
JwtInvalidException
-
hasExpiration
public boolean hasExpiration()
Returns true iff theexpclaim is present.
-
getNotBefore
public java.time.Instant getNotBefore() throws JwtInvalidExceptionReturns the not before claimnbfthat 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
Instantwhich 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.- Throws:
JwtInvalidException
-
hasNotBefore
public boolean hasNotBefore()
Returns true iff thenbfclaim is present.
-
getIssuedAt
public java.time.Instant getIssuedAt() throws JwtInvalidExceptionReturns the issued at time claimiatthat identifies the instant at which the JWT was issued. Throws a JwtInvalidException if no such claim is present.This API requires
Instantwhich 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.- Throws:
JwtInvalidException
-
hasIssuedAt
public boolean hasIssuedAt()
Returns true iff theiatclaim is present.
-
getBooleanClaim
public java.lang.Boolean getBooleanClaim(java.lang.String name) throws JwtInvalidExceptionReturns the non-registered claim of namenameand type Boolean. Throws a JwtInvalidException if no such claim is present or the claim has another type.- Throws:
JwtInvalidException
-
getNumberClaim
public java.lang.Double getNumberClaim(java.lang.String name) throws JwtInvalidExceptionReturns the non-registered claim of namenameand type Number. Throws a JwtInvalidException if no such claim is present or the claim has another type.- Throws:
JwtInvalidException
-
getStringClaim
public java.lang.String getStringClaim(java.lang.String name) throws JwtInvalidExceptionReturns the non-registered claim of namenameand type String. Throws a JwtInvalidException if no such claim is present or the claim has another type.- Throws:
JwtInvalidException
-
isNullClaim
public boolean isNullClaim(java.lang.String name)
Returns true iff there is a non-registered claim of namenameand type NULL.
-
getJsonObjectClaim
public java.lang.String getJsonObjectClaim(java.lang.String name) throws JwtInvalidExceptionReturns the non-registered claim of namenameand type JSON Object encoded in a string. Throws a JwtInvalidException if no such claim is present or the claim has another type.- Throws:
JwtInvalidException
-
getJsonArrayClaim
public java.lang.String getJsonArrayClaim(java.lang.String name) throws JwtInvalidExceptionReturns the non-registered claim of namenameand type JSON Array encoded in a string. Throws a JwtInvalidException if no such claim is present or the claim has another type.- Throws:
JwtInvalidException
-
hasBooleanClaim
public boolean hasBooleanClaim(java.lang.String name)
Returns true iff a non-registered claim of namenameand type boolean is present.
-
hasNumberClaim
public boolean hasNumberClaim(java.lang.String name)
Returns true iff a non-registered claim of namenameand type number is present.
-
hasStringClaim
public boolean hasStringClaim(java.lang.String name)
Returns true iff a non-registered claim of namenameand type string is present.
-
hasJsonObjectClaim
public boolean hasJsonObjectClaim(java.lang.String name)
Returns true iff a non-registered claim of namenameand type JsonObject is present.
-
hasJsonArrayClaim
public boolean hasJsonArrayClaim(java.lang.String name)
Returns true iff a non-registered claim of namenameand type JsonArray is present.
-
customClaimNames
public java.util.Set<java.lang.String> customClaimNames()
Returns all non-registered claim names.
-
toString
public java.lang.String toString()
Returns a brief description of a VerifiedJwt object. The exact details of the representation are unspecified and subject to change.- Overrides:
toStringin classjava.lang.Object
-
-