Class JWT
From RFC 7519 Section 1. Introduction:
The suggested pronunciation of JWT is the same as the English word "jot".
The JWT is not Thread-Safe and should not be re-used.- Author:
- Daniel DeGroff
-
Field Summary
FieldsModifier and TypeFieldDescriptionRegistered Claimaudas defined by RFC 7519 Section 4.1.3.java.time.ZonedDateTimeRegistered Claimexpas defined by RFC 7519 Section 4.1.4.The decoded JWT header.java.time.ZonedDateTimeRegistered Claimiatas defined by RFC 7519 Section 4.1.6.Registered Claimissas defined by RFC 7519 Section 4.1.1.java.time.ZonedDateTimeRegistered Claimnbfas defined by RFC 7519 Section 4.1.5.This Map will contain all the claims that aren't specifically defined in the specification.Registered Claimsubas defined by RFC 7519 Section 4.1.2.Registered Claimjtias defined by RFC 7519 Section 4.1.7. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a claim to this JWT.booleangetBigDecimal(String key) getBigInteger(String key) getBoolean(String key) static JWTDecoderReturn an instance of the JWT Decoder.static JWTEncoderReturn an instance of the JWT encoder.getHeaderClaim(String name) getInteger(String key) static JWTDecodergetTimeMachineDecoder(java.time.ZonedDateTime now) Return a JWT Decoder that allows you to go back or of forward in time.inthashCode()booleanReturn true if this JWT is expired.booleanisExpired(java.time.ZonedDateTime now) Return true if this JWT is expired.booleanReturn true if this JWT is un-available for processing.booleanisUnavailableForProcessing(java.time.ZonedDateTime now) Return true if this JWT is un-available for processing.setAudience(Object audience) setExpiration(java.time.ZonedDateTime expiration) setIssuedAt(java.time.ZonedDateTime issuedAt) setNotBefore(java.time.ZonedDateTime notBefore) setSubject(String subject) setUniqueId(String uniqueId) toString()
-
Field Details
-
header
The decoded JWT header. This is not considered part of the JWT payload, but is available here for convenience. -
audience
Registered Claimaudas defined by RFC 7519 Section 4.1.3. Use of this claim is OPTIONAL.The audience claim identifies the recipients that the JWT is intended for. This may be an array of strings or a single string, in either case if the string value contains a
:it must be a URI. -
expiration
public java.time.ZonedDateTime expirationRegistered Claimexpas defined by RFC 7519 Section 4.1.4. Use of this claim is OPTIONAL.The expiration time claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The expiration time is expected to provided in UNIX time, or the number of seconds since Epoch.
-
issuedAt
public java.time.ZonedDateTime issuedAtRegistered Claimiatas defined by RFC 7519 Section 4.1.6. Use of this claim is OPTIONAL.The issued at claim identifies the time at which the JWT was issued. The issued at time is expected to provided in UNIX time, or the number of seconds since Epoch.
-
issuer
Registered Claimissas defined by RFC 7519 Section 4.1.1. Use of this claim is OPTIONAL.The issuer claim identifies the principal that issued the JWT. If the value contains a
:it must be a URI. -
notBefore
public java.time.ZonedDateTime notBeforeRegistered Claimnbfas defined by RFC 7519 Section 4.1.5. Use of this claim is OPTIONAL.This claim identifies the time before which the JWT MUST NOT be accepted for processing. The not before value is expected to be provided in UNIX time, or the number of seconds since Epoch.
-
otherClaims
This Map will contain all the claims that aren't specifically defined in the specification. These still might be IANA registered claims, but are not known JWT specification claims. -
subject
Registered Claimsubas defined by RFC 7519 Section 4.1.2. Use of this claim is OPTIONAL.The subject claim identifies the principal that is the subject of the JWT. If the value contains a
:it must be a URI. -
uniqueId
Registered Claimjtias defined by RFC 7519 Section 4.1.7. Use of this claim is OPTIONAL.The JWT unique ID claim provides a unique identifier for the JWT.
-
-
Constructor Details
-
JWT
public JWT()
-
-
Method Details
-
getDecoder
Return an instance of the JWT Decoder.- Returns:
- a JWT decoder.
-
getTimeMachineDecoder
Return a JWT Decoder that allows you to go back or of forward in time. Use this at your own risk.Generally speaking, there should not be a use for this in production code since 'now' should always be 'now', but it may come in handy in a test.
- Parameters:
now- a 'now' that can be in the past, present or future.- Returns:
- a JWT decoder with time machine capability.
-
getEncoder
Return an instance of the JWT encoder.- Returns:
- a JWT encoder.
-
getHeaderClaim
-
addClaim
Add a claim to this JWT. This claim can be public or private, it is up to the caller to properly name the claim as to avoid collision.- Parameters:
name- The name of the JWT claim.value- The value of the JWT claim. This value is an object and is expected to properly serialize.- Returns:
- this.
-
equals
-
getAllClaims
- Returns:
- Returns all the claims as cool Java types like ZonedDateTime (where appropriate of course). This will contain the otherClaims and the known JWT claims.
-
getBigDecimal
-
getBigInteger
-
getBoolean
-
getDouble
-
getFloat
-
getInteger
-
getList
-
getLong
-
getMap
-
getNumber
-
getObject
-
getOtherClaims
-
getRawClaims
- Returns:
- Returns the original claims from the JWT without any Java data types like ZonedDateTime. This will contain the otherClaims and the known JWT claims.
-
getString
-
hashCode
public int hashCode() -
isExpired
public boolean isExpired()Return true if this JWT is expired.- Returns:
- true if expired, false if not.
-
isExpired
public boolean isExpired(java.time.ZonedDateTime now) Return true if this JWT is expired.- Parameters:
now- the 'now' you wish to use.- Returns:
- true if expired, false if not.
-
setAudience
-
setExpiration
-
setIssuedAt
-
setIssuer
-
setNotBefore
-
setSubject
-
setUniqueId
-
toString
-