Replace setRefresh with setRefreshPolicy
setRefresh is being removed from core. Original commit: elastic/x-pack-elasticsearch@b865d06c6d
This commit is contained in:
parent
294fabb817
commit
a334ea57fc
|
@ -25,6 +25,7 @@ import org.junit.After;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
@ -58,7 +59,7 @@ public class ShardsTests extends MarvelIntegTestCase {
|
||||||
public void testShards() throws Exception {
|
public void testShards() throws Exception {
|
||||||
logger.debug("--> creating some indices so that shards collector reports data");
|
logger.debug("--> creating some indices so that shards collector reports data");
|
||||||
for (int i = 0; i < randomIntBetween(1, 5); i++) {
|
for (int i = 0; i < randomIntBetween(1, 5); i++) {
|
||||||
client().prepareIndex(INDEX_PREFIX + i, "foo").setRefresh(true).setSource("field1", "value1").get();
|
client().prepareIndex(INDEX_PREFIX + i, "foo").setRefreshPolicy(IMMEDIATE).setSource("field1", "value1").get();
|
||||||
}
|
}
|
||||||
|
|
||||||
securedFlush();
|
securedFlush();
|
||||||
|
|
|
@ -7,6 +7,8 @@ package org.elasticsearch.shield.action.role;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -24,13 +26,13 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
/**
|
/**
|
||||||
* Request object for adding a role to the shield index
|
* Request object for adding a role to the shield index
|
||||||
*/
|
*/
|
||||||
public class PutRoleRequest extends ActionRequest<PutRoleRequest> {
|
public class PutRoleRequest extends ActionRequest<PutRoleRequest> implements WriteRequest<PutRoleRequest> {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String[] clusterPrivileges = Strings.EMPTY_ARRAY;
|
private String[] clusterPrivileges = Strings.EMPTY_ARRAY;
|
||||||
private List<RoleDescriptor.IndicesPrivileges> indicesPrivileges = new ArrayList<>();
|
private List<RoleDescriptor.IndicesPrivileges> indicesPrivileges = new ArrayList<>();
|
||||||
private String[] runAs = Strings.EMPTY_ARRAY;
|
private String[] runAs = Strings.EMPTY_ARRAY;
|
||||||
private boolean refresh = true;
|
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
|
||||||
|
|
||||||
public PutRoleRequest() {
|
public PutRoleRequest() {
|
||||||
}
|
}
|
||||||
|
@ -69,8 +71,19 @@ public class PutRoleRequest extends ActionRequest<PutRoleRequest> {
|
||||||
this.runAs = usernames;
|
this.runAs = usernames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean refresh) {
|
@Override
|
||||||
this.refresh = refresh;
|
public PutRoleRequest setRefreshPolicy(RefreshPolicy refreshPolicy) {
|
||||||
|
this.refreshPolicy = refreshPolicy;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh (
|
||||||
|
* {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WriteRequest.RefreshPolicy getRefreshPolicy() {
|
||||||
|
return refreshPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
|
@ -89,10 +102,6 @@ public class PutRoleRequest extends ActionRequest<PutRoleRequest> {
|
||||||
return runAs;
|
return runAs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refresh() {
|
|
||||||
return refresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
|
@ -104,7 +113,7 @@ public class PutRoleRequest extends ActionRequest<PutRoleRequest> {
|
||||||
indicesPrivileges.add(RoleDescriptor.IndicesPrivileges.createFrom(in));
|
indicesPrivileges.add(RoleDescriptor.IndicesPrivileges.createFrom(in));
|
||||||
}
|
}
|
||||||
runAs = in.readStringArray();
|
runAs = in.readStringArray();
|
||||||
refresh = in.readBoolean();
|
refreshPolicy = RefreshPolicy.readFrom(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,7 +126,7 @@ public class PutRoleRequest extends ActionRequest<PutRoleRequest> {
|
||||||
index.writeTo(out);
|
index.writeTo(out);
|
||||||
}
|
}
|
||||||
out.writeStringArray(runAs);
|
out.writeStringArray(runAs);
|
||||||
out.writeBoolean(refresh);
|
refreshPolicy.writeTo(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
RoleDescriptor roleDescriptor() {
|
RoleDescriptor roleDescriptor() {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.shield.action.role;
|
package org.elasticsearch.shield.action.role;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
|
import org.elasticsearch.action.support.WriteRequestBuilder;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -14,7 +15,8 @@ import org.elasticsearch.shield.authz.RoleDescriptor;
|
||||||
/**
|
/**
|
||||||
* Builder for requests to add a role to the administrative index
|
* Builder for requests to add a role to the administrative index
|
||||||
*/
|
*/
|
||||||
public class PutRoleRequestBuilder extends ActionRequestBuilder<PutRoleRequest, PutRoleResponse, PutRoleRequestBuilder> {
|
public class PutRoleRequestBuilder extends ActionRequestBuilder<PutRoleRequest, PutRoleResponse, PutRoleRequestBuilder>
|
||||||
|
implements WriteRequestBuilder<PutRoleRequestBuilder> {
|
||||||
|
|
||||||
public PutRoleRequestBuilder(ElasticsearchClient client) {
|
public PutRoleRequestBuilder(ElasticsearchClient client) {
|
||||||
this(client, PutRoleAction.INSTANCE);
|
this(client, PutRoleAction.INSTANCE);
|
||||||
|
@ -54,9 +56,4 @@ public class PutRoleRequestBuilder extends ActionRequestBuilder<PutRoleRequest,
|
||||||
request.addIndex(indices, privileges, fields, query);
|
request.addIndex(indices, privileges, fields, query);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutRoleRequestBuilder refresh(boolean refresh) {
|
|
||||||
request.refresh(refresh);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ package org.elasticsearch.shield.action.user;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
@ -17,12 +19,14 @@ import java.io.IOException;
|
||||||
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Request to change a user's password.
|
||||||
*/
|
*/
|
||||||
public class ChangePasswordRequest extends ActionRequest<ChangePasswordRequest> implements UserRequest {
|
public class ChangePasswordRequest extends ActionRequest<ChangePasswordRequest>
|
||||||
|
implements UserRequest, WriteRequest<ChangePasswordRequest> {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private char[] passwordHash;
|
private char[] passwordHash;
|
||||||
private boolean refresh = true;
|
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionRequestValidationException validate() {
|
public ActionRequestValidationException validate() {
|
||||||
|
@ -52,12 +56,19 @@ public class ChangePasswordRequest extends ActionRequest<ChangePasswordRequest>
|
||||||
this.passwordHash = passwordHash;
|
this.passwordHash = passwordHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refresh() {
|
/**
|
||||||
return refresh;
|
* Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh (
|
||||||
|
* {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RefreshPolicy getRefreshPolicy() {
|
||||||
|
return refreshPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean refresh) {
|
@Override
|
||||||
this.refresh = refresh;
|
public ChangePasswordRequest setRefreshPolicy(RefreshPolicy refreshPolicy) {
|
||||||
|
this.refreshPolicy = refreshPolicy;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,6 +81,7 @@ public class ChangePasswordRequest extends ActionRequest<ChangePasswordRequest>
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
username = in.readString();
|
username = in.readString();
|
||||||
passwordHash = CharArrays.utf8BytesToChars(in.readBytesReference().array());
|
passwordHash = CharArrays.utf8BytesToChars(in.readBytesReference().array());
|
||||||
|
refreshPolicy = RefreshPolicy.readFrom(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,5 +89,6 @@ public class ChangePasswordRequest extends ActionRequest<ChangePasswordRequest>
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeString(username);
|
out.writeString(username);
|
||||||
out.writeBytesReference(new BytesArray(CharArrays.toUtf8Bytes(passwordHash)));
|
out.writeBytesReference(new BytesArray(CharArrays.toUtf8Bytes(passwordHash)));
|
||||||
|
refreshPolicy.writeTo(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,25 +7,28 @@ package org.elasticsearch.shield.action.user;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
|
import org.elasticsearch.action.support.WriteRequestBuilder;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.ValidationException;
|
import org.elasticsearch.common.ValidationException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.shield.user.User;
|
|
||||||
import org.elasticsearch.shield.authc.support.Hasher;
|
import org.elasticsearch.shield.authc.support.Hasher;
|
||||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||||
import org.elasticsearch.shield.support.Validation;
|
import org.elasticsearch.shield.support.Validation;
|
||||||
|
import org.elasticsearch.shield.user.User;
|
||||||
import org.elasticsearch.xpack.common.xcontent.XContentUtils;
|
import org.elasticsearch.xpack.common.xcontent.XContentUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Request to change a user's password.
|
||||||
*/
|
*/
|
||||||
public class ChangePasswordRequestBuilder
|
public class ChangePasswordRequestBuilder
|
||||||
extends ActionRequestBuilder<ChangePasswordRequest, ChangePasswordResponse, ChangePasswordRequestBuilder> {
|
extends ActionRequestBuilder<ChangePasswordRequest, ChangePasswordResponse, ChangePasswordRequestBuilder>
|
||||||
|
implements WriteRequestBuilder<ChangePasswordRequestBuilder> {
|
||||||
|
|
||||||
public ChangePasswordRequestBuilder(ElasticsearchClient client) {
|
public ChangePasswordRequestBuilder(ElasticsearchClient client) {
|
||||||
this(client, ChangePasswordAction.INSTANCE);
|
this(client, ChangePasswordAction.INSTANCE);
|
||||||
|
@ -81,9 +84,4 @@ public class ChangePasswordRequestBuilder
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangePasswordRequestBuilder refresh(boolean refresh) {
|
|
||||||
request.refresh(refresh);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ package org.elasticsearch.shield.action.user;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest;
|
||||||
|
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -22,7 +24,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
/**
|
/**
|
||||||
* Request object to put a native user.
|
* Request object to put a native user.
|
||||||
*/
|
*/
|
||||||
public class PutUserRequest extends ActionRequest<PutUserRequest> implements UserRequest {
|
public class PutUserRequest extends ActionRequest<PutUserRequest> implements UserRequest, WriteRequest<PutUserRequest> {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private String[] roles;
|
private String[] roles;
|
||||||
|
@ -30,7 +32,7 @@ public class PutUserRequest extends ActionRequest<PutUserRequest> implements Use
|
||||||
private String email;
|
private String email;
|
||||||
private Map<String, Object> metadata;
|
private Map<String, Object> metadata;
|
||||||
private char[] passwordHash;
|
private char[] passwordHash;
|
||||||
private boolean refresh = true;
|
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
|
||||||
|
|
||||||
public PutUserRequest() {
|
public PutUserRequest() {
|
||||||
}
|
}
|
||||||
|
@ -72,8 +74,19 @@ public class PutUserRequest extends ActionRequest<PutUserRequest> implements Use
|
||||||
this.passwordHash = passwordHash;
|
this.passwordHash = passwordHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean refresh) {
|
/**
|
||||||
this.refresh = refresh;
|
* Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh (
|
||||||
|
* {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}).
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RefreshPolicy getRefreshPolicy() {
|
||||||
|
return refreshPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PutUserRequest setRefreshPolicy(RefreshPolicy refreshPolicy) {
|
||||||
|
this.refreshPolicy = refreshPolicy;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String username() {
|
public String username() {
|
||||||
|
@ -101,10 +114,6 @@ public class PutUserRequest extends ActionRequest<PutUserRequest> implements Use
|
||||||
return passwordHash;
|
return passwordHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refresh() {
|
|
||||||
return refresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] usernames() {
|
public String[] usernames() {
|
||||||
return new String[] { username };
|
return new String[] { username };
|
||||||
|
@ -124,7 +133,7 @@ public class PutUserRequest extends ActionRequest<PutUserRequest> implements Use
|
||||||
fullName = in.readOptionalString();
|
fullName = in.readOptionalString();
|
||||||
email = in.readOptionalString();
|
email = in.readOptionalString();
|
||||||
metadata = in.readBoolean() ? in.readMap() : null;
|
metadata = in.readBoolean() ? in.readMap() : null;
|
||||||
refresh = in.readBoolean();
|
refreshPolicy = RefreshPolicy.readFrom(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,6 +156,6 @@ public class PutUserRequest extends ActionRequest<PutUserRequest> implements Use
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeMap(metadata);
|
out.writeMap(metadata);
|
||||||
}
|
}
|
||||||
out.writeBoolean(refresh);
|
refreshPolicy.writeTo(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.shield.action.user;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
|
import org.elasticsearch.action.support.WriteRequestBuilder;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
|
@ -15,17 +16,18 @@ import org.elasticsearch.common.ValidationException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.shield.user.User;
|
|
||||||
import org.elasticsearch.shield.authc.support.Hasher;
|
import org.elasticsearch.shield.authc.support.Hasher;
|
||||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||||
import org.elasticsearch.shield.support.Validation;
|
import org.elasticsearch.shield.support.Validation;
|
||||||
|
import org.elasticsearch.shield.user.User;
|
||||||
import org.elasticsearch.xpack.common.xcontent.XContentUtils;
|
import org.elasticsearch.xpack.common.xcontent.XContentUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PutUserRequestBuilder extends ActionRequestBuilder<PutUserRequest, PutUserResponse, PutUserRequestBuilder> {
|
public class PutUserRequestBuilder extends ActionRequestBuilder<PutUserRequest, PutUserResponse, PutUserRequestBuilder>
|
||||||
|
implements WriteRequestBuilder<PutUserRequestBuilder> {
|
||||||
|
|
||||||
private final Hasher hasher = Hasher.BCRYPT;
|
private final Hasher hasher = Hasher.BCRYPT;
|
||||||
|
|
||||||
|
@ -77,11 +79,6 @@ public class PutUserRequestBuilder extends ActionRequestBuilder<PutUserRequest,
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutUserRequestBuilder refresh(boolean refresh) {
|
|
||||||
request.refresh(refresh);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PutUserRequestBuilder source(String username, BytesReference source) throws IOException {
|
public PutUserRequestBuilder source(String username, BytesReference source) throws IOException {
|
||||||
username(username);
|
username(username);
|
||||||
try (XContentParser parser = XContentHelper.createParser(source)) {
|
try (XContentParser parser = XContentHelper.createParser(source)) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.carrotsearch.hppc.ObjectHashSet;
|
||||||
import com.carrotsearch.hppc.ObjectLongHashMap;
|
import com.carrotsearch.hppc.ObjectLongHashMap;
|
||||||
import com.carrotsearch.hppc.ObjectLongMap;
|
import com.carrotsearch.hppc.ObjectLongMap;
|
||||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ExceptionsHelper;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
|
@ -50,9 +51,6 @@ import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.shield.InternalClient;
|
import org.elasticsearch.shield.InternalClient;
|
||||||
import org.elasticsearch.shield.ShieldTemplateService;
|
import org.elasticsearch.shield.ShieldTemplateService;
|
||||||
import org.elasticsearch.shield.user.SystemUser;
|
|
||||||
import org.elasticsearch.shield.user.User;
|
|
||||||
import org.elasticsearch.shield.user.User.Fields;
|
|
||||||
import org.elasticsearch.shield.action.realm.ClearRealmCacheRequest;
|
import org.elasticsearch.shield.action.realm.ClearRealmCacheRequest;
|
||||||
import org.elasticsearch.shield.action.realm.ClearRealmCacheResponse;
|
import org.elasticsearch.shield.action.realm.ClearRealmCacheResponse;
|
||||||
import org.elasticsearch.shield.action.user.ChangePasswordRequest;
|
import org.elasticsearch.shield.action.user.ChangePasswordRequest;
|
||||||
|
@ -62,6 +60,9 @@ import org.elasticsearch.shield.authc.support.Hasher;
|
||||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||||
import org.elasticsearch.shield.client.SecurityClient;
|
import org.elasticsearch.shield.client.SecurityClient;
|
||||||
import org.elasticsearch.shield.support.SelfReschedulingRunnable;
|
import org.elasticsearch.shield.support.SelfReschedulingRunnable;
|
||||||
|
import org.elasticsearch.shield.user.SystemUser;
|
||||||
|
import org.elasticsearch.shield.user.User;
|
||||||
|
import org.elasticsearch.shield.user.User.Fields;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.threadpool.ThreadPool.Names;
|
import org.elasticsearch.threadpool.ThreadPool.Names;
|
||||||
|
|
||||||
|
@ -325,7 +326,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL
|
||||||
|
|
||||||
client.prepareUpdate(ShieldTemplateService.SECURITY_INDEX_NAME, docType, username)
|
client.prepareUpdate(ShieldTemplateService.SECURITY_INDEX_NAME, docType, username)
|
||||||
.setDoc(Fields.PASSWORD.getPreferredName(), String.valueOf(request.passwordHash()))
|
.setDoc(Fields.PASSWORD.getPreferredName(), String.valueOf(request.passwordHash()))
|
||||||
.setRefresh(request.refresh())
|
.setRefreshPolicy(request.getRefreshPolicy())
|
||||||
.execute(new ActionListener<UpdateResponse>() {
|
.execute(new ActionListener<UpdateResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(UpdateResponse updateResponse) {
|
public void onResponse(UpdateResponse updateResponse) {
|
||||||
|
@ -346,7 +347,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL
|
||||||
}
|
}
|
||||||
|
|
||||||
if (docType.equals(RESERVED_USER_DOC_TYPE)) {
|
if (docType.equals(RESERVED_USER_DOC_TYPE)) {
|
||||||
createReservedUser(username, request.passwordHash(), request.refresh(), listener);
|
createReservedUser(username, request.passwordHash(), request.getRefreshPolicy(), listener);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("failed to change password for user [{}]", cause, request.username());
|
logger.debug("failed to change password for user [{}]", cause, request.username());
|
||||||
ValidationException validationException = new ValidationException();
|
ValidationException validationException = new ValidationException();
|
||||||
|
@ -357,10 +358,10 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createReservedUser(String username, char[] passwordHash, boolean refresh, ActionListener<Void> listener) {
|
private void createReservedUser(String username, char[] passwordHash, RefreshPolicy refresh, ActionListener<Void> listener) {
|
||||||
client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, RESERVED_USER_DOC_TYPE, username)
|
client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, RESERVED_USER_DOC_TYPE, username)
|
||||||
.setSource(Fields.PASSWORD.getPreferredName(), String.valueOf(passwordHash))
|
.setSource(Fields.PASSWORD.getPreferredName(), String.valueOf(passwordHash))
|
||||||
.setRefresh(refresh)
|
.setRefreshPolicy(refresh)
|
||||||
.execute(new ActionListener<IndexResponse>() {
|
.execute(new ActionListener<IndexResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(IndexResponse indexResponse) {
|
public void onResponse(IndexResponse indexResponse) {
|
||||||
|
@ -401,7 +402,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL
|
||||||
User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(),
|
User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(),
|
||||||
User.Fields.EMAIL.getPreferredName(), putUserRequest.email(),
|
User.Fields.EMAIL.getPreferredName(), putUserRequest.email(),
|
||||||
User.Fields.METADATA.getPreferredName(), putUserRequest.metadata())
|
User.Fields.METADATA.getPreferredName(), putUserRequest.metadata())
|
||||||
.setRefresh(putUserRequest.refresh())
|
.setRefreshPolicy(putUserRequest.getRefreshPolicy())
|
||||||
.execute(new ActionListener<UpdateResponse>() {
|
.execute(new ActionListener<UpdateResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(UpdateResponse updateResponse) {
|
public void onResponse(UpdateResponse updateResponse) {
|
||||||
|
@ -441,7 +442,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL
|
||||||
User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(),
|
User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(),
|
||||||
User.Fields.EMAIL.getPreferredName(), putUserRequest.email(),
|
User.Fields.EMAIL.getPreferredName(), putUserRequest.email(),
|
||||||
User.Fields.METADATA.getPreferredName(), putUserRequest.metadata())
|
User.Fields.METADATA.getPreferredName(), putUserRequest.metadata())
|
||||||
.setRefresh(putUserRequest.refresh())
|
.setRefreshPolicy(putUserRequest.getRefreshPolicy())
|
||||||
.execute(new ActionListener<IndexResponse>() {
|
.execute(new ActionListener<IndexResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(IndexResponse indexResponse) {
|
public void onResponse(IndexResponse indexResponse) {
|
||||||
|
|
|
@ -300,7 +300,7 @@ public class NativeRolesStore extends AbstractComponent implements RolesStore, C
|
||||||
try {
|
try {
|
||||||
client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, ROLE_DOC_TYPE, role.getName())
|
client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, ROLE_DOC_TYPE, role.getName())
|
||||||
.setSource(role.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
|
.setSource(role.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
|
||||||
.setRefresh(request.refresh())
|
.setRefreshPolicy(request.getRefreshPolicy())
|
||||||
.execute(new ActionListener<IndexResponse>() {
|
.execute(new ActionListener<IndexResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(IndexResponse indexResponse) {
|
public void onResponse(IndexResponse indexResponse) {
|
||||||
|
|
|
@ -36,9 +36,7 @@ public class RestPutRoleAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
|
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
|
||||||
PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content());
|
PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content());
|
||||||
if (request.hasParam("refresh")) {
|
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
||||||
requestBuilder.refresh(request.paramAsBoolean("refresh", true));
|
|
||||||
}
|
|
||||||
requestBuilder.execute(new RestBuilderListener<PutRoleResponse>(channel) {
|
requestBuilder.execute(new RestBuilderListener<PutRoleResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(PutRoleResponse putRoleResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(PutRoleResponse putRoleResponse, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class RestChangePasswordAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
new SecurityClient(client).prepareChangePassword(username, request.content())
|
new SecurityClient(client).prepareChangePassword(username, request.content())
|
||||||
.refresh(request.paramAsBoolean("refresh", true))
|
.setRefreshPolicy(request.param("refresh"))
|
||||||
.execute(new RestBuilderListener<ChangePasswordResponse>(channel) {
|
.execute(new RestBuilderListener<ChangePasswordResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(ChangePasswordResponse changePasswordResponse, XContentBuilder builder) throws
|
public RestResponse buildResponse(ChangePasswordResponse changePasswordResponse, XContentBuilder builder) throws
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class RestPutUserAction extends BaseRestHandler {
|
||||||
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
|
protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception {
|
||||||
PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content());
|
PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content());
|
||||||
if (request.hasParam("refresh")) {
|
if (request.hasParam("refresh")) {
|
||||||
requestBuilder.refresh(request.paramAsBoolean("refresh", true));
|
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
||||||
}
|
}
|
||||||
requestBuilder.execute(new RestBuilderListener<PutUserResponse>(channel) {
|
requestBuilder.execute(new RestBuilderListener<PutUserResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,10 +13,9 @@ import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.shield.action.role.PutRoleResponse;
|
|
||||||
import org.elasticsearch.shield.action.role.GetRolesResponse;
|
|
||||||
import org.elasticsearch.shield.ShieldTemplateService;
|
import org.elasticsearch.shield.ShieldTemplateService;
|
||||||
import org.elasticsearch.shield.authc.esnative.NativeRealm;
|
import org.elasticsearch.shield.action.role.GetRolesResponse;
|
||||||
|
import org.elasticsearch.shield.action.role.PutRoleResponse;
|
||||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||||
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
|
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
|
||||||
import org.elasticsearch.shield.authz.RoleDescriptor;
|
import org.elasticsearch.shield.authz.RoleDescriptor;
|
||||||
|
@ -31,10 +30,13 @@ import org.junit.BeforeClass;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE;
|
||||||
import static org.hamcrest.Matchers.arrayWithSize;
|
import static org.hamcrest.Matchers.arrayWithSize;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the Shield clear roles API that changes the polling aspect of shield to only run once an hour in order to
|
* Test for the Shield clear roles API that changes the polling aspect of shield to only run once an hour in order to
|
||||||
* test the cache clearing APIs.
|
* test the cache clearing APIs.
|
||||||
|
@ -91,13 +93,12 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
|
||||||
int modifiedRolesCount = randomIntBetween(1, roles.length);
|
int modifiedRolesCount = randomIntBetween(1, roles.length);
|
||||||
List<String> toModify = randomSubsetOf(modifiedRolesCount, roles);
|
List<String> toModify = randomSubsetOf(modifiedRolesCount, roles);
|
||||||
logger.debug("--> modifying roles {} to have run_as", toModify);
|
logger.debug("--> modifying roles {} to have run_as", toModify);
|
||||||
final boolean refresh = randomBoolean();
|
|
||||||
for (String role : toModify) {
|
for (String role : toModify) {
|
||||||
PutRoleResponse response = securityClient.preparePutRole(role)
|
PutRoleResponse response = securityClient.preparePutRole(role)
|
||||||
.cluster("none")
|
.cluster("none")
|
||||||
.addIndices(new String[] { "*" }, new String[] { "ALL" }, null, null)
|
.addIndices(new String[] { "*" }, new String[] { "ALL" }, null, null)
|
||||||
.runAs(role)
|
.runAs(role)
|
||||||
.refresh(refresh)
|
.setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE)
|
||||||
.get();
|
.get();
|
||||||
assertThat(response.isCreated(), is(false));
|
assertThat(response.isCreated(), is(false));
|
||||||
logger.debug("--> updated role [{}] with run_as", role);
|
logger.debug("--> updated role [{}] with run_as", role);
|
||||||
|
@ -115,7 +116,7 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
|
||||||
UpdateResponse response = internalClient().prepareUpdate().setId(role).setIndex(ShieldTemplateService.SECURITY_INDEX_NAME)
|
UpdateResponse response = internalClient().prepareUpdate().setId(role).setIndex(ShieldTemplateService.SECURITY_INDEX_NAME)
|
||||||
.setType(NativeRolesStore.ROLE_DOC_TYPE)
|
.setType(NativeRolesStore.ROLE_DOC_TYPE)
|
||||||
.setDoc("run_as", new String[] { role })
|
.setDoc("run_as", new String[] { role })
|
||||||
.setRefresh(refresh)
|
.setRefreshPolicy(refresh ? IMMEDIATE : NONE)
|
||||||
.get();
|
.get();
|
||||||
assertThat(response.isCreated(), is(false));
|
assertThat(response.isCreated(), is(false));
|
||||||
logger.debug("--> updated role [{}] with run_as", role);
|
logger.debug("--> updated role [{}] with run_as", role);
|
||||||
|
@ -158,7 +159,7 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
|
||||||
final boolean refresh = randomBoolean();
|
final boolean refresh = randomBoolean();
|
||||||
DeleteResponse response = internalClient()
|
DeleteResponse response = internalClient()
|
||||||
.prepareDelete(ShieldTemplateService.SECURITY_INDEX_NAME, NativeRolesStore.ROLE_DOC_TYPE, role)
|
.prepareDelete(ShieldTemplateService.SECURITY_INDEX_NAME, NativeRolesStore.ROLE_DOC_TYPE, role)
|
||||||
.setRefresh(refresh)
|
.setRefreshPolicy(refresh ? IMMEDIATE : NONE)
|
||||||
.get();
|
.get();
|
||||||
assertThat(response.isFound(), is(true));
|
assertThat(response.isFound(), is(true));
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.elasticsearch.test.ShieldIntegTestCase;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
@ -64,7 +66,8 @@ public class DateMathExpressionIntegTests extends ShieldIntegTestCase {
|
||||||
CreateIndexResponse response = client.admin().indices().prepareCreate(expression).get();
|
CreateIndexResponse response = client.admin().indices().prepareCreate(expression).get();
|
||||||
assertThat(response.isAcknowledged(), is(true));
|
assertThat(response.isAcknowledged(), is(true));
|
||||||
}
|
}
|
||||||
IndexResponse response = client.prepareIndex(expression, "type").setSource("foo", "bar").setRefresh(refeshOnOperation).get();
|
IndexResponse response = client.prepareIndex(expression, "type").setSource("foo", "bar")
|
||||||
|
.setRefreshPolicy(refeshOnOperation ? IMMEDIATE : NONE).get();
|
||||||
|
|
||||||
assertThat(response.isCreated(), is(true));
|
assertThat(response.isCreated(), is(true));
|
||||||
assertThat(response.getIndex(), containsString(expectedIndexName));
|
assertThat(response.getIndex(), containsString(expectedIndexName));
|
||||||
|
@ -84,7 +87,7 @@ public class DateMathExpressionIntegTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
UpdateResponse updateResponse = client.prepareUpdate(expression, "type", response.getId())
|
UpdateResponse updateResponse = client.prepareUpdate(expression, "type", response.getId())
|
||||||
.setDoc("new", "field")
|
.setDoc("new", "field")
|
||||||
.setRefresh(refeshOnOperation)
|
.setRefreshPolicy(refeshOnOperation ? IMMEDIATE : NONE)
|
||||||
.get();
|
.get();
|
||||||
assertThat(updateResponse.isCreated(), is(false));
|
assertThat(updateResponse.isCreated(), is(false));
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.xpack.XPackPlugin;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
|
@ -94,10 +95,10 @@ public class DocumentAndFieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
SearchResponse response = client().filterWithHeader(
|
SearchResponse response = client().filterWithHeader(
|
||||||
|
@ -133,10 +134,10 @@ public class DocumentAndFieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// Both users have the same role query, but user3 has access to field2 and not field1, which should result in zero hits:
|
// Both users have the same role query, but user3 has access to field2 and not field1, which should result in zero hits:
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.xpack.XPackPlugin;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||||
|
@ -108,13 +109,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
SearchResponse response = client()
|
SearchResponse response = client()
|
||||||
|
@ -289,13 +290,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
boolean realtime = randomBoolean();
|
boolean realtime = randomBoolean();
|
||||||
|
@ -354,13 +355,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
boolean realtime = randomBoolean();
|
boolean realtime = randomBoolean();
|
||||||
|
@ -419,13 +420,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text,fielddata=true", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text,fielddata=true", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
client().prepareIndex("test", "type1", "2").setSource("field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
client().prepareIndex("test", "type1", "3").setSource("field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
SearchResponse response = client().prepareSearch("test")
|
SearchResponse response = client().prepareSearch("test")
|
||||||
|
@ -483,11 +484,11 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true")
|
.addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
client().prepareIndex("test", "type2", "2").setSource("field3", "value3")
|
client().prepareIndex("test", "type2", "2").setSource("field3", "value3")
|
||||||
.setParent("1")
|
.setParent("1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
SearchResponse response = client().prepareSearch("test")
|
SearchResponse response = client().prepareSearch("test")
|
||||||
|
@ -705,7 +706,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type", "field1", "type=text", "field2", "type=text")
|
.addMapping("type", "field1", "type=text", "field2", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type", "1").setSource("field1", "value1")
|
client().prepareIndex("test", "type", "1").setSource("field1", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// With document level security enabled the update is not allowed:
|
// With document level security enabled the update is not allowed:
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
|
@ -141,7 +142,7 @@ public class FieldLevelSecurityRandomTests extends ShieldIntegTestCase {
|
||||||
assertAcked(client().admin().indices().prepareCreate("test")
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
.addMapping("type1", (Object[])fieldMappers)
|
.addMapping("type1", (Object[])fieldMappers)
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource(doc).setRefresh(true).get();
|
client().prepareIndex("test", "type1", "1").setSource(doc).setRefreshPolicy(IMMEDIATE).get();
|
||||||
|
|
||||||
for (String allowedField : allowedFields) {
|
for (String allowedField : allowedFields) {
|
||||||
logger.info("Checking allowed field [{}]", allowedField);
|
logger.info("Checking allowed field [{}]", allowedField);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.xpack.XPackPlugin;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
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.hasChildQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||||
|
@ -136,7 +137,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 has access to field1, so the query should match with the document:
|
// user1 has access to field1, so the query should match with the document:
|
||||||
|
@ -488,7 +489,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 is granted access to field1 only:
|
// user1 is granted access to field1 only:
|
||||||
|
@ -622,7 +623,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
int max = scaledRandomIntBetween(4, 32);
|
int max = scaledRandomIntBetween(4, 32);
|
||||||
|
@ -660,7 +661,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
int max = scaledRandomIntBetween(4, 32);
|
int max = scaledRandomIntBetween(4, 32);
|
||||||
|
@ -702,7 +703,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
"field3", "type=text,store=true")
|
"field3", "type=text,store=true")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 is granted access to field1 only:
|
// user1 is granted access to field1 only:
|
||||||
|
@ -799,7 +800,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 is granted access to field1 only:
|
// user1 is granted access to field1 only:
|
||||||
|
@ -873,7 +874,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", 1d, "field2", 2d)
|
client().prepareIndex("test", "type1", "1").setSource("field1", 1d, "field2", 2d)
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 is granted to use field1, so it is included in the sort_values
|
// user1 is granted to use field1, so it is included in the sort_values
|
||||||
|
@ -911,7 +912,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text,fielddata=true", "field2", "type=text,fielddata=true")
|
.addMapping("type1", "field1", "type=text,fielddata=true", "field2", "type=text,fielddata=true")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user1 is authorized to use field1, so buckets are include for a term agg on field1
|
// user1 is authorized to use field1, so buckets are include for a term agg on field1
|
||||||
|
@ -951,7 +952,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
boolean realtime = randomBoolean();
|
boolean realtime = randomBoolean();
|
||||||
|
@ -1035,7 +1036,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
"field3", "type=text,term_vector=with_positions_offsets_payloads")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
boolean realtime = randomBoolean();
|
boolean realtime = randomBoolean();
|
||||||
|
@ -1155,7 +1156,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type", "1")
|
client().prepareIndex("test", "type", "1")
|
||||||
.setSource("field1", "value1", "field2", "value1")
|
.setSource("field1", "value1", "field2", "value1")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// With field level security enabled the update is not allowed:
|
// With field level security enabled the update is not allowed:
|
||||||
|
@ -1200,7 +1201,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
||||||
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// user6 has access to all fields, so the query should match with the document:
|
// user6 has access to all fields, so the query should match with the document:
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.elasticsearch.xpack.XPackPlugin;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
|
@ -72,7 +73,7 @@ public class IndicesPermissionsWithAliasesWildcardsAndRegexsTests extends Shield
|
||||||
.addAlias(new Alias("an_alias"))
|
.addAlias(new Alias("an_alias"))
|
||||||
);
|
);
|
||||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
GetResponse getResponse = client()
|
GetResponse getResponse = client()
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.test.ShieldIntegTestCase;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
@ -183,7 +184,7 @@ public class KibanaUserRoleIntegTests extends ShieldIntegTestCase {
|
||||||
.setIndex(index)
|
.setIndex(index)
|
||||||
.setType("dashboard")
|
.setType("dashboard")
|
||||||
.setSource("foo", "bar")
|
.setSource("foo", "bar")
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
assertThat(response.isCreated(), is(true));
|
assertThat(response.isCreated(), is(true));
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||||
|
@ -63,7 +64,7 @@ public class ShieldClearScrollTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void indexRandomDocuments() {
|
public void indexRandomDocuments() {
|
||||||
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefresh(true);
|
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefreshPolicy(IMMEDIATE);
|
||||||
for (int i = 0; i < randomIntBetween(10, 50); i++) {
|
for (int i = 0; i < randomIntBetween(10, 50); i++) {
|
||||||
bulkRequestBuilder.add(client().prepareIndex("index", "type", String.valueOf(i)).setSource("{ \"foo\" : \"bar\" }"));
|
bulkRequestBuilder.add(client().prepareIndex("index", "type", String.valueOf(i)).setSource("{ \"foo\" : \"bar\" }"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
@ -205,7 +206,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase {
|
||||||
createIndex("idx");
|
createIndex("idx");
|
||||||
ensureGreen("idx");
|
ensureGreen("idx");
|
||||||
// Index a document with the default test user
|
// Index a document with the default test user
|
||||||
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get();
|
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get();
|
||||||
|
|
||||||
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
||||||
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
||||||
|
@ -227,7 +228,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase {
|
||||||
createIndex("idx");
|
createIndex("idx");
|
||||||
ensureGreen("idx");
|
ensureGreen("idx");
|
||||||
// Index a document with the default test user
|
// Index a document with the default test user
|
||||||
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get();
|
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get();
|
||||||
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
||||||
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
||||||
|
|
||||||
|
@ -262,7 +263,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase {
|
||||||
createIndex("idx");
|
createIndex("idx");
|
||||||
ensureGreen("idx");
|
ensureGreen("idx");
|
||||||
// Index a document with the default test user
|
// Index a document with the default test user
|
||||||
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get();
|
client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get();
|
||||||
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray()));
|
||||||
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get();
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||||
|
@ -42,7 +43,7 @@ public class ChainIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||||
public void testChainedInputsAreWorking() throws Exception {
|
public void testChainedInputsAreWorking() throws Exception {
|
||||||
String index = "the-most-awesome-index-ever";
|
String index = "the-most-awesome-index-ever";
|
||||||
createIndex(index);
|
createIndex(index);
|
||||||
client().prepareIndex(index, "type", "id").setSource("{}").setRefresh(true).get();
|
client().prepareIndex(index, "type", "id").setSource("{}").setRefreshPolicy(IMMEDIATE).get();
|
||||||
|
|
||||||
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
||||||
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
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;
|
||||||
|
@ -49,7 +50,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
||||||
@TestLogging("watcher.support.http:TRACE")
|
@TestLogging("watcher.support.http:TRACE")
|
||||||
public void testHttpInput() throws Exception {
|
public void testHttpInput() throws Exception {
|
||||||
createIndex("index");
|
createIndex("index");
|
||||||
client().prepareIndex("index", "type", "id").setSource("{}").setRefresh(true).get();
|
client().prepareIndex("index", "type", "id").setSource("{}").setRefreshPolicy(IMMEDIATE).get();
|
||||||
|
|
||||||
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
||||||
watcherClient().preparePutWatch("_name")
|
watcherClient().preparePutWatch("_name")
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.joda.time.DateTimeZone;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||||
|
@ -140,7 +141,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject())
|
.endObject())
|
||||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// unknown condition:
|
// unknown condition:
|
||||||
|
@ -158,7 +159,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject())
|
.endObject())
|
||||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// unknown trigger:
|
// unknown trigger:
|
||||||
|
@ -176,7 +177,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject())
|
.endObject())
|
||||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
stopWatcher();
|
stopWatcher();
|
||||||
|
@ -200,7 +201,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject())
|
.endObject())
|
||||||
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
.setConsistencyLevel(WriteConsistencyLevel.ALL)
|
||||||
.setRefresh(true)
|
.setRefreshPolicy(IMMEDIATE)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
stopWatcher();
|
stopWatcher();
|
||||||
|
|
Loading…
Reference in New Issue