Skip to content

Commit

Permalink
Set up creatJwkException in exceptionUtils and apply that in JwtVendo…
Browse files Browse the repository at this point in the history
…r constructor

Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Aug 22, 2023
1 parent 0f0478d commit 034aa34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -48,11 +49,11 @@ public JwtVendor(final Settings settings, final Optional<LongSupplier> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down

0 comments on commit 034aa34

Please sign in to comment.