Package com.auth0.jwt
Class JWTVerifier.BaseVerification
- java.lang.Object
-
- com.auth0.jwt.JWTVerifier.BaseVerification
-
- All Implemented Interfaces:
Verification
- Enclosing class:
- JWTVerifier
public static class JWTVerifier.BaseVerification extends java.lang.Object implements Verification
The Verification class holds the Claims required by a JWT to be valid.
-
-
Field Summary
Fields Modifier and Type Field Description private Algorithmalgorithmprivate java.util.Map<java.lang.String,java.lang.Object>claimsprivate longdefaultLeewayprivate booleanignoreIssuedAt
-
Constructor Summary
Constructors Constructor Description BaseVerification(Algorithm algorithm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VerificationacceptExpiresAt(long leeway)Set a specific leeway window in seconds in which the Expires At ("exp") Claim will still be valid.VerificationacceptIssuedAt(long leeway)Set a specific leeway window in seconds in which the Issued At ("iat") Claim will still be valid.VerificationacceptLeeway(long leeway)Define the default window in seconds in which the Not Before, Issued At and Expires At Claims will still be valid.VerificationacceptNotBefore(long leeway)Set a specific leeway window in seconds in which the Not Before ("nbf") Claim will still be valid.private voidaddLeewayToDateClaims()private voidassertNonNull(java.lang.String name)private voidassertPositive(long leeway)JWTVerifierbuild()Creates a new and reusable instance of the JWTVerifier with the configuration already provided.JWTVerifierbuild(Clock clock)Creates a new and reusable instance of the JWTVerifier with the configuration already provided.VerificationignoreIssuedAt()Skip the Issued At ("iat") date verification.private voidrequireClaim(java.lang.String name, java.lang.Object value)VerificationwithArrayClaim(java.lang.String name, java.lang.Integer... items)Require a specific Array Claim to contain at least the given items.VerificationwithArrayClaim(java.lang.String name, java.lang.String... items)Require a specific Array Claim to contain at least the given items.VerificationwithAudience(java.lang.String... audience)Require a specific Audience ("aud") claim.VerificationwithClaim(java.lang.String name, java.lang.Boolean value)Require a specific Claim value.VerificationwithClaim(java.lang.String name, java.lang.Double value)Require a specific Claim value.VerificationwithClaim(java.lang.String name, java.lang.Integer value)Require a specific Claim value.VerificationwithClaim(java.lang.String name, java.lang.Long value)Require a specific Claim value.VerificationwithClaim(java.lang.String name, java.lang.String value)Require a specific Claim value.VerificationwithClaim(java.lang.String name, java.util.Date value)Require a specific Claim value.VerificationwithIssuer(java.lang.String... issuer)Require a specific Issuer ("iss") claim.VerificationwithJWTId(java.lang.String jwtId)Require a specific JWT Id ("jti") claim.VerificationwithSubject(java.lang.String subject)Require a specific Subject ("sub") claim.
-
-
-
Field Detail
-
algorithm
private final Algorithm algorithm
-
claims
private final java.util.Map<java.lang.String,java.lang.Object> claims
-
defaultLeeway
private long defaultLeeway
-
ignoreIssuedAt
private boolean ignoreIssuedAt
-
-
Constructor Detail
-
BaseVerification
BaseVerification(Algorithm algorithm) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
-
Method Detail
-
withIssuer
public Verification withIssuer(java.lang.String... issuer)
Require a specific Issuer ("iss") claim.- Specified by:
withIssuerin 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
public Verification withSubject(java.lang.String subject)
Require a specific Subject ("sub") claim.- Specified by:
withSubjectin interfaceVerification- Parameters:
subject- the required Subject value- Returns:
- this same Verification instance.
-
withAudience
public Verification withAudience(java.lang.String... audience)
Require a specific Audience ("aud") claim.- Specified by:
withAudiencein interfaceVerification- Parameters:
audience- the required Audience value- Returns:
- this same Verification instance.
-
acceptLeeway
public Verification acceptLeeway(long leeway) throws java.lang.IllegalArgumentException
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:
acceptLeewayin 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:
java.lang.IllegalArgumentException- if leeway is negative.
-
acceptExpiresAt
public Verification acceptExpiresAt(long leeway) throws java.lang.IllegalArgumentException
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:
acceptExpiresAtin interfaceVerification- Parameters:
leeway- the window in seconds in which the Expires At Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if leeway is negative.
-
acceptNotBefore
public Verification acceptNotBefore(long leeway) throws java.lang.IllegalArgumentException
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:
acceptNotBeforein interfaceVerification- Parameters:
leeway- the window in seconds in which the Not Before Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if leeway is negative.
-
acceptIssuedAt
public Verification acceptIssuedAt(long leeway) throws java.lang.IllegalArgumentException
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:
acceptIssuedAtin interfaceVerification- Parameters:
leeway- the window in seconds in which the Issued At Claim will still be valid.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if leeway is negative.
-
ignoreIssuedAt
public Verification ignoreIssuedAt()
Skip the Issued At ("iat") date verification. By default, the verification is performed.- Specified by:
ignoreIssuedAtin interfaceVerification
-
withJWTId
public Verification withJWTId(java.lang.String jwtId)
Require a specific JWT Id ("jti") claim.- Specified by:
withJWTIdin interfaceVerification- Parameters:
jwtId- the required Id value- Returns:
- this same Verification instance.
-
withClaim
public Verification withClaim(java.lang.String name, java.lang.Boolean value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withClaim
public Verification withClaim(java.lang.String name, java.lang.Integer value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withClaim
public Verification withClaim(java.lang.String name, java.lang.Long value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withClaim
public Verification withClaim(java.lang.String name, java.lang.Double value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withClaim
public Verification withClaim(java.lang.String name, java.lang.String value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withClaim
public Verification withClaim(java.lang.String name, java.util.Date value) throws java.lang.IllegalArgumentException
Require a specific Claim value.- Specified by:
withClaimin interfaceVerification- Parameters:
name- the Claim's name.value- the Claim's value.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withArrayClaim
public Verification withArrayClaim(java.lang.String name, java.lang.String... items) throws java.lang.IllegalArgumentException
Require a specific Array Claim to contain at least the given items.- Specified by:
withArrayClaimin interfaceVerification- Parameters:
name- the Claim's name.items- the items the Claim must contain.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
withArrayClaim
public Verification withArrayClaim(java.lang.String name, java.lang.Integer... items) throws java.lang.IllegalArgumentException
Require a specific Array Claim to contain at least the given items.- Specified by:
withArrayClaimin interfaceVerification- Parameters:
name- the Claim's name.items- the items the Claim must contain.- Returns:
- this same Verification instance.
- Throws:
java.lang.IllegalArgumentException- if the name is null.
-
build
public JWTVerifier build()
Creates a new and reusable instance of the JWTVerifier with the configuration already provided.- Specified by:
buildin interfaceVerification- Returns:
- a new JWTVerifier instance.
-
build
public JWTVerifier build(Clock clock)
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
private void assertNonNull(java.lang.String name)
-
addLeewayToDateClaims
private void addLeewayToDateClaims()
-
requireClaim
private void requireClaim(java.lang.String name, java.lang.Object value)
-
-