Skip to content

Commit

Permalink
Run spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <cwperx@amazon.com>
  • Loading branch information
cwperks committed Nov 9, 2022
1 parent 1d98c28 commit 271cb3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public BadCredentialsException() {
super();
}

public BadCredentialsException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
public BadCredentialsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ public static String createJwt(Map<String, Object> claims) {
String encodedJwt = jwtProducer.processJwt(jwt);

if (logger.isDebugEnabled()) {
logger.debug("Created JWT: " + encodedJwt + "\n" + jsonMapReaderWriter.toJson(jwt.getJwsHeaders()) + "\n"
+ JwtUtils.claimsToJson(jwt.getClaims()));
logger.debug(
"Created JWT: "
+ encodedJwt
+ "\n"
+ jsonMapReaderWriter.toJson(jwt.getJwsHeaders())
+ "\n"
+ JwtUtils.claimsToJson(jwt.getClaims())
);
}

return encodedJwt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ public static JwtToken getVerifiedJwtToken(String encodedJwt) throws BadCredenti
JsonWebKey key = JwtVendor.getDefaultJsonWebKey();

// Algorithm is not mandatory for the key material, so we set it to the same as the JWT
if (key.getAlgorithm() == null && key.getPublicKeyUse() == PublicKeyUse.SIGN && key.getKeyType() == KeyType.RSA)
{
if (key.getAlgorithm() == null && key.getPublicKeyUse() == PublicKeyUse.SIGN && key.getKeyType() == KeyType.RSA) {
key.setAlgorithm(jwt.getJwsHeaders().getAlgorithm());
}

JwsSignatureVerifier signatureVerifier = getInitializedSignatureVerifier(key, jwt);


boolean signatureValid = jwtConsumer.verifySignatureWith(signatureVerifier);

if (!signatureValid) {
Expand All @@ -66,17 +64,18 @@ private static void validateSignatureAlgorithm(JsonWebKey key, JwtToken jwt) thr
return;
}

SignatureAlgorithm keyAlgorithm =SignatureAlgorithm.getAlgorithm(key.getAlgorithm());
SignatureAlgorithm keyAlgorithm = SignatureAlgorithm.getAlgorithm(key.getAlgorithm());
SignatureAlgorithm tokenAlgorithm = SignatureAlgorithm.getAlgorithm(jwt.getJwsHeaders().getAlgorithm());

if (!keyAlgorithm.equals(tokenAlgorithm)) {
throw new BadCredentialsException("Algorithm of JWT does not match algorithm of JWK (" + keyAlgorithm + " != " + tokenAlgorithm + ")");
throw new BadCredentialsException(
"Algorithm of JWT does not match algorithm of JWK (" + keyAlgorithm + " != " + tokenAlgorithm + ")"
);
}
}


private static JwsSignatureVerifier getInitializedSignatureVerifier(JsonWebKey key, JwtToken jwt)
throws BadCredentialsException, JwtException {
private static JwsSignatureVerifier getInitializedSignatureVerifier(JsonWebKey key, JwtToken jwt) throws BadCredentialsException,
JwtException {

validateSignatureAlgorithm(key, jwt);
JwsSignatureVerifier result = JwsUtils.getSignatureVerifier(key, jwt.getJwsHeaders().getSignatureAlgorithm());
Expand Down

0 comments on commit 271cb3d

Please sign in to comment.