public class Jwt extends Object
Representation of a JSON web token (a generic one).
| Modifier and Type | Class | Description |
|---|---|---|
static class |
Jwt.Builder |
Builder of a
Jwt. |
static class |
Jwt.ExpirationValidator |
Validator of expiration claim.
|
static class |
Jwt.FieldValidator |
Validator of a string field obtained from a JWT.
|
static class |
Jwt.IssueTimeValidator |
Validator of issue time claim.
|
static class |
Jwt.NotBeforeValidator |
Validator of not before claim.
|
| Constructor | Description |
|---|---|
Jwt(javax.json.JsonObject headerJson,
javax.json.JsonObject payloadJson) |
Create a token based on json.
|
public Jwt(javax.json.JsonObject headerJson,
javax.json.JsonObject payloadJson)
headerJson - headerspayloadJson - payloadpublic static List<Validator<Jwt>> defaultTimeValidators()
public static List<Validator<Jwt>> defaultTimeValidators(Instant now, int timeSkewAmount, ChronoUnit timeSkewUnit, boolean mandatory)
now - Time that acts as the "now" instant (this allows us to validate if a token was valid at an instant in
the pasttimeSkewAmount - time skew allowed when validating (amount - such as 5)timeSkewUnit - time skew allowed when validating (unit - such as ChronoUnit.SECONDS)mandatory - whether the field is mandatory. True for mandatory, false for optional (for all default time
validators)public static void addIssuerValidator(Collection<Validator<Jwt>> validators, String issuer, boolean mandatory)
validators - collection of validatorsissuer - issuer expected to be in the tokenmandatory - whether issuer field is mandatory in the token (true - mandatory, false - optional)public static void addAudienceValidator(Collection<Validator<Jwt>> validators, String audience, boolean mandatory)
validators - collection of validatorsaudience - audience expected to be in the tokenmandatory - whether the audience field is mandatory in the tokenpublic static Jwt.Builder builder()
public Optional<javax.json.JsonValue> getHeaderClaim(String claim)
claim - name of a claimpublic Optional<javax.json.JsonValue> getPayloadClaim(String claim)
claim - name of a claimpublic Optional<JwtUtil.Address> getAddress()
public Optional<byte[]> getAtHash()
public Optional<byte[]> getCHash()
public javax.json.JsonObject getHeaderJson()
public javax.json.JsonObject getPayloadJson()
public Errors validate(List<Validator<Jwt>> validators)
validators - Validators to validate with. Obtain them through (e.g.) defaultTimeValidators()
, addAudienceValidator(Collection, String, boolean)
, addIssuerValidator(Collection, String, boolean)public Errors validate(String issuer, String audience)
Expiration time if definedIssue time if definedNot before time if definedgetIssuer() Issuer} if definedAudience if definedissuer - validates that this JWT was issued by this issuer. Setting this to non-null value will make
issuer claim mandatoryaudience - validates that this JWT was issued for this audience. Setting this to non-null value will make
audience claim mandatoryCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.