From 940086ff118db00a8e7c55d4372efc39507e1186 Mon Sep 17 00:00:00 2001 From: rabiuddin Date: Tue, 5 May 2026 22:55:42 +0500 Subject: [PATCH 1/2] Refactor: Change visibility of BaseVerification class to package-private, so as to not violate encapsulation principle. --- lib/src/main/java/com/auth0/jwt/JWTVerifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/auth0/jwt/JWTVerifier.java b/lib/src/main/java/com/auth0/jwt/JWTVerifier.java index bf180300..0a169505 100644 --- a/lib/src/main/java/com/auth0/jwt/JWTVerifier.java +++ b/lib/src/main/java/com/auth0/jwt/JWTVerifier.java @@ -52,7 +52,7 @@ static Verification init(Algorithm algorithm) throws IllegalArgumentException { * Note that this class is not thread-safe. Calling {@link #build()} returns an instance of * {@link com.auth0.jwt.interfaces.JWTVerifier} which can be reused. */ - public static class BaseVerification implements Verification { + static class BaseVerification implements Verification { private final Algorithm algorithm; private final List expectedChecks; private long defaultLeeway; From b6e0d1bb74da3c21adbc4de27de5db9a02dfb478 Mon Sep 17 00:00:00 2001 From: rabiuddin Date: Tue, 5 May 2026 23:06:42 +0500 Subject: [PATCH 2/2] Refactor: Consolidate withClaim and withArrayClaim methods to use generics for improved flexibility, and in accordance to the DRY principle. --- .../main/java/com/auth0/jwt/JWTCreator.java | 120 +----------------- 1 file changed, 4 insertions(+), 116 deletions(-) diff --git a/lib/src/main/java/com/auth0/jwt/JWTCreator.java b/lib/src/main/java/com/auth0/jwt/JWTCreator.java index bfcb9147..056e491c 100644 --- a/lib/src/main/java/com/auth0/jwt/JWTCreator.java +++ b/lib/src/main/java/com/auth0/jwt/JWTCreator.java @@ -253,96 +253,11 @@ public Builder withJWTId(String jwtId) { * * @param name the Claim's name. * @param value the Claim's value. + * @param the type of the claim value. * @return this same Builder instance. * @throws IllegalArgumentException if the name is null. */ - public Builder withClaim(String name, Boolean value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, Integer value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, Long value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, Double value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, String value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. The claim will be written as seconds since the epoch. - * Milliseconds will be truncated by rounding down to the nearest second. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, Date value) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, value); - return this; - } - - /** - * Add a custom Claim value. The claim will be written as seconds since the epoch. - * Milliseconds will be truncated by rounding down to the nearest second. - * - * @param name the Claim's name. - * @param value the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withClaim(String name, Instant value) throws IllegalArgumentException { + public Builder withClaim(String name, T value) throws IllegalArgumentException { assertNonNull(name); addClaim(name, value); return this; @@ -414,38 +329,11 @@ public Builder withNullClaim(String name) throws IllegalArgumentException { * * @param name the Claim's name. * @param items the Claim's value. + * @param the type of the array elements. * @return this same Builder instance. * @throws IllegalArgumentException if the name is null. */ - public Builder withArrayClaim(String name, String[] items) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, items); - return this; - } - - /** - * Add a custom Array Claim with the given items. - * - * @param name the Claim's name. - * @param items the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null. - */ - public Builder withArrayClaim(String name, Integer[] items) throws IllegalArgumentException { - assertNonNull(name); - addClaim(name, items); - return this; - } - - /** - * Add a custom Array Claim with the given items. - * - * @param name the Claim's name. - * @param items the Claim's value. - * @return this same Builder instance. - * @throws IllegalArgumentException if the name is null - */ - public Builder withArrayClaim(String name, Long[] items) throws IllegalArgumentException { + public Builder withArrayClaim(String name, T[] items) throws IllegalArgumentException { assertNonNull(name); addClaim(name, items); return this;