gpt4 book ai didi

spring-boot - 通过高级别的客户端从 SPRING BOOT 连接到 elasticsearch 时忽略 SSL 证书验证

转载 作者:行者123 更新时间:2023-12-04 22:38:50 31 4
gpt4 key购买 nike

有没有办法在使用高级别的客户端连接 elasticsearch 7.4 时忽略 SSL 证书验证。我探索了几个选项,但在我的情况下没有任何效果。我有一个 HTTPS ES 集群,我想通过忽略 ssl 证书验证从我的 Spring Boot 应用程序连接它。

最佳答案

希望这会对你有所帮助,我遇到了同样的问题,这就是我解决的方法。

@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
//port number is given as 443 since its https schema
.builder(new HttpHost(hostNameOrLoadbalancerURL, 443, "https"))
.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 - 通过高级别的客户端从 SPRING BOOT 连接到 elasticsearch 时忽略 SSL 证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62270799/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com