diff --git a/lib/src/main/java/com/auth0/jwt/JWTVerifier.java b/lib/src/main/java/com/auth0/jwt/JWTVerifier.java index bf180300..d4b3d637 100644 --- a/lib/src/main/java/com/auth0/jwt/JWTVerifier.java +++ b/lib/src/main/java/com/auth0/jwt/JWTVerifier.java @@ -343,7 +343,7 @@ private boolean assertValidInstantClaim(String claimName, Claim claim, long leew if (shouldBeFuture) { isValid = assertInstantIsFuture(claimVal, leeway, now); if (!isValid) { - throw new TokenExpiredException(String.format("The Token has expired on %s.", claimVal), claimVal); + throw new TokenExpiredException(String.format("The Token has expired on %s.", claimVal), claim); } } else { isValid = assertInstantIsLessThanOrEqualToNow(claimVal, leeway, now); diff --git a/lib/src/main/java/com/auth0/jwt/exceptions/IncorrectClaimException.java b/lib/src/main/java/com/auth0/jwt/exceptions/IncorrectClaimException.java index 712e937b..da62dbaa 100644 --- a/lib/src/main/java/com/auth0/jwt/exceptions/IncorrectClaimException.java +++ b/lib/src/main/java/com/auth0/jwt/exceptions/IncorrectClaimException.java @@ -6,7 +6,6 @@ * This exception is thrown when the expected value is not found while verifying the Claims. */ public class IncorrectClaimException extends InvalidClaimException { - private final String claimName; private final Claim claimValue; @@ -19,20 +18,10 @@ public class IncorrectClaimException extends InvalidClaimException { * @param claim The Claim value for which verification failed */ public IncorrectClaimException(String message, String claimName, Claim claim) { - super(message); - this.claimName = claimName; + super(message, claimName); this.claimValue = claim; } - /** - * This method can be used to fetch the name for which the Claim verification failed. - * - * @return The claim name for which the verification failed. - */ - public String getClaimName() { - return claimName; - } - /** * This method can be used to fetch the value for which the Claim verification failed. * diff --git a/lib/src/main/java/com/auth0/jwt/exceptions/InvalidClaimException.java b/lib/src/main/java/com/auth0/jwt/exceptions/InvalidClaimException.java index c5b8eb64..6284d9b3 100644 --- a/lib/src/main/java/com/auth0/jwt/exceptions/InvalidClaimException.java +++ b/lib/src/main/java/com/auth0/jwt/exceptions/InvalidClaimException.java @@ -4,7 +4,21 @@ * The exception that will be thrown while verifying Claims of a JWT. */ public class InvalidClaimException extends JWTVerificationException { - public InvalidClaimException(String message) { + + private final String claimName; + + public InvalidClaimException(String message, String claimName) { super(message); + this.claimName = claimName; } + + /** + * This method can be used to fetch the name for which the Claim verification failed. + * + * @return The claim name for which the verification failed. + */ + public String getClaimName() { + return claimName; + } + } \ No newline at end of file diff --git a/lib/src/main/java/com/auth0/jwt/exceptions/MissingClaimException.java b/lib/src/main/java/com/auth0/jwt/exceptions/MissingClaimException.java index 3bcc2121..90a798b4 100644 --- a/lib/src/main/java/com/auth0/jwt/exceptions/MissingClaimException.java +++ b/lib/src/main/java/com/auth0/jwt/exceptions/MissingClaimException.java @@ -5,19 +5,8 @@ */ public class MissingClaimException extends InvalidClaimException { - private final String claimName; - public MissingClaimException(String claimName) { - super(String.format("The Claim '%s' is not present in the JWT.", claimName)); - this.claimName = claimName; + super(String.format("The Claim '%s' is not present in the JWT.", claimName), claimName); } - /** - * This method can be used to fetch the name for which the Claim is missing during the verification. - * - * @return The name of the Claim that doesn't exist. - */ - public String getClaimName() { - return claimName; - } } diff --git a/lib/src/main/java/com/auth0/jwt/exceptions/TokenExpiredException.java b/lib/src/main/java/com/auth0/jwt/exceptions/TokenExpiredException.java index 42ab090d..00d5bd0e 100644 --- a/lib/src/main/java/com/auth0/jwt/exceptions/TokenExpiredException.java +++ b/lib/src/main/java/com/auth0/jwt/exceptions/TokenExpiredException.java @@ -1,19 +1,22 @@ package com.auth0.jwt.exceptions; +import com.auth0.jwt.RegisteredClaims; +import com.auth0.jwt.interfaces.Claim; + import java.time.Instant; /** * The exception that is thrown if the token is expired. */ -public class TokenExpiredException extends JWTVerificationException { +public class TokenExpiredException extends IncorrectClaimException { private static final long serialVersionUID = -7076928975713577708L; private final Instant expiredOn; - public TokenExpiredException(String message, Instant expiredOn) { - super(message); - this.expiredOn = expiredOn; + public TokenExpiredException(String message, Claim claim) { + super(message, RegisteredClaims.EXPIRES_AT, claim); + this.expiredOn = claim.asInstant(); } public Instant getExpiredOn() {