From 02a181ab79dc4868a42966524a32136e1c6db5a5 Mon Sep 17 00:00:00 2001 From: Sujith Vadakkepat Date: Mon, 1 Feb 2021 13:15:44 -0800 Subject: [PATCH] Cleanup single shard request index check (#993) --- .../resolver/IndexResolverReplacer.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/security/resolver/IndexResolverReplacer.java b/src/main/java/com/amazon/opendistroforelasticsearch/security/resolver/IndexResolverReplacer.java index 88354e99f9..990f259225 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/security/resolver/IndexResolverReplacer.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/security/resolver/IndexResolverReplacer.java @@ -647,25 +647,13 @@ private boolean getOrReplaceAllIndices(final Object request, final IndicesProvid } ((UpdateRequest) request).index(newIndices.length!=1?null:newIndices[0]); } else if (request instanceof SingleShardRequest) { - final SingleShardRequest gr = (SingleShardRequest) request; - final String[] indices = gr.indices(); - final String index = gr.index(); - - final List indicesL = new ArrayList(); - - if (index != null) { - indicesL.add(index); - } - - if (indices != null && indices.length > 0) { - indicesL.addAll(Arrays.asList(indices)); - } - - String[] newIndices = provider.provide(indicesL.toArray(new String[0]), request, true); - if (!checkIndices(request, newIndices, true, allowEmptyIndices)) { + final SingleShardRequest singleShardRequest = (SingleShardRequest) request; + final String index = singleShardRequest.index(); + String[] indices = provider.provide(index == null ? null : new String[]{index}, request, true); + if (!checkIndices(request, indices, true, allowEmptyIndices)) { return false; } - ((SingleShardRequest) request).index(newIndices.length!=1?null:newIndices[0]); + singleShardRequest.index(indices.length != 1? null : indices[0]); } else if (request instanceof FieldCapabilitiesIndexRequest) { // FieldCapabilitiesIndexRequest does not support replacing the indexes. // However, the indexes are always determined by FieldCapabilitiesRequest which will be reduced below