Skip to content

Commit 76c88aa

Browse files
authored
Fix compilation of custom auth engine example (#121089) (#121699)
1 parent f338f59 commit 76c88aa

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

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

1212
import org.elasticsearch.action.ActionListener;
1313
import org.elasticsearch.cluster.metadata.IndexAbstraction;
14+
import org.elasticsearch.cluster.metadata.Metadata;
1415
import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse;
1516
import org.elasticsearch.xpack.core.security.action.user.GetUserPrivilegesResponse.Indices;
1617
import org.elasticsearch.xpack.core.security.authc.Authentication;
@@ -85,10 +86,13 @@ public void authorizeClusterAction(RequestInfo requestInfo, AuthorizationInfo au
8586
}
8687

8788
@Override
88-
public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo authorizationInfo,
89-
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
90-
Map<String, IndexAbstraction> aliasOrIndexLookup,
91-
ActionListener<IndexAuthorizationResult> listener) {
89+
public void authorizeIndexAction(
90+
RequestInfo requestInfo,
91+
AuthorizationInfo authorizationInfo,
92+
AsyncSupplier<ResolvedIndices> indicesAsyncSupplier,
93+
Metadata metadata,
94+
ActionListener<IndexAuthorizationResult> listener
95+
) {
9296
if (isSuperuser(requestInfo.getAuthentication().getEffectiveSubject().getUser())) {
9397
indicesAsyncSupplier.getAsync(ActionListener.wrap(resolvedIndices -> {
9498
Map<String, IndexAccessControl> indexAccessControlMap = new HashMap<>();

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.cluster.metadata.IndexAbstraction;
1515
import org.elasticsearch.cluster.metadata.IndexAbstraction.ConcreteIndex;
1616
import org.elasticsearch.cluster.metadata.IndexMetadata;
17+
import org.elasticsearch.cluster.metadata.Metadata;
1718
import org.elasticsearch.common.settings.Settings;
1819
import org.elasticsearch.index.IndexVersion;
1920
import org.elasticsearch.test.ESTestCase;
@@ -31,6 +32,7 @@
3132
import java.util.Collections;
3233
import java.util.HashMap;
3334
import java.util.Map;
35+
import java.util.stream.Stream;
3436

3537
import static org.hamcrest.Matchers.is;
3638

@@ -117,12 +119,13 @@ public void testAuthorizeClusterAction() {
117119

118120
public void testAuthorizeIndexAction() {
119121
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
120-
Map<String, IndexAbstraction> indicesMap = new HashMap<>();
121-
indicesMap.put("index", new ConcreteIndex(IndexMetadata.builder("index")
122-
.settings(Settings.builder().put("index.version.created", IndexVersion.current()))
123-
.numberOfShards(1)
124-
.numberOfReplicas(0)
125-
.build(), null));
122+
Metadata metadata = Metadata.builder().put(IndexMetadata.builder("index")
123+
.settings(Settings.builder().put("index.version.created", IndexVersion.current()))
124+
.numberOfShards(1)
125+
.numberOfReplicas(0)
126+
.build(),
127+
false
128+
).build();
126129
// authorized
127130
{
128131
RequestInfo requestInfo =
@@ -136,7 +139,7 @@ public void testAuthorizeIndexAction() {
136139
PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>();
137140
engine.authorizeIndexAction(requestInfo, authzInfo,
138141
listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())),
139-
indicesMap, resultFuture);
142+
metadata, resultFuture);
140143
IndexAuthorizationResult result = resultFuture.actionGet();
141144
assertThat(result.isGranted(), is(true));
142145
IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl();
@@ -156,7 +159,7 @@ public void testAuthorizeIndexAction() {
156159
PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>();
157160
engine.authorizeIndexAction(requestInfo, authzInfo,
158161
listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())),
159-
indicesMap, resultFuture);
162+
metadata, resultFuture);
160163
IndexAuthorizationResult result = resultFuture.actionGet();
161164
assertThat(result.isGranted(), is(false));
162165
IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl();

0 commit comments

Comments
 (0)