Skip to content

Commit 76be286

Browse files
committed
Merge remote-tracking branch 'elastic/master' into geosql
2 parents 78dfa50 + ba47882 commit 76be286

File tree

166 files changed

+2759
-1731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+2759
-1731
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ class ClusterConfiguration {
110110
return seedNode.transportUri()
111111
}
112112

113+
/**
114+
* A closure to call which returns a manually supplied list of unicast seed hosts.
115+
*/
116+
@Input
117+
Closure<List<String>> otherUnicastHostAddresses = {
118+
Collections.emptyList()
119+
}
120+
113121
/**
114122
* A closure to call before the cluster is considered ready. The closure is passed the node info,
115123
* as well as a groovy AntBuilder, to enable running ant condition checks. The default wait

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,9 @@ class ClusterFormationTasks {
715715
wait.doLast {
716716

717717
Collection<String> unicastHosts = new HashSet<>()
718-
nodes.forEach { otherNode ->
719-
String unicastHost = otherNode.config.unicastTransportUri(otherNode, null, project.ant)
718+
nodes.forEach { node ->
719+
unicastHosts.addAll(node.config.otherUnicastHostAddresses.call())
720+
String unicastHost = node.config.unicastTransportUri(node, null, project.ant)
720721
if (unicastHost != null) {
721722
unicastHosts.addAll(Arrays.asList(unicastHost.split(",")))
722723
}

client/benchmark/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Steps to execute the benchmark
22

3-
1. Build `client-benchmark-noop-api-plugin` with `gradle :client:client-benchmark-noop-api-plugin:assemble`
4-
2. Install it on the target host with `bin/elasticsearch-plugin install file:///full/path/to/client-benchmark-noop-api-plugin.zip`
3+
1. Build `client-benchmark-noop-api-plugin` with `./gradlew :client:client-benchmark-noop-api-plugin:assemble`
4+
2. Install it on the target host with `bin/elasticsearch-plugin install file:///full/path/to/client-benchmark-noop-api-plugin.zip`.
55
3. Start Elasticsearch on the target host (ideally *not* on the machine
66
that runs the benchmarks)
77
4. Run the benchmark with
@@ -49,7 +49,7 @@ The parameters are all in the `'`s and are in order:
4949
Example invocation:
5050

5151
```
52-
gradlew -p client/benchmark run --args ' rest search localhost geonames {"query":{"match_phrase":{"name":"Sankt Georgen"}}} 500,1000,1100,1200'
52+
./gradlew -p client/benchmark run --args ' rest search localhost geonames {"query":{"match_phrase":{"name":"Sankt Georgen"}}} 500,1000,1100,1200'
5353
```
5454

5555
The parameters are in order:

client/rest-high-level/src/main/java/org/elasticsearch/client/SecurityRequestConverters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static Request changePassword(ChangePasswordRequest changePasswordRequest) throw
6363
static Request putUser(PutUserRequest putUserRequest) throws IOException {
6464
String endpoint = new RequestConverters.EndpointBuilder()
6565
.addPathPartAsIs("_xpack/security/user")
66-
.addPathPart(putUserRequest.getUsername())
66+
.addPathPart(putUserRequest.getUser().getUsername())
6767
.build();
6868
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
6969
request.setEntity(createEntity(putUserRequest, REQUEST_BODY_CONTENT_TYPE));

client/rest-high-level/src/main/java/org/elasticsearch/client/security/PutUserRequest.java

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121

2222
import org.elasticsearch.client.Validatable;
2323
import org.elasticsearch.client.ValidationException;
24+
import org.elasticsearch.client.security.user.User;
2425
import org.elasticsearch.common.CharArrays;
26+
import org.elasticsearch.common.Nullable;
2527
import org.elasticsearch.common.xcontent.ToXContentObject;
2628
import org.elasticsearch.common.xcontent.XContentBuilder;
2729

2830
import java.io.IOException;
2931
import java.util.Arrays;
30-
import java.util.Collections;
31-
import java.util.List;
32-
import java.util.Map;
3332
import java.util.Objects;
3433
import java.util.Optional;
3534

@@ -38,62 +37,33 @@
3837
*/
3938
public final class PutUserRequest implements Validatable, ToXContentObject {
4039

41-
private final String username;
42-
private final List<String> roles;
43-
private final String fullName;
44-
private final String email;
45-
private final Map<String, Object> metadata;
46-
private final char[] password;
40+
private final User user;
41+
private final @Nullable char[] password;
4742
private final boolean enabled;
4843
private final RefreshPolicy refreshPolicy;
4944

5045
/**
5146
* Creates a new request that is used to create or update a user in the native realm.
5247
*
53-
* @param username the username of the user to be created or updated
48+
* @param user the user to be created or updated
5449
* @param password the password of the user. The password array is not modified by this class.
5550
* It is the responsibility of the caller to clear the password after receiving
5651
* a response.
57-
* @param roles the roles that this user is assigned
58-
* @param fullName the full name of the user that may be used for display purposes
59-
* @param email the email address of the user
6052
* @param enabled true if the user is enabled and allowed to access elasticsearch
61-
* @param metadata a map of additional user attributes that may be used in templating roles
6253
* @param refreshPolicy the refresh policy for the request.
6354
*/
64-
public PutUserRequest(String username, char[] password, List<String> roles, String fullName, String email, boolean enabled,
65-
Map<String, Object> metadata, RefreshPolicy refreshPolicy) {
66-
this.username = Objects.requireNonNull(username, "username is required");
55+
public PutUserRequest(User user, @Nullable char[] password, boolean enabled, @Nullable RefreshPolicy refreshPolicy) {
56+
this.user = Objects.requireNonNull(user, "user is required, cannot be null");
6757
this.password = password;
68-
this.roles = Collections.unmodifiableList(Objects.requireNonNull(roles, "roles must be specified"));
69-
this.fullName = fullName;
70-
this.email = email;
7158
this.enabled = enabled;
72-
this.metadata = metadata == null ? Collections.emptyMap() : Collections.unmodifiableMap(metadata);
7359
this.refreshPolicy = refreshPolicy == null ? RefreshPolicy.getDefault() : refreshPolicy;
7460
}
7561

76-
public String getUsername() {
77-
return username;
62+
public User getUser() {
63+
return user;
7864
}
7965

80-
public List<String> getRoles() {
81-
return roles;
82-
}
83-
84-
public String getFullName() {
85-
return fullName;
86-
}
87-
88-
public String getEmail() {
89-
return email;
90-
}
91-
92-
public Map<String, Object> getMetadata() {
93-
return metadata;
94-
}
95-
96-
public char[] getPassword() {
66+
public @Nullable char[] getPassword() {
9767
return password;
9868
}
9969

@@ -109,29 +79,25 @@ public RefreshPolicy getRefreshPolicy() {
10979
public boolean equals(Object o) {
11080
if (this == o) return true;
11181
if (o == null || getClass() != o.getClass()) return false;
112-
PutUserRequest that = (PutUserRequest) o;
113-
return enabled == that.enabled &&
114-
Objects.equals(username, that.username) &&
115-
Objects.equals(roles, that.roles) &&
116-
Objects.equals(fullName, that.fullName) &&
117-
Objects.equals(email, that.email) &&
118-
Objects.equals(metadata, that.metadata) &&
119-
Arrays.equals(password, that.password) &&
120-
refreshPolicy == that.refreshPolicy;
82+
final PutUserRequest that = (PutUserRequest) o;
83+
return Objects.equals(user, that.user)
84+
&& Arrays.equals(password, that.password)
85+
&& enabled == that.enabled
86+
&& refreshPolicy == that.refreshPolicy;
12187
}
12288

12389
@Override
12490
public int hashCode() {
125-
int result = Objects.hash(username, roles, fullName, email, metadata, enabled, refreshPolicy);
91+
int result = Objects.hash(user, enabled, refreshPolicy);
12692
result = 31 * result + Arrays.hashCode(password);
12793
return result;
12894
}
12995

13096
@Override
13197
public Optional<ValidationException> validate() {
132-
if (metadata != null && metadata.keySet().stream().anyMatch(s -> s.startsWith("_"))) {
98+
if (user.getMetadata() != null && user.getMetadata().keySet().stream().anyMatch(s -> s.startsWith("_"))) {
13399
ValidationException validationException = new ValidationException();
134-
validationException.addValidationError("metadata keys may not start with [_]");
100+
validationException.addValidationError("user metadata keys may not start with [_]");
135101
return Optional.of(validationException);
136102
}
137103
return Optional.empty();
@@ -140,7 +106,7 @@ public Optional<ValidationException> validate() {
140106
@Override
141107
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
142108
builder.startObject();
143-
builder.field("username", username);
109+
builder.field("username", user.getUsername());
144110
if (password != null) {
145111
byte[] charBytes = CharArrays.toUtf8Bytes(password);
146112
try {
@@ -149,18 +115,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
149115
Arrays.fill(charBytes, (byte) 0);
150116
}
151117
}
152-
if (roles != null) {
153-
builder.field("roles", roles);
154-
}
155-
if (fullName != null) {
156-
builder.field("full_name", fullName);
157-
}
158-
if (email != null) {
159-
builder.field("email", email);
118+
builder.field("roles", user.getRoles());
119+
if (user.getFullName() != null) {
120+
builder.field("full_name", user.getFullName());
160121
}
161-
if (metadata != null) {
162-
builder.field("metadata", metadata);
122+
if (user.getEmail() != null) {
123+
builder.field("email", user.getEmail());
163124
}
125+
builder.field("metadata", user.getMetadata());
126+
builder.field("enabled", enabled);
164127
return builder.endObject();
165128
}
166129
}

client/rest-high-level/src/main/java/org/elasticsearch/client/security/user/User.java

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,59 @@
2424

2525
import java.util.Collection;
2626
import java.util.Collections;
27+
import java.util.HashSet;
2728
import java.util.Map;
2829
import java.util.Objects;
30+
import java.util.Set;
2931

3032

3133
/**
32-
* An authenticated user
34+
* A user to be utilized with security APIs.
35+
* Can be an existing authenticated user or it can be a new user to be enrolled to the native realm.
3336
*/
3437
public final class User {
3538

3639
private final String username;
37-
private final Collection<String> roles;
40+
private final Set<String> roles;
3841
private final Map<String, Object> metadata;
3942
@Nullable private final String fullName;
4043
@Nullable private final String email;
4144

45+
/**
46+
* Builds the user to be utilized with security APIs.
47+
*
48+
* @param username the username, also known as the principal, unique for in the scope of a realm
49+
* @param roles the roles that this user is assigned
50+
* @param metadata a map of additional user attributes that may be used in templating roles
51+
* @param fullName the full name of the user that may be used for display purposes
52+
* @param email the email address of the user
53+
*/
4254
public User(String username, Collection<String> roles, Map<String, Object> metadata, @Nullable String fullName,
4355
@Nullable String email) {
44-
Objects.requireNonNull(username, "`username` cannot be null");
45-
Objects.requireNonNull(roles, "`roles` cannot be null. Pass an empty collection instead.");
46-
Objects.requireNonNull(roles, "`metadata` cannot be null. Pass an empty map instead.");
47-
this.username = username;
48-
this.roles = roles;
49-
this.metadata = Collections.unmodifiableMap(metadata);
56+
this.username = username = Objects.requireNonNull(username, "`username` is required, cannot be null");
57+
this.roles = Collections.unmodifiableSet(new HashSet<>(
58+
Objects.requireNonNull(roles, "`roles` is required, cannot be null. Pass an empty Collection instead.")));
59+
this.metadata = Collections
60+
.unmodifiableMap(Objects.requireNonNull(metadata, "`metadata` is required, cannot be null. Pass an empty map instead."));
5061
this.fullName = fullName;
5162
this.email = email;
5263
}
5364

65+
/**
66+
* Builds the user to be utilized with security APIs.
67+
*
68+
* @param username the username, also known as the principal, unique for in the scope of a realm
69+
* @param roles the roles that this user is assigned
70+
*/
71+
public User(String username, Collection<String> roles) {
72+
this(username, roles, Collections.emptyMap(), null, null);
73+
}
74+
5475
/**
5576
* @return The principal of this user - effectively serving as the
5677
* unique identity of the user. Can never be {@code null}.
5778
*/
58-
public String username() {
79+
public String getUsername() {
5980
return this.username;
6081
}
6182

@@ -64,28 +85,28 @@ public String username() {
6485
* identified by their unique names and each represents as
6586
* set of permissions. Can never be {@code null}.
6687
*/
67-
public Collection<String> roles() {
88+
public Set<String> getRoles() {
6889
return this.roles;
6990
}
7091

7192
/**
7293
* @return The metadata that is associated with this user. Can never be {@code null}.
7394
*/
74-
public Map<String, Object> metadata() {
95+
public Map<String, Object> getMetadata() {
7596
return metadata;
7697
}
7798

7899
/**
79100
* @return The full name of this user. May be {@code null}.
80101
*/
81-
public @Nullable String fullName() {
102+
public @Nullable String getFullName() {
82103
return fullName;
83104
}
84105

85106
/**
86107
* @return The email of this user. May be {@code null}.
87108
*/
88-
public @Nullable String email() {
109+
public @Nullable String getEmail() {
89110
return email;
90111
}
91112

@@ -103,28 +124,14 @@ public String toString() {
103124

104125
@Override
105126
public boolean equals(Object o) {
106-
if (this == o) {
107-
return true;
108-
}
109-
if (o instanceof User == false) {
110-
return false;
111-
}
112-
113-
final User user = (User) o;
114-
115-
if (!username.equals(user.username)) {
116-
return false;
117-
}
118-
if (!roles.equals(user.roles)) {
119-
return false;
120-
}
121-
if (!metadata.equals(user.metadata)) {
122-
return false;
123-
}
124-
if (fullName != null ? !fullName.equals(user.fullName) : user.fullName != null) {
125-
return false;
126-
}
127-
return !(email != null ? !email.equals(user.email) : user.email != null);
127+
if (this == o) return true;
128+
if (o == null || this.getClass() != o.getClass()) return false;
129+
final User that = (User) o;
130+
return Objects.equals(username, that.username)
131+
&& Objects.equals(roles, that.roles)
132+
&& Objects.equals(metadata, that.metadata)
133+
&& Objects.equals(fullName, that.fullName)
134+
&& Objects.equals(email, that.email);
128135
}
129136

130137
@Override

0 commit comments

Comments
 (0)