Skip to content

Commit

Permalink
Fixed the exception in keyutils
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Aug 25, 2023
1 parent 4b406c5 commit 1e24bbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private JwtParserBuilder initParserBuilder(final String signingKey) {
JwtParserBuilder jwtParserBuilder = KeyUtils.createJwtParserBuilderFromSigningKey(signingKey, log);

if (jwtParserBuilder == null) {
throw new RuntimeException("Unable to find on behalf of authenticator signing key");
throw new OpenSearchSecurityException("Unable to find on behalf of authenticator signing key");
}

return jwtParserBuilder;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/opensearch/security/util/KeyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.jsonwebtoken.JwtParserBuilder;
import io.jsonwebtoken.Jwts;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.core.common.Strings;

Expand Down Expand Up @@ -51,13 +52,13 @@ public JwtParserBuilder run() {

try {
key = getPublicKey(decoded, "RSA");
} catch (Exception e) {
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
log.debug("No public RSA key, try other algos ({})", e.toString());
}

try {
key = getPublicKey(decoded, "EC");
} catch (final Exception e) {
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
log.debug("No public ECDSA key, try other algos ({})", e.toString());
}

Expand All @@ -68,7 +69,7 @@ public JwtParserBuilder run() {
return Jwts.parserBuilder().setSigningKey(decoded);
} catch (Throwable e) {
log.error("Error while creating JWT authenticator", e);
throw new RuntimeException(e);
throw new OpenSearchSecurityException(e.toString(), e);
}
}
}
Expand Down

0 comments on commit 1e24bbb

Please sign in to comment.