[英]Ignore SSL certificate verfication while connecting to elasticsearch from SPRING BOOT via high level rest client
Is there a way to ignore SSL certificate verification while connecting elasticsearch 7.4 using high level rest client.有没有办法在使用高级 rest 客户端连接 elasticsearch 7.4 时忽略 SSL 证书验证。 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.我有一个 HTTPS ES 集群,我想通过忽略 ssl 证书验证从我的 spring 引导应用程序连接它。
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!!");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.