Skip to content

Commit

Permalink
Improve client ssl configuration.
Browse files Browse the repository at this point in the history
Original Pull Request #2780
Closes #2778
  • Loading branch information
sothawo authored Nov 24, 2023
1 parent ddd795a commit 1f44790
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.<br />
* <strong>NOTE</strong> You need to leave out the protocol in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 1f44790

Please sign in to comment.