From 3575d98dbfd3d3e746220b0069d1c4688c95568d Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Fri, 21 Apr 2023 12:15:33 -0400 Subject: [PATCH 1/6] remove immutable open map use Signed-off-by: Stephen Crawford --- .../test/framework/matcher/AliasExistsMatcher.java | 6 +++--- .../matcher/ClusterContainTemplateWithAliasMatcher.java | 7 ++++--- .../GetSettingsResponseContainsIndicesMatcher.java | 6 +++--- .../framework/matcher/IndexMappingIsEqualToMatcher.java | 5 ++--- .../framework/matcher/IndexStateIsEqualToMatcher.java | 4 ++-- .../security/privileges/PrivilegesEvaluator.java | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java index ef2ffb365b..48a84b1d0f 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -23,7 +24,6 @@ import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.AliasMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import static java.util.Objects.requireNonNull; import static java.util.Spliterator.IMMUTABLE; @@ -41,8 +41,8 @@ public AliasExistsMatcher(String aliasName) { protected boolean matchesSafely(Client client, Description mismatchDescription) { try { GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get(); - ImmutableOpenMap> aliases = response.getAliases(); - Set actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.valuesIt(), IMMUTABLE), false) + Map> aliases = response.getAliases(); + Set actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.values().iterator(), IMMUTABLE), false) .flatMap(Collection::stream) .map(AliasMetadata::getAlias) .collect(Collectors.toSet()); diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java index 907fb30257..26054392b5 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java @@ -9,6 +9,7 @@ */ package org.opensearch.test.framework.matcher; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -21,7 +22,6 @@ import org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.AliasMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import static java.util.Objects.requireNonNull; @@ -60,10 +60,11 @@ private Set getAliases(GetIndexTemplatesResponse response) { .collect(Collectors.toSet()); } - private Stream aliasNames(ImmutableOpenMap aliasMap) { - return StreamSupport.stream(aliasMap.keys().spliterator(), false).map(objectCursor -> objectCursor.value); + private Stream aliasNames(Map aliasMap) { + return aliasMap.keySet().stream().map(key -> aliasMap.get(key).getAlias()); } + @Override public void describeTo(Description description) { description.appendText("template ").appendValue(templateName).appendText(" exists and "); diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java index 15c558d32f..6b26d4ee49 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java @@ -9,11 +9,11 @@ */ package org.opensearch.test.framework.matcher; +import java.util.Map; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import static java.util.Objects.isNull; @@ -31,12 +31,12 @@ class GetSettingsResponseContainsIndicesMatcher extends TypeSafeDiagnosingMatche @Override protected boolean matchesSafely(GetSettingsResponse response, Description mismatchDescription) { - ImmutableOpenMap indexToSettings = response.getIndexToSettings(); + Map indexToSettings = response.getIndexToSettings(); for (String index : expectedIndices) { if (!indexToSettings.containsKey(index)) { mismatchDescription .appendText("Response contains settings of indices: ") - .appendValue(indexToSettings.keys()); + .appendValue(indexToSettings.keySet()); return false; } } diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java index 9621aff449..837befb7dd 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java @@ -18,7 +18,6 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.index.IndexNotFoundException; import org.opensearch.test.framework.cluster.LocalCluster; @@ -44,8 +43,8 @@ protected boolean matchesSafely(LocalCluster cluster, Description mismatchDescri GetMappingsResponse response = client.admin().indices() .getMappings(new GetMappingsRequest().indices(expectedIndexName)).actionGet(); - ImmutableOpenMap actualMappings = response.mappings(); - Map actualIndexMapping = actualMappings.get(expectedIndexName).getSourceAsMap(); + Map actualMappings = response.getMappings(); + Map actualIndexMapping = actualMappings.get(expectedIndexName).sourceAsMap(); if (!expectedMapping.equals(actualIndexMapping)) { mismatchDescription.appendText("Actual mapping ").appendValue(actualIndexMapping).appendText(" does not match expected"); diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java index a9538b4b8b..6aa6a0b1b0 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java @@ -9,6 +9,7 @@ */ package org.opensearch.test.framework.matcher; +import java.util.Map; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; @@ -16,7 +17,6 @@ import org.opensearch.action.admin.cluster.state.ClusterStateResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.test.framework.cluster.LocalCluster; import static java.util.Objects.requireNonNull; @@ -37,7 +37,7 @@ protected boolean matchesSafely(LocalCluster cluster, Description mismatchDescri ClusterStateRequest clusterStateRequest = new ClusterStateRequest().indices(expectedIndexName); ClusterStateResponse clusterStateResponse = client.admin().cluster().state(clusterStateRequest).actionGet(); - ImmutableOpenMap indicesMetadata = clusterStateResponse.getState().getMetadata().indices(); + Map indicesMetadata = clusterStateResponse.getState().getMetadata().indices(); if (!indicesMetadata.containsKey(expectedIndexName)) { mismatchDescription.appendValue("Index does not exist"); } diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java index 2c0e7ac7c0..5c8a5cd893 100644 --- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java +++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java @@ -78,7 +78,6 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.util.concurrent.ThreadContext; @@ -632,6 +631,7 @@ public static boolean isClusterPerm(String action0) { ) ; } + @SuppressWarnings("unchecked") private boolean checkFilteredAliases(Resolved requestedResolved, String action, boolean isDebugEnabled) { final String faMode = dcm.getFilteredAliasMode();// getConfigSettings().dynamic.filtered_alias_mode; @@ -649,7 +649,7 @@ private boolean checkFilteredAliases(Resolved requestedResolved, String action, indexMetaDataCollection = new Iterable() { @Override public Iterator iterator() { - return clusterService.state().getMetadata().getIndices().valuesIt(); + return (Iterator) clusterService.state().getMetadata().getIndices().values(); } }; } else { @@ -674,14 +674,14 @@ public Iterator iterator() { final List filteredAliases = new ArrayList(); - final ImmutableOpenMap aliases = indexMetaData.getAliases(); + final Map aliases = indexMetaData.getAliases(); if(aliases != null && aliases.size() > 0) { if (isDebugEnabled) { log.debug("Aliases for {}: {}", indexMetaData.getIndex().getName(), aliases); } - final Iterator it = aliases.keysIt(); + final Iterator it = aliases.keySet().iterator(); while(it.hasNext()) { final String alias = it.next(); final AliasMetadata aliasMetadata = aliases.get(alias); From cbfa1544da56fd81f0d725a6007e7b44df659fae Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Mon, 24 Apr 2023 11:44:12 -0400 Subject: [PATCH 2/6] Remove alias dependency Signed-off-by: Stephen Crawford --- .../test/framework/matcher/AliasExistsMatcher.java | 9 ++++++++- .../ClusterContainTemplateWithAliasMatcher.java | 14 ++++++++++++-- .../GetSettingsResponseContainsIndicesMatcher.java | 9 ++++++++- .../matcher/IndexStateIsEqualToMatcher.java | 1 + .../security/privileges/PrivilegesEvaluator.java | 9 ++++++--- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java index 48a84b1d0f..ee665ccbbe 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java @@ -10,6 +10,7 @@ package org.opensearch.test.framework.matcher; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -17,6 +18,7 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; @@ -41,7 +43,12 @@ public AliasExistsMatcher(String aliasName) { protected boolean matchesSafely(Client client, Description mismatchDescription) { try { GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get(); - Map> aliases = response.getAliases(); + + final Map> aliases = new HashMap<>(); + for (ObjectObjectCursor> cursor : response.getAliases()) { + aliases.put(cursor.key, cursor.value); + } + Set actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.values().iterator(), IMMUTABLE), false) .flatMap(Collection::stream) .map(AliasMetadata::getAlias) diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java index 26054392b5..d59792e715 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/ClusterContainTemplateWithAliasMatcher.java @@ -9,12 +9,14 @@ */ package org.opensearch.test.framework.matcher; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; @@ -55,13 +57,21 @@ protected boolean matchesSafely(Client client, Description mismatchDescription) private Set getAliases(GetIndexTemplatesResponse response) { return response.getIndexTemplates() .stream() - .map(metadata -> metadata.getAliases()) + .map(metadata -> { + Map aliases = new HashMap<>(); + for (ObjectObjectCursor cursor : metadata.getAliases()) { + aliases.put(cursor.key, cursor.value); + } + return aliases; + }) .flatMap(aliasMap -> aliasNames(aliasMap)) .collect(Collectors.toSet()); } private Stream aliasNames(Map aliasMap) { - return aliasMap.keySet().stream().map(key -> aliasMap.get(key).getAlias()); + Iterable> iterable = () -> aliasMap.entrySet().iterator(); + return StreamSupport.stream(iterable.spliterator(), false) + .map(entry -> entry.getValue().getAlias()); } diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java index 6b26d4ee49..79ac1c64ac 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/GetSettingsResponseContainsIndicesMatcher.java @@ -9,7 +9,10 @@ */ package org.opensearch.test.framework.matcher; +import java.util.HashMap; import java.util.Map; + +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; @@ -31,7 +34,11 @@ class GetSettingsResponseContainsIndicesMatcher extends TypeSafeDiagnosingMatche @Override protected boolean matchesSafely(GetSettingsResponse response, Description mismatchDescription) { - Map indexToSettings = response.getIndexToSettings(); + + final Map indexToSettings = new HashMap<>(); + for (ObjectObjectCursor cursor : response.getIndexToSettings()) { + indexToSettings.put(cursor.key, cursor.value); + } for (String index : expectedIndices) { if (!indexToSettings.containsKey(index)) { mismatchDescription diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java index 6aa6a0b1b0..ecff3fe2df 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexStateIsEqualToMatcher.java @@ -10,6 +10,7 @@ package org.opensearch.test.framework.matcher; import java.util.Map; + import org.hamcrest.Description; import org.hamcrest.TypeSafeDiagnosingMatcher; diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java index 5c8a5cd893..6eb7ff1a29 100644 --- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java +++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -37,6 +38,7 @@ import java.util.StringJoiner; import java.util.regex.Pattern; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import org.apache.logging.log4j.LogManager; @@ -377,8 +379,6 @@ public PrivilegesEvaluatorResponse evaluate(final User user, String action0, fin presponse.allowed = true; return presponse; } - - } } @@ -674,7 +674,10 @@ public Iterator iterator() { final List filteredAliases = new ArrayList(); - final Map aliases = indexMetaData.getAliases(); + final Map aliases = new HashMap<>(); + for (ObjectObjectCursor cursor : indexMetaData.getAliases()) { + aliases.put(cursor.key, cursor.value); + } if(aliases != null && aliases.size() > 0) { if (isDebugEnabled) { From d40f98b9cd8f66417c6bbc0b66e5acaf8c39520e Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Mon, 24 Apr 2023 14:29:30 -0400 Subject: [PATCH 3/6] Swap over AliasExistsMatcher Signed-off-by: Stephen Crawford --- .../test/framework/matcher/AliasExistsMatcher.java | 2 +- .../framework/matcher/IndexMappingIsEqualToMatcher.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java index ee665ccbbe..4999da8e95 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/AliasExistsMatcher.java @@ -60,7 +60,7 @@ protected boolean matchesSafely(Client client, Description mismatchDescription) } return true; } catch (InterruptedException | ExecutionException e) { - mismatchDescription.appendText("Error occured during checking if cluster contains alias ") + mismatchDescription.appendText("Error occurred during checking if cluster contains alias ") .appendValue(e); return false; } diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java index 837befb7dd..019adc44c1 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java @@ -9,6 +9,8 @@ */ package org.opensearch.test.framework.matcher; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import java.util.HashMap; import java.util.Map; import org.hamcrest.Description; @@ -18,6 +20,7 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.MappingMetadata; +import org.opensearch.common.settings.Settings; import org.opensearch.index.IndexNotFoundException; import org.opensearch.test.framework.cluster.LocalCluster; @@ -43,7 +46,11 @@ protected boolean matchesSafely(LocalCluster cluster, Description mismatchDescri GetMappingsResponse response = client.admin().indices() .getMappings(new GetMappingsRequest().indices(expectedIndexName)).actionGet(); - Map actualMappings = response.getMappings(); + Map actualMappings = new HashMap<>(); + for (ObjectObjectCursor cursor : response.getMappings()) { + actualMappings.put(cursor.key, cursor.value); + } + Map actualIndexMapping = actualMappings.get(expectedIndexName).sourceAsMap(); if (!expectedMapping.equals(actualIndexMapping)) { From cf6788d5078416ed62b79b9bd59070b746263937 Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Mon, 24 Apr 2023 14:44:44 -0400 Subject: [PATCH 4/6] Fix indexMappingIsEqual Signed-off-by: Stephen Crawford --- .../matcher/IndexMappingIsEqualToMatcher.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java index 019adc44c1..b90defef7d 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java +++ b/src/integrationTest/java/org/opensearch/test/framework/matcher/IndexMappingIsEqualToMatcher.java @@ -9,8 +9,6 @@ */ package org.opensearch.test.framework.matcher; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import java.util.HashMap; import java.util.Map; import org.hamcrest.Description; @@ -19,8 +17,6 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest; import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.opensearch.client.Client; -import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.settings.Settings; import org.opensearch.index.IndexNotFoundException; import org.opensearch.test.framework.cluster.LocalCluster; @@ -46,12 +42,7 @@ protected boolean matchesSafely(LocalCluster cluster, Description mismatchDescri GetMappingsResponse response = client.admin().indices() .getMappings(new GetMappingsRequest().indices(expectedIndexName)).actionGet(); - Map actualMappings = new HashMap<>(); - for (ObjectObjectCursor cursor : response.getMappings()) { - actualMappings.put(cursor.key, cursor.value); - } - - Map actualIndexMapping = actualMappings.get(expectedIndexName).sourceAsMap(); + Map actualIndexMapping = response.getMappings().get(expectedIndexName).sourceAsMap(); if (!expectedMapping.equals(actualIndexMapping)) { mismatchDescription.appendText("Actual mapping ").appendValue(actualIndexMapping).appendText(" does not match expected"); From 2b6774b1c580e862244a34e04473981661aa850a Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Mon, 24 Apr 2023 16:11:48 -0400 Subject: [PATCH 5/6] Try to fix privEval iterator Signed-off-by: Stephen Crawford --- .../privileges/PrivilegesEvaluator.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java index 6eb7ff1a29..5a796f3129 100644 --- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java +++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java @@ -26,6 +26,7 @@ package org.opensearch.security.privileges; +import com.carrotsearch.hppc.cursors.ObjectCursor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -649,7 +650,23 @@ private boolean checkFilteredAliases(Resolved requestedResolved, String action, indexMetaDataCollection = new Iterable() { @Override public Iterator iterator() { - return (Iterator) clusterService.state().getMetadata().getIndices().values(); + final Iterator> iterator = clusterService.state().getMetadata().getIndices().values().iterator(); + return new Iterator() { + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public IndexMetadata next() { + return iterator.next().value; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; } }; } else { From 876871eb1f392cd800d82409f776a9afa8dc79ba Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Mon, 24 Apr 2023 16:22:55 -0400 Subject: [PATCH 6/6] Update iterator Signed-off-by: Stephen Crawford --- .../privileges/PrivilegesEvaluator.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java index 5a796f3129..b77b7a000f 100644 --- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java +++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java @@ -26,7 +26,6 @@ package org.opensearch.security.privileges; -import com.carrotsearch.hppc.cursors.ObjectCursor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -650,23 +649,7 @@ private boolean checkFilteredAliases(Resolved requestedResolved, String action, indexMetaDataCollection = new Iterable() { @Override public Iterator iterator() { - final Iterator> iterator = clusterService.state().getMetadata().getIndices().values().iterator(); - return new Iterator() { - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public IndexMetadata next() { - return iterator.next().value; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; + return clusterService.state().getMetadata().getIndices().values().iterator(); } }; } else {