diff --git a/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java b/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java index 457540c361..ec096ea117 100644 --- a/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java +++ b/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java @@ -30,6 +30,7 @@ import org.apache.logging.log4j.Logger; import org.opensearch.common.settings.Settings; +import org.opensearch.security.ssl.util.ExceptionUtils; import org.opensearch.security.support.ConfigConstants; public class JwtVendor { @@ -48,11 +49,11 @@ public JwtVendor(final Settings settings, final Optional timeProvi try { this.signingKey = createJwkFromSettings(settings); } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.createJwkCreationException(e); } this.jwtProducer = jwtProducer; if (settings.get("encryption_key") == null) { - throw new RuntimeException("encryption_key cannot be null"); + throw new IllegalArgumentException("encryption_key cannot be null"); } else { this.claimsEncryptionKey = settings.get("encryption_key"); } diff --git a/src/main/java/org/opensearch/security/ssl/util/ExceptionUtils.java b/src/main/java/org/opensearch/security/ssl/util/ExceptionUtils.java index 81fc4d7fe3..83982239f0 100644 --- a/src/main/java/org/opensearch/security/ssl/util/ExceptionUtils.java +++ b/src/main/java/org/opensearch/security/ssl/util/ExceptionUtils.java @@ -68,6 +68,14 @@ public static OpenSearchException invalidUsageOfOBOTokenException() { return new OpenSearchException("On-Behalf-Of Token is not allowed to be used for accessing this endpoint."); } + public static OpenSearchException createJwkCreationException() { + return new OpenSearchException("An error occurred during the creation of Jwk."); + } + + public static OpenSearchException createJwkCreationException(Throwable cause) { + return new OpenSearchException("An error occurred during the creation of Jwk: {}", cause, cause.getMessage()); + } + public static OpenSearchException createTransportClientNoLongerSupportedException() { return new OpenSearchException("Transport client authentication no longer supported."); }