通过高级别的客户端从 SPRING BOOT 连接到 elasticsearch 时忽略 SSL 证书验证 [英] Ignore SSL certificate verfication while connecting to elasticsearch from SPRING BOOT via high level rest client
本文介绍了通过高级别的客户端从 SPRING BOOT 连接到 elasticsearch 时忽略 SSL 证书验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在使用高级休息客户端连接 elasticsearch 7.4 时忽略 SSL 证书验证.我探索了几个选项,但在我的情况下没有任何效果.我有一个 HTTPS ES 集群,我想通过忽略 ssl 证书验证从我的 Spring Boot 应用程序连接.
Is there a way to ignore SSL certificate verification while connecting elasticsearch 7.4 using high level rest client. I explored a couple of options but nothing worked in my case. I have a HTTPS ES cluster which I want to connect from my spring boot application by ignoring ssl certificate verification.
推荐答案
希望能帮到你,我遇到了同样的问题,我就是这样解决的.
hope this will help you, I had the same problem and this is how I resolved.
@Bean
public RestHighLevelClient createSimpleElasticClient() throws Exception {
try {
SSLContextBuilder sslBuilder = SSLContexts.custom()
.loadTrustMaterial(null, (x509Certificates, s) -> true);
final SSLContext sslContext = sslBuilder.build();
RestHighLevelClient client = new RestHighLevelClient(RestClient
.builder(new HttpHost(hostNameOrLoadbalancerURL, 443, "https"))
//port number is given as 443 since its https schema
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder
.setSSLContext(sslContext)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}
})
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(5000)
.setSocketTimeout(120000);
}
}));
System.out.println("elasticsearch client created");
return client;
} catch (Exception e) {
System.out.println(e);
throw new Exception("Could not create an elasticsearch client!!");
}
}
这篇关于通过高级别的客户端从 SPRING BOOT 连接到 elasticsearch 时忽略 SSL 证书验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文