Class JwtClaims
java.lang.Object
com.jsgalactic.axiom.security.jwt.JwtClaims
The claims of a token whose signature, expiry, issuer, audience and subject have been verified,
read through typed accessors so that no JSON library type is exposed. Passed to a
TokenCheck and to JwtAuthenticator.Builder.attributes(java.util.function.Function<com.jsgalactic.axiom.security.jwt.JwtClaims, java.util.Map<java.lang.String, java.lang.String>>).
Accessors never return a value of another type than they promise: a claim of the wrong type
throws IllegalArgumentException, which the authenticator answers like any invalid token
(401 invalid_token). An absent claim is empty. The claim values are untrusted in the
sense that the issuer chose them; apply the same care as to any input. toString() lists
the number of claims, not their values.
Immutable and thread-safe; valid after the call that received it returns.
-
Method Summary
Modifier and TypeMethodDescriptionReads a boolean claim.Returns theexpclaim, which is always present in a verified token.booleanReports whether a claim is present, with any value (including JSONnull).id()Returns thejticlaim, the token's unique identifier, for replay and revocation checks.issuer()Returns theissclaim, which is always present in a verified token.names()Lists the names of the claims present.Reads a claim that is a non-negative integer of at most 15 digits.Reads a string claim.Reads a claim that is a string or an array of strings, as a list.subject()Returns thesubclaim, which is always present in a verified token.Reads a scalar claim (string, number or boolean) as text.toString()
-
Method Details
-
names
Lists the names of the claims present.- Returns:
- unmodifiable set of claim names
-
has
Reports whether a claim is present, with any value (including JSONnull).- Parameters:
name- claim name- Returns:
- true if present
-
string
Reads a string claim.- Parameters:
name- claim name- Returns:
- the value, or empty if absent or JSON
null - Throws:
IllegalArgumentException- if the claim is not a string
-
strings
Reads a claim that is a string or an array of strings, as a list.- Parameters:
name- claim name- Returns:
- the values; empty if absent or JSON
null - Throws:
IllegalArgumentException- if the claim is neither a string nor an array of strings
-
number
Reads a claim that is a non-negative integer of at most 15 digits.- Parameters:
name- claim name- Returns:
- the value, or empty if absent or JSON
null - Throws:
IllegalArgumentException- if the claim is not such an integer
-
bool
Reads a boolean claim.- Parameters:
name- claim name- Returns:
- the value, or empty if absent or JSON
null - Throws:
IllegalArgumentException- if the claim is not a boolean
-
text
Reads a scalar claim (string, number or boolean) as text.- Parameters:
name- claim name- Returns:
- the text; empty if absent or JSON
null - Throws:
IllegalArgumentException- if the claim is an array or an object
-
id
Returns thejticlaim, the token's unique identifier, for replay and revocation checks.- Returns:
- the identifier, or empty if the token has none
- Throws:
IllegalArgumentException- if present but not a string
-
subject
Returns thesubclaim, which is always present in a verified token.- Returns:
- the subject
-
issuer
Returns theissclaim, which is always present in a verified token.- Returns:
- the issuer
-
expiresAt
Returns theexpclaim, which is always present in a verified token. A replay record forid()can be dropped after this instant plus the clock skew.- Returns:
- the expiry
-
toString
-