|
|
@ -37,6 +37,7 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsea
|
|
|
|
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
|
|
|
|
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
|
|
|
|
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients.WebClientConfigurationCallback;
|
|
|
|
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients.WebClientConfigurationCallback;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
import org.springframework.util.unit.DataSize;
|
|
|
|
import org.springframework.util.unit.DataSize;
|
|
|
|
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
|
|
|
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
@ -120,7 +121,11 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
|
|
|
if (this.deprecatedProperties.isCustomized()) {
|
|
|
|
if (this.deprecatedProperties.isCustomized()) {
|
|
|
|
return this.deprecatedProperties.getEndpoints();
|
|
|
|
return this.deprecatedProperties.getEndpoints();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.uris.stream().map((uri) -> uri.getHost() + ":" + uri.getPort()).collect(Collectors.toList());
|
|
|
|
return this.uris.stream().map(this::getEndpoint).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getEndpoint(URI uri) {
|
|
|
|
|
|
|
|
return uri.getHost() + ":" + uri.getPort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Credentials getCredentials() {
|
|
|
|
private Credentials getCredentials() {
|
|
|
@ -132,13 +137,10 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
|
|
|
if (uriCredentials == null) {
|
|
|
|
if (uriCredentials == null) {
|
|
|
|
return propertyCredentials;
|
|
|
|
return propertyCredentials;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (propertyCredentials != null && !uriCredentials.equals(propertyCredentials)) {
|
|
|
|
Assert.isTrue(propertyCredentials == null || uriCredentials.equals(propertyCredentials),
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"Credentials from URI user info do not match those from spring.elasticsearch.username and "
|
|
|
|
"Credentials from URI user info do not match those from spring.elasticsearch.username and "
|
|
|
|
+ "spring.elasticsearch.password");
|
|
|
|
+ "spring.elasticsearch.password");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return uriCredentials;
|
|
|
|
return uriCredentials;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Duration getConnectionTimeout() {
|
|
|
|
private Duration getConnectionTimeout() {
|
|
|
@ -155,8 +157,8 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
|
|
|
if (this.deprecatedProperties.isCustomized()) {
|
|
|
|
if (this.deprecatedProperties.isCustomized()) {
|
|
|
|
return this.deprecatedProperties.isUseSsl();
|
|
|
|
return this.deprecatedProperties.isUseSsl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<String> schemes = this.uris.stream().map((uri) -> uri.getScheme()).collect(Collectors.toSet());
|
|
|
|
Set<String> schemes = this.uris.stream().map(URI::getScheme).collect(Collectors.toSet());
|
|
|
|
Assert.isTrue(schemes.size() == 1, () -> "Configured Elasticsearch URIs have varying schemes");
|
|
|
|
Assert.isTrue(schemes.size() == 1, "Configured Elasticsearch URIs have varying schemes");
|
|
|
|
return schemes.iterator().next().equals("https");
|
|
|
|
return schemes.iterator().next().equals("https");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -189,29 +191,28 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Credentials from(List<String> uris) {
|
|
|
|
private static Credentials from(List<String> uris) {
|
|
|
|
Set<String> userInfos = uris.stream().map(URI::create).map((uri) -> uri.getUserInfo())
|
|
|
|
Set<String> userInfos = uris.stream().map(URI::create).map(URI::getUserInfo)
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
Assert.isTrue(userInfos.size() == 1, () -> "Configured Elasticsearch URIs have varying user infos");
|
|
|
|
Assert.isTrue(userInfos.size() == 1, "Configured Elasticsearch URIs have varying user infos");
|
|
|
|
String userInfo = userInfos.iterator().next();
|
|
|
|
String userInfo = userInfos.iterator().next();
|
|
|
|
if (userInfo != null) {
|
|
|
|
if (userInfo == null) {
|
|
|
|
String[] parts = userInfo.split(":");
|
|
|
|
return null;
|
|
|
|
return new Credentials(parts[0], (parts.length == 2) ? parts[1] : "");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
String[] parts = userInfo.split(":");
|
|
|
|
|
|
|
|
String username = parts[0];
|
|
|
|
|
|
|
|
String password = (parts.length != 2) ? "" : parts[1];
|
|
|
|
|
|
|
|
return new Credentials(username, password);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Credentials from(ElasticsearchProperties properties) {
|
|
|
|
private static Credentials from(ElasticsearchProperties properties) {
|
|
|
|
String username = properties.getUsername();
|
|
|
|
return getCredentials(properties.getUsername(), properties.getPassword());
|
|
|
|
String password = properties.getPassword();
|
|
|
|
|
|
|
|
if (username == null && password == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Credentials(username, password);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Credentials from(DeprecatedReactiveElasticsearchRestClientProperties properties) {
|
|
|
|
private static Credentials from(DeprecatedReactiveElasticsearchRestClientProperties properties) {
|
|
|
|
String username = properties.getUsername();
|
|
|
|
return getCredentials(properties.getUsername(), properties.getPassword());
|
|
|
|
String password = properties.getPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Credentials getCredentials(String username, String password) {
|
|
|
|
if (username == null && password == null) {
|
|
|
|
if (username == null && password == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -223,38 +224,20 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
|
|
|
if (this == obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (obj == null) {
|
|
|
|
if (obj == null || getClass() != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Credentials other = (Credentials) obj;
|
|
|
|
Credentials other = (Credentials) obj;
|
|
|
|
if (this.password == null) {
|
|
|
|
return ObjectUtils.nullSafeEquals(this.username, other.username)
|
|
|
|
if (other.password != null) {
|
|
|
|
&& ObjectUtils.nullSafeEquals(this.password, other.password);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!this.password.equals(other.password)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.username == null) {
|
|
|
|
|
|
|
|
if (other.username != null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!this.username.equals(other.username)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
public int hashCode() {
|
|
|
|
final int prime = 31;
|
|
|
|
final int prime = 31;
|
|
|
|
int result = 1;
|
|
|
|
int result = 1;
|
|
|
|
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
|
|
|
|
result = prime * result + ObjectUtils.nullSafeHashCode(this.username);
|
|
|
|
result = prime * result + ((this.username == null) ? 0 : this.username.hashCode());
|
|
|
|
result = prime * result + ObjectUtils.nullSafeHashCode(this.password);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|