Adapt x-pack after the parent/child modularisation (elastic/x-pack-elasticsearch#1407)

This is the x-pack side of elastic/elasticsearch#24634
The hasChild, hasParent queries and the children agg are now in a module.

Original commit: elastic/x-pack-elasticsearch@e9b1296fc3
This commit is contained in:
Jim Ferenczi 2017-05-12 15:59:40 +02:00 committed by GitHub
parent 4f073cd4bd
commit de1d98b135
5 changed files with 45 additions and 15 deletions

View File

@ -51,7 +51,7 @@ Closure setAwsCreds = {
def matcher = javaVersion =~ /1\.8\.0(?:_(\d+))?/ def matcher = javaVersion =~ /1\.8\.0(?:_(\d+))?/
boolean matches = matcher.matches() boolean matches = matcher.matches()
assert matches assert matches
final int update final int update
if (matcher.group(1) == null) { if (matcher.group(1) == null) {
update = 0 update = 0
@ -240,6 +240,7 @@ dependencies {
testCompile 'org.slf4j:slf4j-log4j12:1.6.2' testCompile 'org.slf4j:slf4j-log4j12:1.6.2'
testCompile 'org.slf4j:slf4j-api:1.6.2' testCompile 'org.slf4j:slf4j-api:1.6.2'
testCompile project(path: ':modules:reindex', configuration: 'runtime') testCompile project(path: ':modules:reindex', configuration: 'runtime')
testCompile project(path: ':modules:parent-join', configuration: 'runtime')
} }
// make LicenseSigner available for testing signed licenses // make LicenseSigner available for testing signed licenses

View File

@ -46,8 +46,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.BoostingQueryBuilder; import org.elasticsearch.index.query.BoostingQueryBuilder;
import org.elasticsearch.index.query.ConstantScoreQueryBuilder; import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.HasChildQueryBuilder;
import org.elasticsearch.index.query.HasParentQueryBuilder;
import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.ParsedQuery;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.query.QueryRewriteContext;
@ -319,9 +317,9 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
// another module. So we don't allow the entire percolate query. I don't think users would ever use // another module. So we don't allow the entire percolate query. I don't think users would ever use
// a percolate query as role query, so this restriction shouldn't prohibit anyone from using dls. // a percolate query as role query, so this restriction shouldn't prohibit anyone from using dls.
throw new IllegalArgumentException("percolate query isn't support as part of a role query"); throw new IllegalArgumentException("percolate query isn't support as part of a role query");
} else if (queryBuilder instanceof HasChildQueryBuilder) { } else if (queryBuilder.getName().equals("has_child")) {
throw new IllegalArgumentException("has_child query isn't support as part of a role query"); throw new IllegalArgumentException("has_child query isn't support as part of a role query");
} else if (queryBuilder instanceof HasParentQueryBuilder) { } else if (queryBuilder.getName().equals("has_parent")) {
throw new IllegalArgumentException("has_parent query isn't support as part of a role query"); throw new IllegalArgumentException("has_parent query isn't support as part of a role query");
} else if (queryBuilder instanceof BoolQueryBuilder) { } else if (queryBuilder instanceof BoolQueryBuilder) {
BoolQueryBuilder boolQueryBuilder = (BoolQueryBuilder) queryBuilder; BoolQueryBuilder boolQueryBuilder = (BoolQueryBuilder) queryBuilder;

View File

@ -26,23 +26,29 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndicesRequestCache; import org.elasticsearch.indices.IndicesRequestCache;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.children.Children; import org.elasticsearch.join.aggregations.JoinAggregationBuilders;
import org.elasticsearch.join.aggregations.Children;
import org.elasticsearch.search.aggregations.bucket.global.Global; import org.elasticsearch.search.aggregations.bucket.global.Global;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortMode; import org.elasticsearch.search.sort.SortMode;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.join.ParentJoinPlugin;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Collection;
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.join.query.JoinQueryBuilders.hasChildQuery;
import static org.elasticsearch.join.query.JoinQueryBuilders.hasParentQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
@ -58,6 +64,16 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
protected static final SecureString USERS_PASSWD = new SecureString("change_me".toCharArray()); protected static final SecureString USERS_PASSWD = new SecureString("change_me".toCharArray());
protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(USERS_PASSWD)); protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(USERS_PASSWD));
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(XPackPlugin.class, ParentJoinPlugin.class);
}
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return nodePlugins();
}
@Override @Override
protected String configUsers() { protected String configUsers() {
return super.configUsers() + return super.configUsers() +
@ -577,7 +593,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
SearchResponse response = client().prepareSearch("test") SearchResponse response = client().prepareSearch("test")
.setTypes("type1") .setTypes("type1")
.addAggregation(AggregationBuilders.children("children", "type2") .addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3"))) .subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get(); .get();
assertHitCount(response, 1); assertHitCount(response, 1);
@ -592,7 +608,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.setTypes("type1") .setTypes("type1")
.addAggregation(AggregationBuilders.children("children", "type2") .addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3"))) .subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get(); .get();
assertHitCount(response, 1); assertHitCount(response, 1);
@ -606,7 +622,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD)))
.prepareSearch("test") .prepareSearch("test")
.setTypes("type1") .setTypes("type1")
.addAggregation(AggregationBuilders.children("children", "type2") .addAggregation(JoinAggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3"))) .subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get(); .get();
assertHitCount(response, 1); assertHitCount(response, 1);

View File

@ -30,19 +30,24 @@ import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.join.ParentJoinPlugin;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Collection;
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
import static org.elasticsearch.index.query.QueryBuilders.existsQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery;
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.join.query.JoinQueryBuilders.hasChildQuery;
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@ -60,6 +65,16 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase {
protected static final SecureString USERS_PASSWD = new SecureString("change_me".toCharArray()); protected static final SecureString USERS_PASSWD = new SecureString("change_me".toCharArray());
protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(new SecureString("change_me".toCharArray()))); protected static final String USERS_PASSWD_HASHED = new String(Hasher.BCRYPT.hash(new SecureString("change_me".toCharArray())));
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(XPackPlugin.class, ParentJoinPlugin.class);
}
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return nodePlugins();
}
@Override @Override
protected String configUsers() { protected String configUsers() {
return super.configUsers() + return super.configUsers() +

View File

@ -56,8 +56,8 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.BoostingQueryBuilder; import org.elasticsearch.index.query.BoostingQueryBuilder;
import org.elasticsearch.index.query.ConstantScoreQueryBuilder; import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.HasChildQueryBuilder; import org.elasticsearch.join.query.HasChildQueryBuilder;
import org.elasticsearch.index.query.HasParentQueryBuilder; import org.elasticsearch.join.query.HasParentQueryBuilder;
import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.query.QueryRewriteContext;
@ -214,7 +214,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
Set<String> expected = new HashSet<>(META_FIELDS_WITHOUT_ALL); Set<String> expected = new HashSet<>(META_FIELDS_WITHOUT_ALL);
expected.add("foo.bar"); expected.add("foo.bar");
assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.bar"}, null)), expected, "foo", "foo.baz", "bar.foo"); assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.bar"}, null)), expected, "foo", "foo.baz", "bar.foo");
expected = new HashSet<>(META_FIELDS_WITHOUT_ALL); expected = new HashSet<>(META_FIELDS_WITHOUT_ALL);
expected.add("foo.bar"); expected.add("foo.bar");
assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.*"}, null)), expected, "foo", "bar"); assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.*"}, null)), expected, "foo", "bar");