Skip to content

Commit 5922f1f

Browse files
committed
Javadoc and renames
1 parent 253f6ab commit 5922f1f

File tree

16 files changed

+207
-132
lines changed

16 files changed

+207
-132
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/RoleDescriptorRequestValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
1212
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilege;
1313
import org.elasticsearch.xpack.core.security.authz.privilege.ClusterPrivilegeResolver;
14-
import org.elasticsearch.xpack.core.security.authz.privilege.IndexComponentSelectorPrivilege;
14+
import org.elasticsearch.xpack.core.security.authz.privilege.IndexComponentSelectorPredicate;
1515
import org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege;
1616
import org.elasticsearch.xpack.core.security.authz.restriction.WorkflowResolver;
1717
import org.elasticsearch.xpack.core.security.support.MetadataUtils;
@@ -49,7 +49,7 @@ public static ActionRequestValidationException validate(
4949
if (roleDescriptor.getIndicesPrivileges() != null) {
5050
for (RoleDescriptor.IndicesPrivileges idp : roleDescriptor.getIndicesPrivileges()) {
5151
try {
52-
IndexPrivilege.getSplitBySelector(Set.of(idp.getPrivileges()));
52+
IndexPrivilege.getSplitBySelectorAccess(Set.of(idp.getPrivileges()));
5353
} catch (IllegalArgumentException ile) {
5454
validationException = addValidationError(ile.getMessage(), validationException);
5555
}
@@ -61,8 +61,8 @@ public static ActionRequestValidationException validate(
6161
validationException = addValidationError("remote index cluster alias cannot be an empty string", validationException);
6262
}
6363
try {
64-
var privileges = IndexPrivilege.getSplitBySelector(Set.of(ridp.indicesPrivileges().getPrivileges()));
65-
if (privileges.stream().anyMatch(p -> p.getSelectorPrivilege() == IndexComponentSelectorPrivilege.FAILURES)) {
64+
var privileges = IndexPrivilege.getSplitBySelectorAccess(Set.of(ridp.indicesPrivileges().getPrivileges()));
65+
if (privileges.stream().anyMatch(p -> p.getSelectorPredicate() == IndexComponentSelectorPredicate.FAILURES)) {
6666
validationException = addValidationError(
6767
"remote index privileges cannot contain privileges that grant access to the failure store",
6868
validationException

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.elasticsearch.index.Index;
2828
import org.elasticsearch.xpack.core.security.authz.RestrictedIndices;
2929
import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl;
30-
import org.elasticsearch.xpack.core.security.authz.privilege.IndexComponentSelectorPrivilege;
30+
import org.elasticsearch.xpack.core.security.authz.privilege.IndexComponentSelectorPredicate;
3131
import org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege;
3232
import org.elasticsearch.xpack.core.security.support.Automatons;
3333
import org.elasticsearch.xpack.core.security.support.StringMatcher;
@@ -302,7 +302,7 @@ public boolean checkResourcePrivileges(
302302
}
303303
}
304304
for (String privilege : checkForPrivileges) {
305-
IndexPrivilege indexPrivilege = IndexPrivilege.getSingleSelector(Collections.singleton(privilege));
305+
IndexPrivilege indexPrivilege = IndexPrivilege.getSingleSelectorOrThrow(Collections.singleton(privilege));
306306
if (allowedIndexPrivilegesAutomaton != null
307307
&& Automatons.subsetOf(indexPrivilege.getAutomaton(), allowedIndexPrivilegesAutomaton)) {
308308
if (resourcePrivilegesMapBuilder != null) {
@@ -793,7 +793,7 @@ public static class Group {
793793
public static final Group[] EMPTY_ARRAY = new Group[0];
794794

795795
private final IndexPrivilege privilege;
796-
private final IndexComponentSelectorPrivilege selectorPrivilege;
796+
private final IndexComponentSelectorPredicate selectorPredicate;
797797
private final Predicate<String> actionMatcher;
798798
private final String[] indices;
799799
private final StringMatcher indexNameMatcher;
@@ -817,7 +817,7 @@ public Group(
817817
assert indices.length != 0;
818818
this.privilege = privilege;
819819
this.actionMatcher = privilege.predicate();
820-
this.selectorPrivilege = privilege.getSelectorPrivilege();
820+
this.selectorPredicate = privilege.getSelectorPredicate();
821821
this.indices = indices;
822822
this.allowRestrictedIndices = allowRestrictedIndices;
823823
ConcurrentHashMap<String[], Automaton> indexNameAutomatonMemo = new ConcurrentHashMap<>(1);
@@ -866,7 +866,7 @@ boolean hasQuery() {
866866
}
867867

868868
public boolean checkSelector(IndexComponentSelector selector) {
869-
return selectorPrivilege.test(selector);
869+
return selectorPredicate.test(selector);
870870
}
871871

872872
public boolean allowRestrictedIndices() {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/Role.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static SimpleRole buildFromRoleDescriptor(
437437
new FieldPermissionsDefinition(indexPrivilege.getGrantedFields(), indexPrivilege.getDeniedFields())
438438
),
439439
indexPrivilege.getQuery() == null ? null : Collections.singleton(indexPrivilege.getQuery()),
440-
IndexPrivilege.getSplitBySelector(Set.of(indexPrivilege.getPrivileges())),
440+
IndexPrivilege.getSplitBySelectorAccess(Set.of(indexPrivilege.getPrivileges())),
441441
indexPrivilege.allowRestrictedIndices(),
442442
indexPrivilege.getIndices()
443443
);
@@ -454,7 +454,7 @@ static SimpleRole buildFromRoleDescriptor(
454454
new FieldPermissionsDefinition(indicesPrivileges.getGrantedFields(), indicesPrivileges.getDeniedFields())
455455
),
456456
indicesPrivileges.getQuery() == null ? null : Collections.singleton(indicesPrivileges.getQuery()),
457-
IndexPrivilege.getSplitBySelector(Set.of(indicesPrivileges.getPrivileges())),
457+
IndexPrivilege.getSplitBySelectorAccess(Set.of(indicesPrivileges.getPrivileges())),
458458
indicesPrivileges.allowRestrictedIndices(),
459459
indicesPrivileges.getIndices()
460460
);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivileges.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ public ManageRolesPrivilege(List<ManageRolesIndexPermissionGroup> manageRolesInd
414414
this.requestPredicateSupplier = (restrictedIndices) -> {
415415
IndicesPermission.Builder indicesPermissionBuilder = new IndicesPermission.Builder(restrictedIndices);
416416
for (ManageRolesIndexPermissionGroup indexPatternPrivilege : manageRolesIndexPermissionGroups) {
417-
Set<IndexPrivilege> splitBySelector = IndexPrivilege.getSplitBySelector(Set.of(indexPatternPrivilege.privileges()));
417+
Set<IndexPrivilege> splitBySelector = IndexPrivilege.getSplitBySelectorAccess(
418+
Set.of(indexPatternPrivilege.privileges())
419+
);
418420
for (IndexPrivilege indexPrivilege : splitBySelector) {
419421
indicesPermissionBuilder.addGroup(
420422
indexPrivilege,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexComponentSelectorPrivilege.java renamed to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexComponentSelectorPredicate.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@
1313
import java.util.Set;
1414
import java.util.function.Predicate;
1515

16-
public record IndexComponentSelectorPrivilege(Set<String> names, Predicate<IndexComponentSelector> predicate)
16+
/**
17+
* A predicate to capture role access by {@link IndexComponentSelector}.
18+
* This is assigned to each {@link org.elasticsearch.xpack.core.security.authz.permission.IndicesPermission.Group} during role building.
19+
* See also {@link org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege#getSplitBySelectorAccess(Set)}.
20+
*/
21+
public record IndexComponentSelectorPredicate(Set<String> names, Predicate<IndexComponentSelector> predicate)
1722
implements
1823
Predicate<IndexComponentSelector> {
19-
IndexComponentSelectorPrivilege(String name, Predicate<IndexComponentSelector> predicate) {
24+
IndexComponentSelectorPredicate(String name, Predicate<IndexComponentSelector> predicate) {
2025
this(Set.of(name), predicate);
2126
}
2227

23-
public static final IndexComponentSelectorPrivilege ALL = new IndexComponentSelectorPrivilege("all", Predicates.always());
24-
public static final IndexComponentSelectorPrivilege DATA = new IndexComponentSelectorPrivilege(
28+
public static final IndexComponentSelectorPredicate ALL = new IndexComponentSelectorPredicate("all", Predicates.always());
29+
public static final IndexComponentSelectorPredicate DATA = new IndexComponentSelectorPredicate(
2530
"data",
2631
IndexComponentSelector.DATA::equals
2732
);
28-
public static final IndexComponentSelectorPrivilege FAILURES = new IndexComponentSelectorPrivilege(
33+
public static final IndexComponentSelectorPredicate FAILURES = new IndexComponentSelectorPredicate(
2934
"failures",
3035
IndexComponentSelector.FAILURES::equals
3136
);

0 commit comments

Comments
 (0)