Skip to content

Commit 23e5c15

Browse files
authored
Fix custom authz engine for multi-project (#123937)
1 parent b4602d5 commit 23e5c15

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

plugins/examples/security-authorization-engine/src/main/java/org/elasticsearch/example/CustomAuthorizationEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import org.elasticsearch.action.ActionListener;
1313
import org.elasticsearch.cluster.metadata.IndexAbstraction;
14-
import org.elasticsearch.cluster.metadata.Metadata;
14+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1515
import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse;
1616
import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse.Indices;
1717
import org.elasticsearch.xpack.core.security.authc.Authentication;
@@ -90,7 +90,7 @@ public void authorizeIndexAction(
9090
RequestInfo requestInfo,
9191
AuthorizationInfo authorizationInfo,
9292
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
93-
Metadata metadata,
93+
ProjectMetadata project,
9494
ActionListener<IndexAuthorizationResult> listener
9595
) {
9696
if (isSuperuser(requestInfo.getAuthentication().getEffectiveSubject().getUser())) {

plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.cluster.metadata.IndexAbstraction.ConcreteIndex;
1616
import org.elasticsearch.cluster.metadata.IndexMetadata;
1717
import org.elasticsearch.cluster.metadata.Metadata;
18+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1819
import org.elasticsearch.common.settings.Settings;
1920
import org.elasticsearch.index.IndexVersion;
2021
import org.elasticsearch.test.ESTestCase;
@@ -119,7 +120,7 @@ public void testAuthorizeClusterAction() {
119120

120121
public void testAuthorizeIndexAction() {
121122
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
122-
Metadata metadata = Metadata.builder().put(IndexMetadata.builder("index")
123+
ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(IndexMetadata.builder("index")
123124
.settings(Settings.builder().put("index.version.created", IndexVersion.current()))
124125
.numberOfShards(1)
125126
.numberOfReplicas(0)
@@ -139,7 +140,7 @@ public void testAuthorizeIndexAction() {
139140
PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>();
140141
engine.authorizeIndexAction(requestInfo, authzInfo,
141142
listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())),
142-
metadata, resultFuture);
143+
project, resultFuture);
143144
IndexAuthorizationResult result = resultFuture.actionGet();
144145
assertThat(result.isGranted(), is(true));
145146
IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl();
@@ -159,7 +160,7 @@ public void testAuthorizeIndexAction() {
159160
PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>();
160161
engine.authorizeIndexAction(requestInfo, authzInfo,
161162
listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())),
162-
metadata, resultFuture);
163+
project, resultFuture);
163164
IndexAuthorizationResult result = resultFuture.actionGet();
164165
assertThat(result.isGranted(), is(false));
165166
IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl();

0 commit comments

Comments
 (0)