11package com .auth0 .jwt ;
22
33import com .auth0 .jwt .algorithms .Algorithm ;
4- import com .auth0 .jwt .exceptions .*;
4+ import com .auth0 .jwt .exceptions .AlgorithmMismatchException ;
5+ import com .auth0 .jwt .exceptions .InvalidClaimException ;
6+ import com .auth0 .jwt .exceptions .JWTVerificationException ;
7+ import com .auth0 .jwt .exceptions .SignatureVerificationException ;
58import com .auth0 .jwt .impl .PublicClaims ;
69import com .auth0 .jwt .interfaces .Claim ;
710import org .apache .commons .codec .binary .Base64 ;
@@ -39,7 +42,7 @@ static JWTVerifier.Verification init(Algorithm algorithm) throws IllegalArgument
3942 static class Verification {
4043 private final Algorithm algorithm ;
4144 private final Map <String , Object > claims ;
42- private long defaultDelta ;
45+ private long defaultLeeway ;
4346
4447 Verification (Algorithm algorithm ) throws IllegalArgumentException {
4548 if (algorithm == null ) {
@@ -48,7 +51,7 @@ static class Verification {
4851
4952 this .algorithm = algorithm ;
5053 this .claims = new HashMap <>();
51- this .defaultDelta = 0 ;
54+ this .defaultLeeway = 0 ;
5255 }
5356
5457 /**
@@ -86,65 +89,65 @@ public Verification withAudience(String... audience) {
8689
8790 /**
8891 * Define the default window in milliseconds in which the Not Before, Issued At and Expires At Claims will still be valid.
89- * Setting a specific delta value on a given Claim will override this value for that Claim.
92+ * Setting a specific leeway value on a given Claim will override this value for that Claim.
9093 *
91- * @param delta the window in milliseconds in which the Not Before, Issued At and Expires At Claims will still be valid.
94+ * @param leeway the window in milliseconds in which the Not Before, Issued At and Expires At Claims will still be valid.
9295 * @return this same Verification instance.
93- * @throws IllegalArgumentException if delta is negative.
96+ * @throws IllegalArgumentException if leeway is negative.
9497 */
95- public Verification acceptTimeDelta (long delta ) throws IllegalArgumentException {
96- if (delta < 0 ) {
97- throw new IllegalArgumentException ("Delta value can't be negative." );
98+ public Verification acceptLeeway (long leeway ) throws IllegalArgumentException {
99+ if (leeway < 0 ) {
100+ throw new IllegalArgumentException ("Leeway value can't be negative." );
98101 }
99- this .defaultDelta = delta ;
102+ this .defaultLeeway = leeway ;
100103 return this ;
101104 }
102105
103106 /**
104- * Set a specific delta window in milliseconds in which the Expires At ("exp") Claim will still be valid.
105- * Expiration Date is always verified when the value is present. This method overrides the value set with acceptTimeDelta
107+ * Set a specific leeway window in milliseconds in which the Expires At ("exp") Claim will still be valid.
108+ * Expiration Date is always verified when the value is present. This method overrides the value set with acceptLeeway
106109 *
107- * @param delta the window in milliseconds in which the Expires At Claim will still be valid.
110+ * @param leeway the window in milliseconds in which the Expires At Claim will still be valid.
108111 * @return this same Verification instance.
109- * @throws IllegalArgumentException if delta is negative.
112+ * @throws IllegalArgumentException if leeway is negative.
110113 */
111- public Verification acceptExpiresAt (long delta ) throws IllegalArgumentException {
112- if (delta < 0 ) {
113- throw new IllegalArgumentException ("Delta value can't be negative." );
114+ public Verification acceptExpiresAt (long leeway ) throws IllegalArgumentException {
115+ if (leeway < 0 ) {
116+ throw new IllegalArgumentException ("Leeway value can't be negative." );
114117 }
115- requireClaim (PublicClaims .EXPIRES_AT , delta );
118+ requireClaim (PublicClaims .EXPIRES_AT , leeway );
116119 return this ;
117120 }
118121
119122 /**
120- * Set a specific delta window in milliseconds in which the Not Before ("nbf") Claim will still be valid.
121- * Not Before Date is always verified when the value is present. This method overrides the value set with acceptTimeDelta
123+ * Set a specific leeway window in milliseconds in which the Not Before ("nbf") Claim will still be valid.
124+ * Not Before Date is always verified when the value is present. This method overrides the value set with acceptLeeway
122125 *
123- * @param delta the window in milliseconds in which the Not Before Claim will still be valid.
126+ * @param leeway the window in milliseconds in which the Not Before Claim will still be valid.
124127 * @return this same Verification instance.
125- * @throws IllegalArgumentException if delta is negative.
128+ * @throws IllegalArgumentException if leeway is negative.
126129 */
127- public Verification acceptNotBefore (long delta ) throws IllegalArgumentException {
128- if (delta < 0 ) {
129- throw new IllegalArgumentException ("Delta value can't be negative." );
130+ public Verification acceptNotBefore (long leeway ) throws IllegalArgumentException {
131+ if (leeway < 0 ) {
132+ throw new IllegalArgumentException ("Leeway value can't be negative." );
130133 }
131- requireClaim (PublicClaims .NOT_BEFORE , delta );
134+ requireClaim (PublicClaims .NOT_BEFORE , leeway );
132135 return this ;
133136 }
134137
135138 /**
136- * Set a specific delta window in milliseconds in which the Issued At ("iat") Claim will still be valid.
137- * Issued At Date is always verified when the value is present. This method overrides the value set with acceptTimeDelta
139+ * Set a specific leeway window in milliseconds in which the Issued At ("iat") Claim will still be valid.
140+ * Issued At Date is always verified when the value is present. This method overrides the value set with acceptLeeway
138141 *
139- * @param delta the window in milliseconds in which the Issued At Claim will still be valid.
142+ * @param leeway the window in milliseconds in which the Issued At Claim will still be valid.
140143 * @return this same Verification instance.
141- * @throws IllegalArgumentException if delta is negative.
144+ * @throws IllegalArgumentException if leeway is negative.
142145 */
143- public Verification acceptIssuedAt (long delta ) throws IllegalArgumentException {
144- if (delta < 0 ) {
145- throw new IllegalArgumentException ("Delta value can't be negative." );
146+ public Verification acceptIssuedAt (long leeway ) throws IllegalArgumentException {
147+ if (leeway < 0 ) {
148+ throw new IllegalArgumentException ("Leeway value can't be negative." );
146149 }
147- requireClaim (PublicClaims .ISSUED_AT , delta );
150+ requireClaim (PublicClaims .ISSUED_AT , leeway );
148151 return this ;
149152 }
150153
@@ -204,13 +207,13 @@ JWTVerifier build(Clock clock) {
204207
205208 private void addDeltaToDateClaims () {
206209 if (!claims .containsKey (PublicClaims .EXPIRES_AT )) {
207- claims .put (PublicClaims .EXPIRES_AT , defaultDelta );
210+ claims .put (PublicClaims .EXPIRES_AT , defaultLeeway );
208211 }
209212 if (!claims .containsKey (PublicClaims .NOT_BEFORE )) {
210- claims .put (PublicClaims .NOT_BEFORE , defaultDelta );
213+ claims .put (PublicClaims .NOT_BEFORE , defaultLeeway );
211214 }
212215 if (!claims .containsKey (PublicClaims .ISSUED_AT )) {
213- claims .put (PublicClaims .ISSUED_AT , defaultDelta );
216+ claims .put (PublicClaims .ISSUED_AT , defaultLeeway );
214217 }
215218 }
216219
@@ -307,16 +310,16 @@ private void assertValidStringClaim(String claimName, String value, String expec
307310 }
308311 }
309312
310- private void assertValidDateClaim (Date date , long delta , boolean shouldBeFuture ) {
313+ private void assertValidDateClaim (Date date , long leeway , boolean shouldBeFuture ) {
311314 Date today = clock .getToday ();
312315 boolean isValid ;
313316 String errMessage ;
314317 if (shouldBeFuture ) {
315- today .setTime (today .getTime () - delta );
318+ today .setTime (today .getTime () - leeway );
316319 isValid = date == null || !today .after (date );
317320 errMessage = String .format ("The Token has expired on %s." , date );
318321 } else {
319- today .setTime (today .getTime () + delta );
322+ today .setTime (today .getTime () + leeway );
320323 isValid = date == null || !today .before (date );
321324 errMessage = String .format ("The Token can't be used before %s." , date );
322325 }
0 commit comments