Skip to content

Commit 5d5f087

Browse files
Merge branch 'main' of github.com:elastic/elasticsearch into ml-ccm-api-settings
2 parents bd04fe4 + 7e53106 commit 5d5f087

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

server/src/test/java/org/elasticsearch/index/query/SearchExecutionContextTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.apache.lucene.document.Field;
1212
import org.apache.lucene.document.KeywordField;
13-
import org.apache.lucene.document.StringField;
1413
import org.apache.lucene.index.DirectoryReader;
1514
import org.apache.lucene.index.LeafReaderContext;
1615
import org.apache.lucene.index.Term;
@@ -223,18 +222,27 @@ public void testFielddataLookupTerminatesInLoop() {
223222
}
224223

225224
public void testFielddataLookupSometimesLoop() throws IOException {
226-
SearchExecutionContext searchExecutionContext = createSearchExecutionContext(
227-
// simulate a runtime field cycle in the second doc: 1: doc['2'] 2: doc['3'] 3: doc['4'] 4: doc['4']
225+
// create this field so we can use it to make sure we're escaping the loop on only the "first" document
226+
var concreteField = new KeywordFieldMapper.KeywordFieldType("indexed_field", true, true, Collections.emptyMap());
227+
228+
// simulate a runtime field cycle in the second doc: 1: doc['2'] 2: doc['3'] 3: doc['4'] 4: doc['4']
229+
var runtimeFields = List.of(
228230
runtimeField("1", leafLookup -> leafLookup.doc().get("2").get(0).toString()),
229231
runtimeField("2", leafLookup -> leafLookup.doc().get("3").get(0).toString()),
230232
runtimeField("3", leafLookup -> leafLookup.doc().get("4").get(0).toString()),
231-
runtimeField("4", (leafLookup, docId) -> {
232-
if (docId == 0) {
233+
runtimeField("4", leafLookup -> {
234+
if (leafLookup.doc().get("indexed_field").getFirst().equals("first")) {
233235
return "escape!";
234236
}
235-
return leafLookup.doc().get("4").get(0).toString();
237+
return leafLookup.doc().get("4").getFirst().toString();
236238
})
237239
);
240+
SearchExecutionContext searchExecutionContext = createSearchExecutionContext(
241+
"uuid",
242+
null,
243+
createMappingLookup(List.of(concreteField), runtimeFields),
244+
Collections.emptyMap()
245+
);
238246
List<String> values = collect("1", searchExecutionContext, new TermQuery(new Term("indexed_field", "first")));
239247
assertEquals(List.of("escape!"), values);
240248
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> collect("1", searchExecutionContext));
@@ -776,8 +784,8 @@ private static List<String> collect(String field, SearchExecutionContext searchE
776784
private static List<String> collect(String field, SearchExecutionContext searchExecutionContext, Query query) throws IOException {
777785
List<String> result = new ArrayList<>();
778786
try (Directory directory = newDirectory(); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
779-
indexWriter.addDocument(List.of(new StringField("indexed_field", "first", Field.Store.NO)));
780-
indexWriter.addDocument(List.of(new StringField("indexed_field", "second", Field.Store.NO)));
787+
indexWriter.addDocument(List.of(new KeywordField("indexed_field", "first", Field.Store.YES)));
788+
indexWriter.addDocument(List.of(new KeywordField("indexed_field", "second", Field.Store.YES)));
781789
try (DirectoryReader reader = indexWriter.getReader()) {
782790
IndexSearcher searcher = newSearcher(reader);
783791
MappedFieldType fieldType = searchExecutionContext.getFieldType(field);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ Collection<Object> createComponents(
11461146
if (authorizationDenialMessages.get() == null) {
11471147
authorizationDenialMessages.set(new AuthorizationDenialMessages.Default());
11481148
}
1149+
final var authorizedProjectsResolver = getCustomAuthorizedProjectsResolverOrDefault(extensionComponents);
11491150
final AuthorizationService authzService = new AuthorizationService(
11501151
settings,
11511152
allRolesStore,
@@ -1164,14 +1165,15 @@ Collection<Object> createComponents(
11641165
authorizationDenialMessages.get(),
11651166
linkedProjectConfigService,
11661167
projectResolver,
1167-
getCustomAuthorizedProjectsResolverOrDefault(extensionComponents),
1168+
authorizedProjectsResolver,
11681169
new CrossProjectModeDecider(settings)
11691170
);
11701171

11711172
components.add(nativeRolesStore); // used by roles actions
11721173
components.add(reservedRolesStore); // used by roles actions
11731174
components.add(allRolesStore); // for SecurityInfoTransportAction and clear roles cache
11741175
components.add(authzService);
1176+
components.add(new PluginComponentBinding<>(AuthorizedProjectsResolver.class, authorizedProjectsResolver));
11751177

11761178
final SecondaryAuthenticator secondaryAuthenticator = new SecondaryAuthenticator(
11771179
securityContext.get(),

0 commit comments

Comments
 (0)