Skip to content

Commit

Permalink
fix: early exit to avoid nested if(s)
Browse files Browse the repository at this point in the history
early exit is request is null
  • Loading branch information
HemantKMehta authored Feb 3, 2022
1 parent 5057531 commit ab65ac9
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -795,31 +795,29 @@ private Response requestAuthorization(

@Nullable
private JsonWebResponse parseRequestToJwr(String request) {
if (request != null) {
String[] parts = request.split("\\.");
try {
if (parts.length == 5) {
String encodedHeader = parts[0];
JwtHeader jwtHeader = new JwtHeader(encodedHeader);
String keyId = jwtHeader.getKeyId();
PrivateKey privateKey = null;
KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm
.fromName(jwtHeader.getClaimAsString(JwtHeaderName.ALGORITHM));
if (AlgorithmFamily.RSA.equals(keyEncryptionAlgorithm.getFamily())) {
privateKey = cryptoProvider.getPrivateKey(keyId);
}
Jwe jwe = Jwe.parse(request, privateKey, null);
if (jwe == null) {
return null;
}
return jwe;
if (request == null) {
return null;
}
String[] parts = request.split("\\.");
try {
if (parts.length == 5) {
String encodedHeader = parts[0];
JwtHeader jwtHeader = new JwtHeader(encodedHeader);
String keyId = jwtHeader.getKeyId();
PrivateKey privateKey = null;
KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm
.fromName(jwtHeader.getClaimAsString(JwtHeaderName.ALGORITHM));
if (AlgorithmFamily.RSA.equals(keyEncryptionAlgorithm.getFamily())) {
privateKey = cryptoProvider.getPrivateKey(keyId);
}
return Jwt.parseSilently(request);
} catch (Exception e) {
log.error(e.getMessage(), e);
Jwe jwe = Jwe.parse(request, privateKey, null);
return jwe;
}
return Jwt.parseSilently(request);
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
return null;
}

private void fillRedirectUriResponseforJARM(RedirectUriResponse redirectUriResponse, JsonWebResponse jwr, Client client) {
Expand Down

0 comments on commit ab65ac9

Please sign in to comment.