@@ -696,28 +696,30 @@ static class StatefulIndexPrivileges extends RuntimeOptimizedActionPrivileges.St
696696 continue ;
697697 }
698698
699+ List <IndexAbstraction > matchingIndices = indexMatcher .matching (indices .values (), IndexAbstraction ::getName );
700+ if (matchingIndices .isEmpty ()) {
701+ continue ;
702+ }
703+
699704 for (String permission : permissions ) {
700705 WildcardMatcher actionMatcher = WildcardMatcher .from (permission );
701706 Collection <String > matchedActions = actionMatcher .getMatchAny (
702707 WellKnownActions .INDEX_ACTIONS ,
703708 Collectors .toList ()
704709 );
705710
706- for (Map .Entry <String , IndexAbstraction > indicesEntry : indexMatcher .iterateMatching (
707- indices .entrySet (),
708- Map .Entry ::getKey
709- )) {
711+ for (IndexAbstraction index : matchingIndices ) {
710712 for (String action : matchedActions ) {
711713 CompactMapGroupBuilder .MapBuilder <
712714 String ,
713715 DeduplicatingCompactSubSetBuilder .SubSetBuilder <String >> indexToRoles = actionToIndexToRoles
714716 .computeIfAbsent (action , k -> indexMapBuilder .createMapBuilder ());
715717
716- indexToRoles .get (indicesEntry . getKey ()).add (roleName );
718+ indexToRoles .get (index . getName ()).add (roleName );
717719
718- if (indicesEntry . getValue () instanceof IndexAbstraction .Alias ) {
720+ if (index instanceof IndexAbstraction .Alias ) {
719721 // For aliases we additionally add the sub-indices to the privilege map
720- for (IndexMetadata subIndex : indicesEntry . getValue () .getIndices ()) {
722+ for (IndexMetadata subIndex : index .getIndices ()) {
721723 String subIndexName = subIndex .getIndex ().getName ();
722724 // We need to check whether the subIndex is part of the global indices
723725 // metadata map because that map has been filtered by relevantOnly().
@@ -732,7 +734,7 @@ static class StatefulIndexPrivileges extends RuntimeOptimizedActionPrivileges.St
732734 log .debug (
733735 "Ignoring member index {} of alias {}. This is usually the case because the index is closed or a data stream backing index." ,
734736 subIndexName ,
735- indicesEntry . getKey ()
737+ index . getName ()
736738 );
737739 }
738740 }
0 commit comments