|
47 | 47 | import org.elasticsearch.common.transport.TransportAddress; |
48 | 48 |
|
49 | 49 | import com.amazon.opendistroforelasticsearch.security.resolver.IndexResolverReplacer.Resolved; |
50 | | -import com.amazon.opendistroforelasticsearch.security.securityconf.ConfigModelV6.SecurityRole; |
51 | 50 | import com.amazon.opendistroforelasticsearch.security.securityconf.impl.SecurityDynamicConfiguration; |
52 | 51 | import com.amazon.opendistroforelasticsearch.security.securityconf.impl.v7.ActionGroupsV7; |
53 | 52 | import com.amazon.opendistroforelasticsearch.security.securityconf.impl.v7.RoleMappingsV7; |
@@ -936,38 +935,35 @@ private static String toQuotedCommaSeparatedString(final Set<String> roles) { |
936 | 935 | })); |
937 | 936 | } |
938 | 937 |
|
939 | | - private static boolean impliesTypePerm(Set<IndexPattern> ipatterns, Resolved resolved, User user, String[] actions, |
940 | | - IndexNameExpressionResolver resolver, ClusterService cs) { |
941 | | - Set<String> matchingIndex = new HashSet<>(resolved.getAllIndices()); |
942 | | - |
943 | | - for (String in : resolved.getAllIndices()) { |
944 | | - //find index patterns who are matching |
945 | | - Set<String> matchingActions = new HashSet<>(Arrays.asList(actions)); |
946 | | - //Set<String> matchingTypes = new HashSet<>(resolved.getTypes(-)); |
947 | | - for (IndexPattern p : ipatterns) { |
948 | | - if (WildcardMatcher.matchAny(p.getResolvedIndexPattern(user, resolver, cs), in)) { |
949 | | - //per resolved index per pattern |
950 | | - //for (String t : resolved.getTypes(-)) { |
951 | | - //for (TypePerm tp : p.typePerms) { |
952 | | - //if (WildcardMatcher.match(tp.typePattern, t)) { |
953 | | - //matchingTypes.remove(t); |
954 | | - for (String a : Arrays.asList(actions)) { |
955 | | - if (WildcardMatcher.matchAny(p.perms, a)) { |
956 | | - matchingActions.remove(a); |
957 | | - } |
958 | | - } |
959 | | - //} |
960 | | - //} |
961 | | - //} |
962 | | - } |
963 | | - } |
| 938 | + private static final class IndexPatternsAndPermissions { |
| 939 | + private String[] pattern; |
| 940 | + private Set<String> perms; |
| 941 | + public IndexPatternsAndPermissions(String[] pattern, Set<String> perms) { |
| 942 | + this.pattern = pattern; |
| 943 | + this.perms = perms; |
| 944 | + } |
964 | 945 |
|
965 | | - if (matchingActions.isEmpty() /*&& matchingTypes.isEmpty()*/) { |
966 | | - matchingIndex.remove(in); |
967 | | - } |
| 946 | + public boolean matches(String index, String action) { |
| 947 | + return WildcardMatcher.matchAny(pattern, index) && WildcardMatcher.matchAny(perms, action); |
968 | 948 | } |
| 949 | + } |
969 | 950 |
|
970 | | - return matchingIndex.isEmpty(); |
| 951 | + private static boolean impliesTypePerm(Set<IndexPattern> ipatterns, Resolved resolved, User user, String[] requestedActions, |
| 952 | + IndexNameExpressionResolver resolver, ClusterService cs) { |
| 953 | + Set<String> resolvedRequestedIndices = resolved.getAllIndices(); |
| 954 | + IndexPatternsAndPermissions[] indexPatternsAndPermissions = ipatterns |
| 955 | + .stream() |
| 956 | + .map(p -> new IndexPatternsAndPermissions(p.getResolvedIndexPattern(user, resolver, cs), p.perms)) |
| 957 | + .toArray(IndexPatternsAndPermissions[]::new); |
| 958 | + return resolvedRequestedIndices |
| 959 | + .stream() |
| 960 | + .allMatch(index -> |
| 961 | + Arrays.stream(requestedActions).allMatch(action -> |
| 962 | + Arrays.stream(indexPatternsAndPermissions).anyMatch(ipap -> |
| 963 | + ipap.matches(index, action) |
| 964 | + ) |
| 965 | + ) |
| 966 | + ); |
971 | 967 | } |
972 | 968 |
|
973 | 969 |
|
|
0 commit comments