Package com.auth0.jwt
Class JWTVerifier.BaseVerification
java.lang.Object
com.auth0.jwt.JWTVerifier.BaseVerification
- All Implemented Interfaces:
Verification
- Enclosing class:
JWTVerifier
The Verification class holds the Claims required by a JWT to be valid.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacceptExpiresAt
(long leeway) Set a specific leeway window in seconds in which the Expires At ("exp") Claim will still be valid.acceptIssuedAt
(long leeway) Set a specific leeway window in seconds in which the Issued At ("iat") Claim will still be valid.acceptLeeway
(long leeway) Define the default window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid.acceptNotBefore
(long leeway) Set a specific leeway window in seconds in which the Not Before ("nbf") Claim will still be valid.private void
private void
assertNonNull
(String name) private void
assertPositive
(long leeway) build()
Creates a new and reusable instance of the JWTVerifier with the configuration already provided.Creates a new and reusable instance of the JWTVerifier with the configuration already provided.Skip the Issued At ("iat") date verification.private void
requireClaim
(String name, Object value) withArrayClaim
(String name, Integer... items) Require a specific Array Claim to contain at least the given items.withArrayClaim
(String name, String... items) Require a specific Array Claim to contain at least the given items.withAudience
(String... audience) Require a specific Audience ("aud") claim.Require a specific Claim value.Require a specific Claim value.Require a specific Claim value.Require a specific Claim value.Require a specific Claim value.Require a specific Claim value.withIssuer
(String... issuer) Require a specific Issuer ("iss") claim.Require a specific JWT Id ("jti") claim.withSubject
(String subject) Require a specific Subject ("sub") claim.
-
Field Details
-
algorithm
-
claims
-
defaultLeeway
private long defaultLeeway -
ignoreIssuedAt
private boolean ignoreIssuedAt
-
-
Constructor Details
-
BaseVerification
BaseVerification(Algorithm algorithm) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
-
Method Details
-
withIssuer
Require a specific Issuer ("iss") claim.- Specified by:
withIssuer
in interfaceVerification
- Parameters:
issuer
- the required Issuer value. If multiple values are given, the claim must at least match one of them- Returns:
- this same Verification instance.
-
withSubject
Require a specific Subject ("sub") claim.- Specified by:
withSubject
in interfaceVerification
- Parameters:
subject
- the required Subject value- Returns:
- this same Verification instance.
-
withAudience
Require a specific Audience ("aud") claim.- Specified by:
withAudience
in interfaceVerification
- Parameters:
audience
- the required Audience value- Returns:
- this same Verification instance.
-
acceptLeeway
Define the default window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid. Setting a specific leeway value on a given Claim will override this value for that Claim.- Specified by:
acceptLeeway
in interfaceVerification
- Parameters:
leeway
- the window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if leeway is negative.
-
acceptExpiresAt
Set a specific leeway window in seconds in which the Expires At ("exp") Claim will still be valid. Expiration Date is always verified when the value is present. This method overrides the value set with acceptLeeway- Specified by:
acceptExpiresAt
in interfaceVerification
- Parameters:
leeway
- the window in seconds in which the Expires At Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if leeway is negative.
-
acceptNotBefore
Set a specific leeway window in seconds in which the Not Before ("nbf") Claim will still be valid. Not Before Date is always verified when the value is present. This method overrides the value set with acceptLeeway- Specified by:
acceptNotBefore
in interfaceVerification
- Parameters:
leeway
- the window in seconds in which the Not Before Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if leeway is negative.
-
acceptIssuedAt
Set a specific leeway window in seconds in which the Issued At ("iat") Claim will still be valid. Issued At Date is always verified when the value is present. This method overrides the value set with acceptLeeway- Specified by:
acceptIssuedAt
in interfaceVerification
- Parameters:
leeway
- the window in seconds in which the Issued At Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if leeway is negative.
-
ignoreIssuedAt
Skip the Issued At ("iat") date verification. By default, the verification is performed.- Specified by:
ignoreIssuedAt
in interfaceVerification
-
withJWTId
Require a specific JWT Id ("jti") claim.- Specified by:
withJWTId
in interfaceVerification
- Parameters:
jwtId
- the required Id value- Returns:
- this same Verification instance.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withClaim
Require a specific Claim value.- Specified by:
withClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.value
- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withArrayClaim
Require a specific Array Claim to contain at least the given items.- Specified by:
withArrayClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.items
- the items the Claim must contain.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
withArrayClaim
Require a specific Array Claim to contain at least the given items.- Specified by:
withArrayClaim
in interfaceVerification
- Parameters:
name
- the Claim's name.items
- the items the Claim must contain.- Returns:
- this same Verification instance.
- Throws:
IllegalArgumentException
- if the name is null.
-
build
Creates a new and reusable instance of the JWTVerifier with the configuration already provided.- Specified by:
build
in interfaceVerification
- Returns:
- a new JWTVerifier instance.
-
build
Creates a new and reusable instance of the JWTVerifier with the configuration already provided. ONLY FOR TEST PURPOSES.- Parameters:
clock
- the instance that will handle the current time.- Returns:
- a new JWTVerifier instance with a custom Clock.
-
assertPositive
private void assertPositive(long leeway) -
assertNonNull
-
addLeewayToDateClaims
private void addLeewayToDateClaims() -
requireClaim
-