From 1015c8e609ba2dc511c2f4a99d73add69d121df8 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Wed, 3 Mar 2021 16:44:34 -0600 Subject: [PATCH] [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 --- .../reindex/ReindexFromRemoteWithAuthTests.java | 6 +++--- .../java/org/elasticsearch/OpenSearchException.java | 4 ++-- ...ception.java => OpenSearchSecurityException.java} | 12 ++++++------ .../elasticsearch/tasks/TaskCancellationService.java | 6 +++--- .../elasticsearch/ExceptionSerializationTests.java | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) rename server/src/main/java/org/elasticsearch/{ElasticsearchSecurityException.java => OpenSearchSecurityException.java} (75%) diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java index 74033cda742aa..585809a744498 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFromRemoteWithAuthTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.reindex; import org.apache.lucene.util.SetOnce; -import org.elasticsearch.ElasticsearchSecurityException; +import org.elasticsearch.OpenSearchSecurityException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; @@ -208,13 +208,13 @@ public void app } String auth = context.getHeader(AUTHORIZATION_HEADER); if (auth == null) { - ElasticsearchSecurityException e = new ElasticsearchSecurityException("Authentication required", + OpenSearchSecurityException e = new OpenSearchSecurityException("Authentication required", RestStatus.UNAUTHORIZED); e.addHeader("WWW-Authenticate", "Basic realm=auth-realm"); throw e; } 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); } diff --git a/server/src/main/java/org/elasticsearch/OpenSearchException.java b/server/src/main/java/org/elasticsearch/OpenSearchException.java index e2fa896de3ebc..1be5877b609ae 100644 --- a/server/src/main/java/org/elasticsearch/OpenSearchException.java +++ b/server/src/main/java/org/elasticsearch/OpenSearchException.java @@ -740,8 +740,8 @@ private enum OpenSearchExceptionHandle { org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException::new, 2, UNKNOWN_VERSION_ADDED), MASTER_NOT_DISCOVERED_EXCEPTION(org.elasticsearch.discovery.MasterNotDiscoveredException.class, org.elasticsearch.discovery.MasterNotDiscoveredException::new, 3, UNKNOWN_VERSION_ADDED), - ELASTICSEARCH_SECURITY_EXCEPTION(org.elasticsearch.ElasticsearchSecurityException.class, - org.elasticsearch.ElasticsearchSecurityException::new, 4, UNKNOWN_VERSION_ADDED), + ELASTICSEARCH_SECURITY_EXCEPTION(org.elasticsearch.OpenSearchSecurityException.class, + org.elasticsearch.OpenSearchSecurityException::new, 4, UNKNOWN_VERSION_ADDED), INDEX_SHARD_RESTORE_EXCEPTION(org.elasticsearch.index.snapshots.IndexShardRestoreException.class, org.elasticsearch.index.snapshots.IndexShardRestoreException::new, 5, UNKNOWN_VERSION_ADDED), INDEX_CLOSED_EXCEPTION(org.elasticsearch.indices.IndexClosedException.class, diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchSecurityException.java b/server/src/main/java/org/elasticsearch/OpenSearchSecurityException.java similarity index 75% rename from server/src/main/java/org/elasticsearch/ElasticsearchSecurityException.java rename to server/src/main/java/org/elasticsearch/OpenSearchSecurityException.java index 0cf5fb474e0e0..b8708a23c717c 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchSecurityException.java +++ b/server/src/main/java/org/elasticsearch/OpenSearchSecurityException.java @@ -26,39 +26,39 @@ /** * Generic security exception */ -public class ElasticsearchSecurityException extends ElasticsearchStatusException { +public class OpenSearchSecurityException extends ElasticsearchStatusException { /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** * Read from a stream. */ - public ElasticsearchSecurityException(StreamInput in) throws IOException { + public OpenSearchSecurityException(StreamInput in) throws IOException { super(in); } } diff --git a/server/src/main/java/org/elasticsearch/tasks/TaskCancellationService.java b/server/src/main/java/org/elasticsearch/tasks/TaskCancellationService.java index 6ab511d3de3fa..69dbc9916dae8 100644 --- a/server/src/main/java/org/elasticsearch/tasks/TaskCancellationService.java +++ b/server/src/main/java/org/elasticsearch/tasks/TaskCancellationService.java @@ -21,7 +21,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.ElasticsearchSecurityException; +import org.elasticsearch.OpenSearchSecurityException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -124,7 +124,7 @@ public void handleResponse(TransportResponse.Empty response) { @Override 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); groupedListener.onFailure(exp); } @@ -140,7 +140,7 @@ private void removeBanOnNodes(CancellableTask task, Collection ch transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) { @Override 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); } }); diff --git a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 9baae64937a7f..ad15af168e4c4 100644 --- a/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -559,7 +559,7 @@ public void testWriteThrowable() throws IOException { new IllegalArgumentException("alalaal"), new NullPointerException("boom"), new EOFException("dadada"), - new ElasticsearchSecurityException("nono!"), + new OpenSearchSecurityException("nono!"), new NumberFormatException("not a number"), new CorruptIndexException("baaaam booom", "this is my resource"), new IndexFormatTooNewException("tooo new", 1, 2, 3), @@ -647,8 +647,8 @@ public RestStatus status() { } public void testElasticsearchSecurityException() throws IOException { - ElasticsearchSecurityException ex = new ElasticsearchSecurityException("user [{}] is not allowed", RestStatus.UNAUTHORIZED, "foo"); - ElasticsearchSecurityException e = serialize(ex); + OpenSearchSecurityException ex = new OpenSearchSecurityException("user [{}] is not allowed", RestStatus.UNAUTHORIZED, "foo"); + OpenSearchSecurityException e = serialize(ex); assertEquals(ex.status(), e.status()); assertEquals(RestStatus.UNAUTHORIZED, e.status()); } @@ -678,7 +678,7 @@ public void testIds() { ids.put(1, org.elasticsearch.search.dfs.DfsPhaseExecutionException.class); ids.put(2, org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.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(6, org.elasticsearch.indices.IndexClosedException.class); ids.put(7, org.elasticsearch.http.BindHttpException.class);