Skip to content

Commit

Permalink
remove some <>'s and undo some accidental codestyle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thepeachbeetle committed Jul 25, 2017
1 parent ba3ae16 commit f1e1eec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/jsonwebtoken/SigningKeyResolverAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Collection<Key> resolveSigningKeys(JwsHeader header, Claims claims) {
Collection<byte[]> keysBytes = resolveSigningKeysBytes(header, claims);
if (keysBytes == null)
return null;
Collection<Key> keys = new ArrayList<>();
Collection<Key> keys = new ArrayList<Key>();
for (byte[] keyBytes: keysBytes)
keys.add(new SecretKeySpec(keyBytes, alg.getJcaName()));

Expand Down Expand Up @@ -91,7 +91,7 @@ public Collection<Key> resolveSigningKeys(JwsHeader header, String plaintext) {
Collection<byte[]> keysBytes = resolveSigningKeysBytes(header, plaintext);
if (keysBytes == null)
return null;
Collection<Key> keys = new ArrayList<>();
Collection<Key> keys = new ArrayList<Key>();
for (byte[] keyBytes: keysBytes)
keys.add(new SecretKeySpec(keyBytes, alg.getJcaName()));

Expand Down
46 changes: 23 additions & 23 deletions src/main/java/io/jsonwebtoken/impl/DefaultJwtParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class DefaultJwtParser implements JwtParser {
private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final int MILLISECONDS_PER_SECOND = 1000;

private final ObjectMapper objectMapper = new ObjectMapper();
private ObjectMapper objectMapper = new ObjectMapper();

private Collection<byte[]> keyBytes;

Expand All @@ -79,51 +79,51 @@ public class DefaultJwtParser implements JwtParser {

@Override
public JwtParser requireIssuedAt(Date issuedAt) {
this.expectedClaims.setIssuedAt(issuedAt);
expectedClaims.setIssuedAt(issuedAt);
return this;
}

@Override
public JwtParser requireIssuer(String issuer) {
this.expectedClaims.setIssuer(issuer);
expectedClaims.setIssuer(issuer);
return this;
}

@Override
public JwtParser requireAudience(String audience) {
this.expectedClaims.setAudience(audience);
expectedClaims.setAudience(audience);
return this;
}

@Override
public JwtParser requireSubject(String subject) {
this.expectedClaims.setSubject(subject);
expectedClaims.setSubject(subject);
return this;
}

@Override
public JwtParser requireId(String id) {
this.expectedClaims.setId(id);
expectedClaims.setId(id);
return this;
}

@Override
public JwtParser requireExpiration(Date expiration) {
this.expectedClaims.setExpiration(expiration);
expectedClaims.setExpiration(expiration);
return this;
}

@Override
public JwtParser requireNotBefore(Date notBefore) {
this.expectedClaims.setNotBefore(notBefore);
expectedClaims.setNotBefore(notBefore);
return this;
}

@Override
public JwtParser require(String claimName, Object value) {
Assert.hasText(claimName, "claim name cannot be null or empty.");
Assert.notNull(value, "The value cannot be null for claim name: " + claimName);
this.expectedClaims.put(claimName, value);
expectedClaims.put(claimName, value);
return this;
}

Expand All @@ -144,7 +144,7 @@ public JwtParser setAllowedClockSkewSeconds(long seconds) {
public JwtParser setSigningKey(byte[] key) {
Assert.notEmpty(key, "signing key cannot be null or empty.");
if (this.keyBytes == null)
this.keyBytes = new ArrayList<>();
this.keyBytes = new ArrayList<byte[]>();
this.keyBytes.add(key);
return this;
}
Expand All @@ -153,7 +153,7 @@ public JwtParser setSigningKey(byte[] key) {
public JwtParser setSigningKey(String base64EncodedKeyBytes) {
Assert.hasText(base64EncodedKeyBytes, "signing key cannot be null or empty.");
if (this.keyBytes == null)
this.keyBytes = new ArrayList<>();
this.keyBytes = new ArrayList<byte[]>();
this.keyBytes.add(TextCodec.BASE64.decode(base64EncodedKeyBytes));
return this;
}
Expand All @@ -162,7 +162,7 @@ public JwtParser setSigningKey(String base64EncodedKeyBytes) {
public JwtParser setSigningKey(Key key) {
Assert.notNull(key, "signing key cannot be null.");
if (this.keys == null)
this.keys = new ArrayList<>();
this.keys = new ArrayList<Key>();
this.keys.add(key);
return this;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public Jwt parse(String jwt) throws ExpiredJwtException, MalformedJwtException,
header = new DefaultHeader(m);
}

compressionCodec = this.compressionCodecResolver.resolveCompressionCodec(header);
compressionCodec = compressionCodecResolver.resolveCompressionCodec(header);
}

// =============== Body =================
Expand Down Expand Up @@ -318,7 +318,7 @@ public Jwt parse(String jwt) throws ExpiredJwtException, MalformedJwtException,
if (keys == null) { //fall back to keyBytes

if (Objects.isEmpty(this.keyBytes) && this.signingKeyResolver != null) { //use the signingKeyResolver
keys = new ArrayList<>();
keys = new ArrayList<Key>();
if (claims != null) {
Key key = this.signingKeyResolver.resolveSigningKey(jwsHeader, claims);
if (key != null)
Expand All @@ -341,7 +341,7 @@ public Jwt parse(String jwt) throws ExpiredJwtException, MalformedJwtException,
Assert.isTrue(algorithm.isHmac(),
"Key bytes can only be specified for HMAC signatures. Please specify a PublicKey or PrivateKey instance.");

keys = new ArrayList<>();
keys = new ArrayList<Key>();
for (byte[] bytes: this.keyBytes)
this.keys.add(new SecretKeySpec(bytes, algorithm.getJcaName()));
}
Expand Down Expand Up @@ -441,17 +441,17 @@ public Jwt parse(String jwt) throws ExpiredJwtException, MalformedJwtException,
}

private void validateExpectedClaims(Header header, Claims claims) {
for (String expectedClaimName : this.expectedClaims.keySet()) {
for (String expectedClaimName : expectedClaims.keySet()) {

Object expectedClaimValue = this.expectedClaims.get(expectedClaimName);
Object expectedClaimValue = expectedClaims.get(expectedClaimName);
Object actualClaimValue = claims.get(expectedClaimName);

if (
Claims.ISSUED_AT.equals(expectedClaimName) ||
Claims.EXPIRATION.equals(expectedClaimName) ||
Claims.NOT_BEFORE.equals(expectedClaimName)
) {
expectedClaimValue = this.expectedClaims.get(expectedClaimName, Date.class);
expectedClaimValue = expectedClaims.get(expectedClaimName, Date.class);
actualClaimValue = claims.get(expectedClaimName, Date.class);
} else if (
expectedClaimValue instanceof Date &&
Expand Down Expand Up @@ -504,16 +504,16 @@ public <T> T parse(String compact, JwtHandler<T> handler)
Jws jws = (Jws) jwt;
Object body = jws.getBody();
if (body instanceof Claims) {
return handler.onClaimsJws(jws);
return handler.onClaimsJws((Jws<Claims>) jws);
} else {
return handler.onPlaintextJws(jws);
return handler.onPlaintextJws((Jws<String>) jws);
}
} else {
Object body = jwt.getBody();
if (body instanceof Claims) {
return handler.onClaimsJwt(jwt);
return handler.onClaimsJwt((Jwt<Header, Claims>) jwt);
} else {
return handler.onPlaintextJwt(jwt);
return handler.onPlaintextJwt((Jwt<Header, String>) jwt);
}
}
}
Expand Down Expand Up @@ -569,7 +569,7 @@ public Jws<Claims> onClaimsJws(Jws<Claims> jws) {
@SuppressWarnings("unchecked")
protected Map<String, Object> readValue(String val) {
try {
return this.objectMapper.readValue(val, Map.class);
return objectMapper.readValue(val, Map.class);
} catch (IOException e) {
throw new MalformedJwtException("Unable to read JSON value: " + val, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MacValidator implements SignatureValidator {
private final Collection<MacSigner> signers;

public MacValidator(SignatureAlgorithm alg, Collection<Key> keys) {
Collection<MacSigner> signers = new ArrayList<>();
Collection<MacSigner> signers = new ArrayList<MacSigner>();
for (Key key: keys)
signers.add(new MacSigner(alg, key));
this.signers = signers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SignerAndKey(final RsaSigner signer, final Key key) {
public RsaSignatureValidator(SignatureAlgorithm alg, Collection<Key> keys) {
super(alg, null);

Collection<SignerAndKey> SIGNERS = new ArrayList<>();
Collection<SignerAndKey> SIGNERS = new ArrayList<SignerAndKey>();
for (Key key: keys) {
Assert.isTrue(key instanceof RSAPrivateKey || key instanceof RSAPublicKey,
"RSA Signature validation requires either a RSAPublicKey or RSAPrivateKey instance.");
Expand Down

0 comments on commit f1e1eec

Please sign in to comment.