[Rename] ElasticsearchSecurityException class in server module (#170)

This commit refactors ElasticsearchSecurityException class in the server module
to OpenSearchSecurityException. References and usages throughout the rest of the
codebase are fully refactored.

Signed-off-by: Nicholas Knize <nknize@amazon.com>
This commit is contained in:
Nick Knize 2021-03-03 16:44:34 -06:00
parent ff9fd6c91f
commit 1015c8e609
5 changed files with 18 additions and 18 deletions

View File

@ -20,7 +20,7 @@
package org.elasticsearch.index.reindex; package org.elasticsearch.index.reindex;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.OpenSearchSecurityException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
@ -208,13 +208,13 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
} }
String auth = context.getHeader(AUTHORIZATION_HEADER); String auth = context.getHeader(AUTHORIZATION_HEADER);
if (auth == null) { if (auth == null) {
ElasticsearchSecurityException e = new ElasticsearchSecurityException("Authentication required", OpenSearchSecurityException e = new OpenSearchSecurityException("Authentication required",
RestStatus.UNAUTHORIZED); RestStatus.UNAUTHORIZED);
e.addHeader("WWW-Authenticate", "Basic realm=auth-realm"); e.addHeader("WWW-Authenticate", "Basic realm=auth-realm");
throw e; throw e;
} }
if (false == REQUIRED_AUTH.equals(auth)) { if (false == REQUIRED_AUTH.equals(auth)) {
throw new ElasticsearchSecurityException("Bad Authorization", RestStatus.FORBIDDEN); throw new OpenSearchSecurityException("Bad Authorization", RestStatus.FORBIDDEN);
} }
chain.proceed(task, action, request, listener); chain.proceed(task, action, request, listener);
} }

View File

@ -740,8 +740,8 @@ public class OpenSearchException extends RuntimeException implements ToXContentF
org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, UNKNOWN_VERSION_ADDED), org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, UNKNOWN_VERSION_ADDED),
MASTER_NOT_DISCOVERED_EXCEPTION(org.elasticsearch.discovery.MasterNotDiscoveredException.class, MASTER_NOT_DISCOVERED_EXCEPTION(org.elasticsearch.discovery.MasterNotDiscoveredException.class,
org.elasticsearch.discovery.MasterNotDiscoveredException::new, 3, UNKNOWN_VERSION_ADDED), org.elasticsearch.discovery.MasterNotDiscoveredException::new, 3, UNKNOWN_VERSION_ADDED),
ELASTICSEARCH_SECURITY_EXCEPTION(org.elasticsearch.ElasticsearchSecurityException.class, ELASTICSEARCH_SECURITY_EXCEPTION(org.elasticsearch.OpenSearchSecurityException.class,
org.elasticsearch.ElasticsearchSecurityException::new, 4, UNKNOWN_VERSION_ADDED), org.elasticsearch.OpenSearchSecurityException::new, 4, UNKNOWN_VERSION_ADDED),
INDEX_SHARD_RESTORE_EXCEPTION(org.elasticsearch.index.snapshots.IndexShardRestoreException.class, INDEX_SHARD_RESTORE_EXCEPTION(org.elasticsearch.index.snapshots.IndexShardRestoreException.class,
org.elasticsearch.index.snapshots.IndexShardRestoreException::new, 5, UNKNOWN_VERSION_ADDED), org.elasticsearch.index.snapshots.IndexShardRestoreException::new, 5, UNKNOWN_VERSION_ADDED),
INDEX_CLOSED_EXCEPTION(org.elasticsearch.indices.IndexClosedException.class, INDEX_CLOSED_EXCEPTION(org.elasticsearch.indices.IndexClosedException.class,

View File

@ -26,39 +26,39 @@ import java.io.IOException;
/** /**
* Generic security exception * Generic security exception
*/ */
public class ElasticsearchSecurityException extends ElasticsearchStatusException { public class OpenSearchSecurityException extends ElasticsearchStatusException {
/** /**
* Build the exception with a specific status and cause. * Build the exception with a specific status and cause.
*/ */
public ElasticsearchSecurityException(String msg, RestStatus status, Throwable cause, Object... args) { public OpenSearchSecurityException(String msg, RestStatus status, Throwable cause, Object... args) {
super(msg, status, cause, args); super(msg, status, cause, args);
} }
/** /**
* Build the exception with the status derived from the cause. * Build the exception with the status derived from the cause.
*/ */
public ElasticsearchSecurityException(String msg, Exception cause, Object... args) { public OpenSearchSecurityException(String msg, Exception cause, Object... args) {
this(msg, ExceptionsHelper.status(cause), cause, args); this(msg, ExceptionsHelper.status(cause), cause, args);
} }
/** /**
* Build the exception with a status of {@link RestStatus#INTERNAL_SERVER_ERROR} without a cause. * Build the exception with a status of {@link RestStatus#INTERNAL_SERVER_ERROR} without a cause.
*/ */
public ElasticsearchSecurityException(String msg, Object... args) { public OpenSearchSecurityException(String msg, Object... args) {
this(msg, RestStatus.INTERNAL_SERVER_ERROR, args); this(msg, RestStatus.INTERNAL_SERVER_ERROR, args);
} }
/** /**
* Build the exception without a cause. * Build the exception without a cause.
*/ */
public ElasticsearchSecurityException(String msg, RestStatus status, Object... args) { public OpenSearchSecurityException(String msg, RestStatus status, Object... args) {
super(msg, status, args); super(msg, status, args);
} }
/** /**
* Read from a stream. * Read from a stream.
*/ */
public ElasticsearchSecurityException(StreamInput in) throws IOException { public OpenSearchSecurityException(StreamInput in) throws IOException {
super(in); super(in);
} }
} }

View File

@ -21,7 +21,7 @@ package org.elasticsearch.tasks;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.OpenSearchSecurityException;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -124,7 +124,7 @@ public class TaskCancellationService {
@Override @Override
public void handleException(TransportException exp) { public void handleException(TransportException exp) {
assert ExceptionsHelper.unwrapCause(exp) instanceof ElasticsearchSecurityException == false; assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false;
logger.warn("Cannot send ban for tasks with the parent [{}] to the node [{}]", taskId, node); logger.warn("Cannot send ban for tasks with the parent [{}] to the node [{}]", taskId, node);
groupedListener.onFailure(exp); groupedListener.onFailure(exp);
} }
@ -140,7 +140,7 @@ public class TaskCancellationService {
transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
@Override @Override
public void handleException(TransportException exp) { public void handleException(TransportException exp) {
assert ExceptionsHelper.unwrapCause(exp) instanceof ElasticsearchSecurityException == false; assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false;
logger.info("failed to remove the parent ban for task {} on node {}", request.parentTaskId, node); logger.info("failed to remove the parent ban for task {} on node {}", request.parentTaskId, node);
} }
}); });

View File

@ -559,7 +559,7 @@ public class ExceptionSerializationTests extends ESTestCase {
new IllegalArgumentException("alalaal"), new IllegalArgumentException("alalaal"),
new NullPointerException("boom"), new NullPointerException("boom"),
new EOFException("dadada"), new EOFException("dadada"),
new ElasticsearchSecurityException("nono!"), new OpenSearchSecurityException("nono!"),
new NumberFormatException("not a number"), new NumberFormatException("not a number"),
new CorruptIndexException("baaaam booom", "this is my resource"), new CorruptIndexException("baaaam booom", "this is my resource"),
new IndexFormatTooNewException("tooo new", 1, 2, 3), new IndexFormatTooNewException("tooo new", 1, 2, 3),
@ -647,8 +647,8 @@ public class ExceptionSerializationTests extends ESTestCase {
} }
public void testElasticsearchSecurityException() throws IOException { public void testElasticsearchSecurityException() throws IOException {
ElasticsearchSecurityException ex = new ElasticsearchSecurityException("user [{}] is not allowed", RestStatus.UNAUTHORIZED, "foo"); OpenSearchSecurityException ex = new OpenSearchSecurityException("user [{}] is not allowed", RestStatus.UNAUTHORIZED, "foo");
ElasticsearchSecurityException e = serialize(ex); OpenSearchSecurityException e = serialize(ex);
assertEquals(ex.status(), e.status()); assertEquals(ex.status(), e.status());
assertEquals(RestStatus.UNAUTHORIZED, e.status()); assertEquals(RestStatus.UNAUTHORIZED, e.status());
} }
@ -678,7 +678,7 @@ public class ExceptionSerializationTests extends ESTestCase {
ids.put(1, org.elasticsearch.search.dfs.DfsPhaseExecutionException.class); ids.put(1, org.elasticsearch.search.dfs.DfsPhaseExecutionException.class);
ids.put(2, org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class); ids.put(2, org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class);
ids.put(3, org.elasticsearch.discovery.MasterNotDiscoveredException.class); ids.put(3, org.elasticsearch.discovery.MasterNotDiscoveredException.class);
ids.put(4, org.elasticsearch.ElasticsearchSecurityException.class); ids.put(4, org.elasticsearch.OpenSearchSecurityException.class);
ids.put(5, org.elasticsearch.index.snapshots.IndexShardRestoreException.class); ids.put(5, org.elasticsearch.index.snapshots.IndexShardRestoreException.class);
ids.put(6, org.elasticsearch.indices.IndexClosedException.class); ids.put(6, org.elasticsearch.indices.IndexClosedException.class);
ids.put(7, org.elasticsearch.http.BindHttpException.class); ids.put(7, org.elasticsearch.http.BindHttpException.class);