diff --git a/src/main/java/org/springframework/data/elasticsearch/client/ClientConfiguration.java b/src/main/java/org/springframework/data/elasticsearch/client/ClientConfiguration.java index 02aa6f80d..f7d469f4f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/ClientConfiguration.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/ClientConfiguration.java @@ -233,6 +233,15 @@ interface MaybeSecureClientConfigurationBuilder extends TerminalClientConfigurat */ TerminalClientConfigurationBuilder usingSsl(); + /** + * Connects using https if flag is true. + * + * @param flag whether to use https in the connection + * @return the {@link TerminalClientConfigurationBuilder} + * @since 5.3 + */ + TerminalClientConfigurationBuilder usingSsl(boolean flag); + /** * Connect via {@literal https} using the given {@link SSLContext}.
* NOTE You need to leave out the protocol in diff --git a/src/main/java/org/springframework/data/elasticsearch/client/ClientConfigurationBuilder.java b/src/main/java/org/springframework/data/elasticsearch/client/ClientConfigurationBuilder.java index 9d276a494..f9521d12c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/ClientConfigurationBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/ClientConfigurationBuilder.java @@ -25,7 +25,6 @@ import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; -import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; import org.springframework.data.elasticsearch.client.ClientConfiguration.ClientConfigurationBuilderWithRequiredEndpoint; import org.springframework.data.elasticsearch.client.ClientConfiguration.MaybeSecureClientConfigurationBuilder; import org.springframework.data.elasticsearch.client.ClientConfiguration.TerminalClientConfigurationBuilder; @@ -106,6 +105,13 @@ public TerminalClientConfigurationBuilder usingSsl() { return this; } + @Override + public TerminalClientConfigurationBuilder usingSsl(boolean flag) { + + this.useSsl = flag; + return this; + } + /* * (non-Javadoc) * @see org.springframework.data.elasticsearch.client.ClientConfiguration.MaybeSecureClientConfigurationBuilder#usingSsl(javax.net.ssl.SSLContext) diff --git a/src/test/java/org/springframework/data/elasticsearch/client/ClientConfigurationUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/client/ClientConfigurationUnitTests.java index 8fca09ca4..c73b864c3 100644 --- a/src/test/java/org/springframework/data/elasticsearch/client/ClientConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/client/ClientConfigurationUnitTests.java @@ -58,7 +58,7 @@ public void shouldCreateCustomizedConfiguration() { ClientConfiguration clientConfiguration = ClientConfiguration.builder() // .connectedTo("foo", "bar") // - .usingSsl() // + .usingSsl(true) // .withDefaultHeaders(headers) // .withConnectTimeout(Duration.ofDays(1)).withSocketTimeout(Duration.ofDays(2)) // .withPathPrefix("myPathPrefix") // diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ElasticsearchTemplateConfiguration.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ElasticsearchTemplateConfiguration.java index b86561eb3..a2e620eb7 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ElasticsearchTemplateConfiguration.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ElasticsearchTemplateConfiguration.java @@ -51,10 +51,8 @@ public ClientConfiguration clientConfiguration() { configurationBuilder = configurationBuilder.withProxy(proxy); } - if (clusterConnectionInfo.isUseSsl()) { - configurationBuilder = ((ClientConfiguration.MaybeSecureClientConfigurationBuilder) configurationBuilder) - .usingSsl(); - } + configurationBuilder = ((ClientConfiguration.MaybeSecureClientConfigurationBuilder) configurationBuilder) + .usingSsl(clusterConnectionInfo.isUseSsl()); String user = System.getenv("DATAES_ELASTICSEARCH_USER"); String password = System.getenv("DATAES_ELASTICSEARCH_PASSWORD"); diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ReactiveElasticsearchTemplateConfiguration.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ReactiveElasticsearchTemplateConfiguration.java index 45b10a553..c020fe7e7 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ReactiveElasticsearchTemplateConfiguration.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ReactiveElasticsearchTemplateConfiguration.java @@ -50,10 +50,9 @@ public ClientConfiguration clientConfiguration() { if (proxy != null) { configurationBuilder = configurationBuilder.withProxy(proxy); } - if (clusterConnectionInfo.isUseSsl()) { - configurationBuilder = ((ClientConfiguration.MaybeSecureClientConfigurationBuilder) configurationBuilder) - .usingSsl(); - } + + configurationBuilder = ((ClientConfiguration.MaybeSecureClientConfigurationBuilder) configurationBuilder) + .usingSsl(clusterConnectionInfo.isUseSsl()); String user = System.getenv("DATAES_ELASTICSEARCH_USER"); String password = System.getenv("DATAES_ELASTICSEARCH_PASSWORD");