Authz FieldExtractor support for TermInSet query (elastic/x-pack-elasticsearch#2539)
FieldExtractor for TermInSet query. Closes: elastic/x-pack-elasticsearch#1104 Original commit: elastic/x-pack-elasticsearch@7a46361c86
This commit is contained in:
parent
6b51f5e6ca
commit
a8ea4f2d90
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.security.authz.accesscontrol;
|
package org.elasticsearch.xpack.security.authz.accesscontrol;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.PrefixCodedTerms.TermIterator;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
import org.apache.lucene.search.DisjunctionMaxQuery;
|
import org.apache.lucene.search.DisjunctionMaxQuery;
|
||||||
|
@ -19,6 +20,7 @@ import org.apache.lucene.search.PointInSetQuery;
|
||||||
import org.apache.lucene.search.PointRangeQuery;
|
import org.apache.lucene.search.PointRangeQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.SynonymQuery;
|
import org.apache.lucene.search.SynonymQuery;
|
||||||
|
import org.apache.lucene.search.TermInSetQuery;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.Weight;
|
import org.apache.lucene.search.Weight;
|
||||||
import org.apache.lucene.search.spans.SpanTermQuery;
|
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||||
|
@ -88,6 +90,14 @@ class FieldExtractor {
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
extractFields(((IndexOrDocValuesQuery) query).getIndexQuery(), fields);
|
extractFields(((IndexOrDocValuesQuery) query).getIndexQuery(), fields);
|
||||||
}
|
}
|
||||||
|
} else if (query instanceof TermInSetQuery) {
|
||||||
|
// TermInSetQuery#field is inaccessible
|
||||||
|
TermInSetQuery termInSetQuery = (TermInSetQuery) query;
|
||||||
|
TermIterator termIterator = termInSetQuery.getTermData().iterator();
|
||||||
|
// there should only be one field
|
||||||
|
if (termIterator.next() != null) {
|
||||||
|
fields.add(termIterator.field());
|
||||||
|
}
|
||||||
} else if (query instanceof MatchAllDocsQuery) {
|
} else if (query instanceof MatchAllDocsQuery) {
|
||||||
// no field
|
// no field
|
||||||
} else if (query instanceof MatchNoDocsQuery) {
|
} else if (query instanceof MatchNoDocsQuery) {
|
||||||
|
|
|
@ -21,8 +21,10 @@ import org.apache.lucene.search.MultiPhraseQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.SynonymQuery;
|
import org.apache.lucene.search.SynonymQuery;
|
||||||
|
import org.apache.lucene.search.TermInSetQuery;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.spans.SpanTermQuery;
|
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||||
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -113,6 +115,12 @@ public class FieldExtractorTests extends ESTestCase {
|
||||||
assertEquals(asSet("foo"), fields);
|
assertEquals(asSet("foo"), fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testTermInSet() {
|
||||||
|
Set<String> fields = new HashSet<>();
|
||||||
|
FieldExtractor.extractFields(new TermInSetQuery("foo", new BytesRef("baz"), new BytesRef("baz2")), fields);
|
||||||
|
assertEquals(asSet("foo"), fields);
|
||||||
|
}
|
||||||
|
|
||||||
public void testMatchAllDocs() {
|
public void testMatchAllDocs() {
|
||||||
Set<String> fields = new HashSet<>();
|
Set<String> fields = new HashSet<>();
|
||||||
FieldExtractor.extractFields(new MatchAllDocsQuery(), fields);
|
FieldExtractor.extractFields(new MatchAllDocsQuery(), fields);
|
||||||
|
|
Loading…
Reference in New Issue