Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,15 @@ private List<HttpHost> getHosts() {
}

private void buildClient() throws NoSuchFieldException, IllegalAccessException {
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
ElasticsearchClientFactory.ClientBuilder esClienBuilder = ElasticsearchClientFactory.builder();

if (sslTrustAllCertificates) {
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
try {
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
Expand All @@ -506,12 +507,13 @@ public void checkClientTrusted(X509Certificate[] certs, String authType) {
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} }, new SecureRandom());
esClienBuilder.sslContext(sslContext);
} catch (KeyManagementException e) {
LOGGER.error("Error creating SSL Context for trust all certificates", e);
}
}

esClient = ElasticsearchClientFactory.builder().hosts(getHosts()).socketTimeout(clientSocketTimeout).sslContext(sslContext)
esClient = esClienBuilder.hosts(getHosts()).socketTimeout(clientSocketTimeout)
.usernameAndPassword(username, password).build();

buildBulkIngester();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static ElasticsearchClient createClient(

builder.setHttpClientConfigCallback(httpClientBuilder -> {
if (sslContext != null) {
httpClientBuilder.setSSLContext(sslContext);
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setSSLContext(sslContext);
}
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
});
Expand Down
Loading