Skip to content

Commit 5037817

Browse files
committed
Code style changes
1 parent cea9297 commit 5037817

75 files changed

Lines changed: 765 additions & 498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/src/main/java/com/auth0/jwt/JWTDecoder.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package com.auth0.jwt;
2121

2222
import com.auth0.jwt.creators.EncodeType;
23-
import com.auth0.jwt.creators.JWTCreator;
24-
import com.auth0.jwt.exceptions.JWTDecodeException;
2523
import com.auth0.jwt.impl.JWTParser;
2624
import com.auth0.jwt.interfaces.Claim;
2725
import com.auth0.jwt.interfaces.DecodedJWT;
@@ -33,7 +31,6 @@
3331
import org.apache.commons.codec.binary.StringUtils;
3432

3533
import java.net.URLDecoder;
36-
import java.net.URLEncoder;
3734
import java.util.Date;
3835
import java.util.List;
3936
import java.util.Map;

lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
import com.auth0.jwt.interfaces.RSAKeyProvider;
2828

2929
import java.io.UnsupportedEncodingException;
30-
import java.security.interfaces.*;
30+
import java.security.interfaces.ECKey;
31+
import java.security.interfaces.ECPrivateKey;
32+
import java.security.interfaces.ECPublicKey;
33+
import java.security.interfaces.RSAKey;
34+
import java.security.interfaces.RSAPrivateKey;
35+
import java.security.interfaces.RSAPublicKey;
3136

3237
/**
3338
* The Algorithm class represents an algorithm to be used in the Signing or Verification process of a Token.
@@ -396,12 +401,15 @@ public String toString() {
396401

397402
@Override
398403
public boolean equals(Object algorithmParam) {
399-
if(this == algorithmParam)
404+
if (this == algorithmParam) {
400405
return true;
401-
if(algorithmParam == null)
406+
}
407+
if (algorithmParam == null) {
402408
return false;
403-
if(getClass() != algorithmParam.getClass())
409+
}
410+
if (getClass() != algorithmParam.getClass()) {
404411
return false;
412+
}
405413

406414
Algorithm algorithm = (Algorithm) algorithmParam;
407415
return this.description.equals(algorithm.description) && this.name.equals(algorithm.name);

lib/src/main/java/com/auth0/jwt/algorithms/CryptoHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121

2222
import javax.crypto.Mac;
2323
import javax.crypto.spec.SecretKeySpec;
24-
import java.security.*;
24+
25+
import java.security.InvalidKeyException;
26+
import java.security.MessageDigest;
27+
import java.security.NoSuchAlgorithmException;
28+
import java.security.PrivateKey;
29+
import java.security.PublicKey;
30+
import java.security.Signature;
31+
import java.security.SignatureException;
2532

2633
class CryptoHelper {
2734

lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.commons.codec.binary.Base32;
2828
import org.apache.commons.codec.binary.Base64;
2929
import org.apache.commons.codec.binary.Hex;
30-
import org.apache.commons.codec.binary.StringUtils;
3130

3231
import java.net.URLDecoder;
3332
import java.nio.charset.StandardCharsets;

lib/src/main/java/com/auth0/jwt/algorithms/HMACAlgorithm.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020
package com.auth0.jwt.algorithms;
2121

2222
import com.auth0.jwt.creators.EncodeType;
23-
import com.auth0.jwt.creators.JWTCreator;
2423
import com.auth0.jwt.exceptions.SignatureGenerationException;
2524
import com.auth0.jwt.exceptions.SignatureVerificationException;
2625
import com.auth0.jwt.interfaces.DecodedJWT;
2726
import org.apache.commons.codec.CharEncoding;
2827
import org.apache.commons.codec.binary.Base32;
2928
import org.apache.commons.codec.binary.Base64;
3029
import org.apache.commons.codec.binary.Hex;
31-
import org.apache.commons.codec.binary.StringUtils;
3230

3331
import java.io.UnsupportedEncodingException;
3432
import java.net.URLDecoder;
35-
import java.nio.charset.Charset;
3633
import java.nio.charset.StandardCharsets;
3734
import java.security.InvalidKeyException;
3835
import java.security.NoSuchAlgorithmException;

lib/src/main/java/com/auth0/jwt/creators/AccessJwtCreator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ public AccessJwtCreator withNonStandardClaim(String name, Date value) throws Ill
205205
*/
206206
public AccessJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
207207
jwt.withArrayClaim(name, items);
208-
if(publicClaims.contains(name))
208+
if (publicClaims.contains(name)) {
209209
addedClaims.put(name, true);
210+
}
210211
return this;
211212
}
212213

@@ -232,7 +233,7 @@ public AccessJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed
232233
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
233234
*/
234235
public String sign(Algorithm algorithm) throws Exception {
235-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
236+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
236237
throw new IllegalAccessException("None algorithm isn't allowed");
237238
}
238239
String JWS = jwt.sign(algorithm);
@@ -250,7 +251,7 @@ public String sign(Algorithm algorithm) throws Exception {
250251
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
251252
*/
252253
public String signBase16Encoding(Algorithm algorithm) throws Exception {
253-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
254+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
254255
throw new IllegalAccessException("None algorithm isn't allowed");
255256
}
256257
String JWS = jwt.sign(algorithm, EncodeType.Base16);
@@ -268,7 +269,7 @@ public String signBase16Encoding(Algorithm algorithm) throws Exception {
268269
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
269270
*/
270271
public String signBase32Encoding(Algorithm algorithm) throws Exception {
271-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
272+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
272273
throw new IllegalAccessException("None algorithm isn't allowed");
273274
}
274275
String JWS = jwt.sign(algorithm, EncodeType.Base32);
@@ -278,12 +279,15 @@ public String signBase32Encoding(Algorithm algorithm) throws Exception {
278279

279280
/**
280281
* Verifies that all the standard claims were provided
282+
*
281283
* @throws Exception if all the standard claims weren't provided
282284
*/
283285
private void verifyClaims() throws Exception {
284-
for(String claim : addedClaims.keySet())
285-
if(!addedClaims.get(claim))
286+
for (String claim : addedClaims.keySet()) {
287+
if (!addedClaims.get(claim)) {
286288
throw new Exception("Standard claim: " + claim + " has not been set");
289+
}
290+
}
287291
}
288292

289293
public static AccessJwtCreator build() {

lib/src/main/java/com/auth0/jwt/creators/ExtendedJwtCreator.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* The ExtendedJwtCreator class holds the sign method to generate a complete Extended JWT (with Signature) from a given Header and Payload content.
2929
*/
30-
public class ExtendedJwtCreator extends GoogleJwtCreator{
30+
public class ExtendedJwtCreator extends GoogleJwtCreator {
3131

3232
public ExtendedJwtCreator() {
3333
super();
@@ -53,8 +53,9 @@ public GoogleJwtCreator withNbf(Date nbf) {
5353
* @throws IllegalArgumentException if the provided algorithm is null.
5454
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
5555
*/
56+
@Override
5657
public String sign(Algorithm algorithm) throws Exception {
57-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
58+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
5859
throw new IllegalAccessException("None algorithm isn't allowed");
5960
}
6061
String JWS = jwt.sign(algorithm);
@@ -71,8 +72,9 @@ public String sign(Algorithm algorithm) throws Exception {
7172
* @throws IllegalArgumentException if the provided algorithm is null.
7273
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
7374
*/
75+
@Override
7476
public String signBase16Encoding(Algorithm algorithm) throws Exception {
75-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
77+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
7678
throw new IllegalAccessException("None algorithm isn't allowed");
7779
}
7880
String JWS = jwt.sign(algorithm, EncodeType.Base16);
@@ -89,8 +91,9 @@ public String signBase16Encoding(Algorithm algorithm) throws Exception {
8991
* @throws IllegalArgumentException if the provided algorithm is null.
9092
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
9193
*/
94+
@Override
9295
public String signBase32Encoding(Algorithm algorithm) throws Exception {
93-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
96+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
9497
throw new IllegalAccessException("None algorithm isn't allowed");
9598
}
9699
String JWS = jwt.sign(algorithm, EncodeType.Base32);
@@ -100,12 +103,15 @@ public String signBase32Encoding(Algorithm algorithm) throws Exception {
100103

101104
/**
102105
* Verifies that all the standard claims were provided
106+
*
103107
* @throws Exception if all the standard claims weren't provided
104108
*/
105109
private void verifyClaims() throws Exception {
106-
for(String claim : addedClaims.keySet())
107-
if(!addedClaims.get(claim))
110+
for (String claim : addedClaims.keySet()) {
111+
if (!addedClaims.get(claim)) {
108112
throw new Exception("Standard claim: " + claim + " has not been set");
113+
}
114+
}
109115
}
110116

111117
public static ExtendedJwtCreator build() {

lib/src/main/java/com/auth0/jwt/creators/FbJwtCreator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ public FbJwtCreator withNonStandardClaim(String name, Date value) throws Illegal
186186
*/
187187
public FbJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
188188
jwt.withArrayClaim(name, items);
189-
if(publicClaims.contains(name))
189+
if (publicClaims.contains(name)) {
190190
addedClaims.put(name, true);
191+
}
191192
return this;
192193
}
193194

@@ -213,7 +214,7 @@ public FbJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
213214
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
214215
*/
215216
public String sign(Algorithm algorithm) throws Exception {
216-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
217+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
217218
throw new IllegalAccessException("None algorithm isn't allowed");
218219
}
219220
String JWS = jwt.sign(algorithm);
@@ -231,7 +232,7 @@ public String sign(Algorithm algorithm) throws Exception {
231232
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
232233
*/
233234
public String signBase16Encoding(Algorithm algorithm) throws Exception {
234-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
235+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
235236
throw new IllegalAccessException("None algorithm isn't allowed");
236237
}
237238
String JWS = jwt.sign(algorithm, EncodeType.Base16);
@@ -249,7 +250,7 @@ public String signBase16Encoding(Algorithm algorithm) throws Exception {
249250
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
250251
*/
251252
public String signBase32Encoding(Algorithm algorithm) throws Exception {
252-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
253+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
253254
throw new IllegalAccessException("None algorithm isn't allowed");
254255
}
255256
String JWS = jwt.sign(algorithm, EncodeType.Base32);
@@ -259,12 +260,15 @@ public String signBase32Encoding(Algorithm algorithm) throws Exception {
259260

260261
/**
261262
* Verifies that all the standard claims were provided
263+
*
262264
* @throws Exception if all the standard claims weren't provided
263265
*/
264266
private void verifyClaims() throws Exception {
265-
for(String claim : addedClaims.keySet())
266-
if(!addedClaims.get(claim))
267+
for (String claim : addedClaims.keySet()) {
268+
if (!addedClaims.get(claim)) {
267269
throw new Exception("Standard claim: " + claim + " has not been set");
270+
}
271+
}
268272
}
269273

270274
public static FbJwtCreator build() {

lib/src/main/java/com/auth0/jwt/creators/GoogleJwtCreator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ public GoogleJwtCreator withNonStandardClaim(String name, Date value) throws Ill
245245
*/
246246
public GoogleJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
247247
jwt.withArrayClaim(name, items);
248-
if(publicClaims.contains(name))
248+
if (publicClaims.contains(name)) {
249249
addedClaims.put(name, true);
250+
}
250251
return this;
251252
}
252253

@@ -272,7 +273,7 @@ public GoogleJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed
272273
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
273274
*/
274275
public String sign(Algorithm algorithm) throws Exception {
275-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
276+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
276277
throw new IllegalAccessException("None algorithm isn't allowed");
277278
}
278279
String JWS = jwt.sign(algorithm);
@@ -290,7 +291,7 @@ public String sign(Algorithm algorithm) throws Exception {
290291
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
291292
*/
292293
public String signBase16Encoding(Algorithm algorithm) throws Exception {
293-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
294+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
294295
throw new IllegalAccessException("None algorithm isn't allowed");
295296
}
296297
String JWS = jwt.sign(algorithm, EncodeType.Base16);
@@ -308,7 +309,7 @@ public String signBase16Encoding(Algorithm algorithm) throws Exception {
308309
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
309310
*/
310311
public String signBase32Encoding(Algorithm algorithm) throws Exception {
311-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
312+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
312313
throw new IllegalAccessException("None algorithm isn't allowed");
313314
}
314315
String JWS = jwt.sign(algorithm, EncodeType.Base32);
@@ -318,12 +319,15 @@ public String signBase32Encoding(Algorithm algorithm) throws Exception {
318319

319320
/**
320321
* Verifies that all the standard claims were provided
322+
*
321323
* @throws Exception if all the standard claims weren't provided
322324
*/
323325
private void verifyClaims() throws Exception {
324-
for(String claim : addedClaims.keySet())
325-
if(!addedClaims.get(claim))
326+
for (String claim : addedClaims.keySet()) {
327+
if (!addedClaims.get(claim)) {
326328
throw new Exception("Standard claim: " + claim + " has not been set");
329+
}
330+
}
327331
}
328332

329333
public static GoogleJwtCreator build() {

lib/src/main/java/com/auth0/jwt/creators/ImplicitJwtCreator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ public ImplicitJwtCreator withNonStandardClaim(String name, Date value) throws I
191191
*/
192192
public ImplicitJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
193193
jwt.withArrayClaim(name, items);
194-
if(publicClaims.contains(name))
194+
if (publicClaims.contains(name)) {
195195
addedClaims.put(name, true);
196+
}
196197
return this;
197198
}
198199

@@ -218,7 +219,7 @@ public ImplicitJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllow
218219
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
219220
*/
220221
public String sign(Algorithm algorithm) throws Exception {
221-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
222+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
222223
throw new IllegalAccessException("None algorithm isn't allowed");
223224
}
224225
String JWS = jwt.sign(algorithm);
@@ -236,7 +237,7 @@ public String sign(Algorithm algorithm) throws Exception {
236237
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
237238
*/
238239
public String signBase16Encoding(Algorithm algorithm) throws Exception {
239-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
240+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
240241
throw new IllegalAccessException("None algorithm isn't allowed");
241242
}
242243
String JWS = jwt.sign(algorithm, EncodeType.Base16);
@@ -254,7 +255,7 @@ public String signBase16Encoding(Algorithm algorithm) throws Exception {
254255
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
255256
*/
256257
public String signBase32Encoding(Algorithm algorithm) throws Exception {
257-
if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
258+
if (!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
258259
throw new IllegalAccessException("None algorithm isn't allowed");
259260
}
260261
String JWS = jwt.sign(algorithm, EncodeType.Base32);
@@ -264,12 +265,15 @@ public String signBase32Encoding(Algorithm algorithm) throws Exception {
264265

265266
/**
266267
* Verifies that all the standard claims were provided
268+
*
267269
* @throws Exception if all the standard claims weren't provided
268270
*/
269271
private void verifyClaims() throws Exception {
270-
for(String claim : addedClaims.keySet())
271-
if(!addedClaims.get(claim))
272+
for (String claim : addedClaims.keySet()) {
273+
if (!addedClaims.get(claim)) {
272274
throw new Exception("Standard claim: " + claim + " has not been set");
275+
}
276+
}
273277
}
274278

275279
public static ImplicitJwtCreator build() {

0 commit comments

Comments
 (0)