Class JwtClaimsSet.Builder
java.lang.Object
com.revetsec.jose.JwtClaimsSet.Builder
- Enclosing class:
JwtClaimsSet
Builds an outbound claims set. Registered setters replace values, and
null clears them. Custom claim
methods add one name per call and reject repeated or registered names, even when their value is JSON null.
All content checks run in the setters. No token-profile or time-ordering policy is applied by build().- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionReplaces the audiences (aud), serialized as an array even when there is one audience.build()Returns an immutable snapshot of this builder's claims, without signing or applying a token profile.Adds a custom claim.Adds a custom boolean claim.Adds a custom integral number claim.Adds a custom string claim.claim(@NonNull String name, @NonNull BigDecimal value) Adds a custom number claim held exactly as a JSON number.Adds a custom claim whose value is JSONnull.Sets the expiration time (exp) as a NumericDate, preserving nanoseconds.Sets the issue time (iat) as a NumericDate, preserving nanoseconds.Sets the issuer (iss).Sets the JWT ID (jti).Sets the time before which the token is not valid (nbf) as a NumericDate, preserving nanoseconds.Sets the subject (sub).toString()Describes this builder without any claim.
-
Method Details
-
issuer
Sets the issuer (iss).- Parameters:
issuer- the issuer, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the string contains an unpaired surrogate- Since:
- 1.0.0
-
subject
Sets the subject (sub).- Parameters:
subject- the subject, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the string contains an unpaired surrogate- Since:
- 1.0.0
-
audiences
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder audiences(@Nullable List<@NonNull String> audiences) Replaces the audiences (aud), serialized as an array even when there is one audience.- Parameters:
audiences- a non-empty list, copied before assignment;nullclears it- Returns:
- this builder
- Throws:
NullPointerException- if an element isnullIllegalArgumentException- if the list is empty or an audience contains an unpaired surrogate- Since:
- 1.0.0
-
expiresAt
Sets the expiration time (exp) as a NumericDate, preserving nanoseconds.- Parameters:
expiresAt- the instant, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the instant is outside years -9999 through 9999- Since:
- 1.0.0
-
issuedAt
Sets the issue time (iat) as a NumericDate, preserving nanoseconds.- Parameters:
issuedAt- the instant, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the instant is outside years -9999 through 9999- Since:
- 1.0.0
-
notBefore
Sets the time before which the token is not valid (nbf) as a NumericDate, preserving nanoseconds.- Parameters:
notBefore- the instant, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the instant is outside years -9999 through 9999- Since:
- 1.0.0
-
jwtId
Sets the JWT ID (jti).- Parameters:
jwtId- the JWT ID, ornullto clear it- Returns:
- this builder
- Throws:
IllegalArgumentException- if the string contains an unpaired surrogate- Since:
- 1.0.0
-
claim
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder claim(@NonNull String name, @NonNull JsonValue value) Adds a custom claim. Use the typed setters for registered claim names.- Parameters:
name- the claim name, compared exactlyvalue- the JSON value, includingJsonNullfor JSONnull- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- if the name is registered, already present or contains an unpaired surrogate, or the claims object would nest more than 64 deep- Since:
- 1.0.0
-
claim
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder claim(@NonNull String name, @NonNull String value) Adds a custom string claim.- Parameters:
name- the claim name, compared exactlyvalue- the string- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- if the name is registered or already present, or the name or value contains an unpaired surrogate- Since:
- 1.0.0
-
claim
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder claim(@NonNull String name, @NonNull Long value) Adds a custom integral number claim.- Parameters:
name- the claim name, compared exactlyvalue- the number- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- if the name is registered, already present or contains an unpaired surrogate- Since:
- 1.0.0
-
claim
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder claim(@NonNull String name, @NonNull BigDecimal value) Adds a custom number claim held exactly as a JSON number.- Parameters:
name- the claim name, compared exactlyvalue- the number- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- if the name is registered, already present or contains an unpaired surrogate, or the value exceeds the limits ofJsonNumber.fromValue(BigDecimal)- Since:
- 1.0.0
-
claim
@CanIgnoreReturnValue public @NonNull JwtClaimsSet.Builder claim(@NonNull String name, @NonNull Boolean value) Adds a custom boolean claim.- Parameters:
name- the claim name, compared exactlyvalue- the boolean- Returns:
- this builder
- Throws:
NullPointerException- if an argument isnullIllegalArgumentException- if the name is registered, already present or contains an unpaired surrogate- Since:
- 1.0.0
-
claimNull
Adds a custom claim whose value is JSONnull.- Parameters:
name- the claim name, compared exactly- Returns:
- this builder
- Throws:
NullPointerException- if the name isnullIllegalArgumentException- if the name is registered, already present or contains an unpaired surrogate- Since:
- 1.0.0
-
build
Returns an immutable snapshot of this builder's claims, without signing or applying a token profile.- Returns:
- the outbound claims set
- Since:
- 1.0.0
-
toString
-