1313import java .util .ArrayList ;
1414import java .util .Arrays ;
1515import java .util .Collection ;
16+ import java .util .Collections ;
1617import java .util .HashMap ;
1718import java .util .List ;
1819import java .util .Map ;
2930import org .junit .runners .Parameterized ;
3031import org .junit .runners .Suite ;
3132
33+ import org .opensearch .action .OriginalIndices ;
3234import org .opensearch .action .support .IndicesOptions ;
3335import org .opensearch .cluster .metadata .IndexAbstraction ;
3436import org .opensearch .cluster .metadata .IndexMetadata ;
3537import org .opensearch .cluster .metadata .Metadata ;
38+ import org .opensearch .cluster .metadata .ResolvedIndices ;
3639import org .opensearch .common .settings .Settings ;
3740import org .opensearch .core .common .unit .ByteSizeUnit ;
3841import org .opensearch .core .common .unit .ByteSizeValue ;
3942import org .opensearch .security .privileges .PrivilegesEvaluationContext ;
4043import org .opensearch .security .privileges .PrivilegesEvaluatorResponse ;
41- import org .opensearch .security .resolver .IndexResolverReplacer ;
4244import org .opensearch .security .securityconf .FlattenedActionGroups ;
4345import org .opensearch .security .securityconf .impl .CType ;
4446import org .opensearch .security .securityconf .impl .SecurityDynamicConfiguration ;
@@ -352,13 +354,13 @@ public void positive_partial2() throws Exception {
352354
353355 @ Test
354356 public void positive_noLocal () throws Exception {
355- IndexResolverReplacer . Resolved resolved = new IndexResolverReplacer . Resolved (
356- ImmutableSet . of (),
357- ImmutableSet .of (),
358- ImmutableSet . of ( "remote:a" ) ,
359- ImmutableSet . of ( "remote:a" ),
360- IndicesOptions . LENIENT_EXPAND_OPEN
361- );
357+ ResolvedIndices resolved = ResolvedIndices . of ( Collections . emptySet ())
358+ . withRemoteIndices (
359+ Map .of (
360+ "remote" ,
361+ new OriginalIndices ( new String [] { "a" }, IndicesOptions . STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED )
362+ )
363+ );
362364 PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (
363365 ctx ().roles ("test_role" ).indexMetadata (INDEX_METADATA ).get (),
364366 requiredActions ,
@@ -481,14 +483,8 @@ public IndicesAndAliases(IndexSpec indexSpec, ActionSpec actionSpec, Statefulnes
481483 .of ("index_b1" , "index_b2" )//
482484 .build ();
483485
484- static IndexResolverReplacer .Resolved resolved (String ... indices ) {
485- return new IndexResolverReplacer .Resolved (
486- ImmutableSet .of (),
487- ImmutableSet .copyOf (indices ),
488- ImmutableSet .copyOf (indices ),
489- ImmutableSet .of (),
490- IndicesOptions .LENIENT_EXPAND_OPEN
491- );
486+ static ResolvedIndices resolved (String ... indices ) {
487+ return ResolvedIndices .of (indices );
492488 }
493489
494490 }
@@ -648,28 +644,24 @@ public DataStreams(IndexSpec indexSpec, ActionSpec actionSpec, Statefulness stat
648644 dataStreams ("data_stream_a11" , "data_stream_a12" , "data_stream_a21" , "data_stream_a22" , "data_stream_b1" , "data_stream_b2" )
649645 .build ();
650646
651- static IndexResolverReplacer .Resolved resolved (String ... indices ) {
652- ImmutableSet .Builder <String > allIndices = ImmutableSet .builder ();
653-
654- for (String index : indices ) {
655- IndexAbstraction indexAbstraction = INDEX_METADATA .getIndicesLookup ().get (index );
647+ static ResolvedIndices resolved (String ... indices ) {
648+ return ResolvedIndices .of (indices );
649+ // TODO check
650+ // ImmutableSet.Builder<String> allIndices = ImmutableSet.builder();
651+ //
652+ //
653+ // for (String index : indices) {
654+ // IndexAbstraction indexAbstraction = INDEX_METADATA.getIndicesLookup().get(index);
655+ //
656+ // if (indexAbstraction instanceof IndexAbstraction.DataStream) {
657+ // allIndices.addAll(
658+ // indexAbstraction.getIndices().stream().map(i -> i.getIndex().getName()).collect(Collectors.toList())
659+ // );
660+ // }
661+ //
662+ // allIndices.add(index);
663+ // }
656664
657- if (indexAbstraction instanceof IndexAbstraction .DataStream ) {
658- allIndices .addAll (
659- indexAbstraction .getIndices ().stream ().map (i -> i .getIndex ().getName ()).collect (Collectors .toList ())
660- );
661- }
662-
663- allIndices .add (index );
664- }
665-
666- return new IndexResolverReplacer .Resolved (
667- ImmutableSet .of (),
668- allIndices .build (),
669- ImmutableSet .copyOf (indices ),
670- ImmutableSet .of (),
671- IndicesOptions .LENIENT_EXPAND_OPEN
672- );
673665 }
674666 }
675667
@@ -871,7 +863,7 @@ public void hasIndexPrivilege_errors() throws Exception {
871863 PrivilegesEvaluatorResponse result = subject .hasIndexPrivilege (
872864 ctx ().roles ("role_with_errors" ).get (),
873865 Set .of ("indices:some_action" , "indices:data/write/index" ),
874- IndexResolverReplacer . Resolved . ofIndex ("any_index" )
866+ ResolvedIndices . of ("any_index" )
875867 );
876868 assertThat (result , isForbidden ());
877869 assertTrue (result .hasEvaluationExceptions ());
@@ -897,7 +889,7 @@ public void hasExplicitIndexPrivilege_positive() throws Exception {
897889 PrivilegesEvaluatorResponse result = subject .hasExplicitIndexPrivilege (
898890 ctx ().roles ("test_role" ).get (),
899891 Set .of ("system:admin/system_index" ),
900- IndexResolverReplacer . Resolved . ofIndex ("test_index" )
892+ ResolvedIndices . of ("test_index" )
901893 );
902894 assertThat (result , isAllowed ());
903895 }
@@ -917,7 +909,7 @@ public void hasExplicitIndexPrivilege_positive_wildcard() throws Exception {
917909 PrivilegesEvaluatorResponse result = subject .hasExplicitIndexPrivilege (
918910 ctx ().roles ("test_role" ).get (),
919911 Set .of ("system:admin/system_index" ),
920- IndexResolverReplacer . Resolved . ofIndex ("test_index" )
912+ ResolvedIndices . of ("test_index" )
921913 );
922914 assertThat (result , isAllowed ());
923915 }
@@ -934,7 +926,7 @@ public void hasExplicitIndexPrivilege_noWildcard() throws Exception {
934926 PrivilegesEvaluatorResponse result = subject .hasExplicitIndexPrivilege (
935927 ctx ().roles ("test_role" ).get (),
936928 Set .of ("system:admin/system_index" ),
937- IndexResolverReplacer . Resolved . ofIndex ("test_index" )
929+ ResolvedIndices . of ("test_index" )
938930 );
939931 assertThat (result , isForbidden ());
940932 }
@@ -954,7 +946,7 @@ public void hasExplicitIndexPrivilege_negative_wrongAction() throws Exception {
954946 PrivilegesEvaluatorResponse result = subject .hasExplicitIndexPrivilege (
955947 ctx ().roles ("test_role" ).get (),
956948 Set .of ("system:admin/system_foo" ),
957- IndexResolverReplacer . Resolved . ofIndex ("test_index" )
949+ ResolvedIndices . of ("test_index" )
958950 );
959951 assertThat (result , isForbidden ());
960952 }
@@ -974,7 +966,7 @@ public void hasExplicitIndexPrivilege_errors() throws Exception {
974966 PrivilegesEvaluatorResponse result = subject .hasExplicitIndexPrivilege (
975967 ctx ().roles ("role_with_errors" ).get (),
976968 Set .of ("system:admin/system_index" ),
977- IndexResolverReplacer . Resolved . ofIndex ("any_index" )
969+ ResolvedIndices . of ("any_index" )
978970 );
979971 assertThat (result , isForbidden ());
980972 assertTrue (result .hasEvaluationExceptions ());
@@ -1004,14 +996,14 @@ public void aliasesOnDataStreamBackingIndices() throws Exception {
1004996 PrivilegesEvaluatorResponse resultForIndexCoveredByAlias = subject .hasIndexPrivilege (
1005997 ctx ().roles ("role" ).indexMetadata (metadata ).get (),
1006998 Set .of ("indices:data/write/index" ),
1007- IndexResolverReplacer . Resolved . ofIndex (".ds-ds_a-000001" )
999+ ResolvedIndices . of (".ds-ds_a-000001" )
10081000 );
10091001 assertThat (resultForIndexCoveredByAlias , isAllowed ());
10101002
10111003 PrivilegesEvaluatorResponse resultForIndexNotCoveredByAlias = subject .hasIndexPrivilege (
10121004 ctx ().roles ("role" ).indexMetadata (metadata ).get (),
10131005 Set .of ("indices:data/write/index" ),
1014- IndexResolverReplacer . Resolved . ofIndex (".ds-ds_a-000002" )
1006+ ResolvedIndices . of (".ds-ds_a-000002" )
10151007 );
10161008 assertThat (resultForIndexNotCoveredByAlias , isForbidden ());
10171009 }
0 commit comments