Skip to content

Commit 1e24bbb

Browse files
committed
Fixed the exception in keyutils
Signed-off-by: Ryan Liang <jiallian@amazon.com>
1 parent 4b406c5 commit 1e24bbb

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/org/opensearch/security/http/OnBehalfOfAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private JwtParserBuilder initParserBuilder(final String signingKey) {
7878
JwtParserBuilder jwtParserBuilder = KeyUtils.createJwtParserBuilderFromSigningKey(signingKey, log);
7979

8080
if (jwtParserBuilder == null) {
81-
throw new RuntimeException("Unable to find on behalf of authenticator signing key");
81+
throw new OpenSearchSecurityException("Unable to find on behalf of authenticator signing key");
8282
}
8383

8484
return jwtParserBuilder;

src/main/java/org/opensearch/security/util/KeyUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.jsonwebtoken.JwtParserBuilder;
1515
import io.jsonwebtoken.Jwts;
1616
import org.apache.logging.log4j.Logger;
17+
import org.opensearch.OpenSearchSecurityException;
1718
import org.opensearch.SpecialPermission;
1819
import org.opensearch.core.common.Strings;
1920

@@ -51,13 +52,13 @@ public JwtParserBuilder run() {
5152

5253
try {
5354
key = getPublicKey(decoded, "RSA");
54-
} catch (Exception e) {
55+
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
5556
log.debug("No public RSA key, try other algos ({})", e.toString());
5657
}
5758

5859
try {
5960
key = getPublicKey(decoded, "EC");
60-
} catch (final Exception e) {
61+
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
6162
log.debug("No public ECDSA key, try other algos ({})", e.toString());
6263
}
6364

@@ -68,7 +69,7 @@ public JwtParserBuilder run() {
6869
return Jwts.parserBuilder().setSigningKey(decoded);
6970
} catch (Throwable e) {
7071
log.error("Error while creating JWT authenticator", e);
71-
throw new RuntimeException(e);
72+
throw new OpenSearchSecurityException(e.toString(), e);
7273
}
7374
}
7475
}

0 commit comments

Comments
 (0)