mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
es连接配置支持外部证书、证书密码加载
This commit is contained in:
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
package com.cf.imes.framework.es.config;
|
package com.cf.imes.framework.es.config;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.file.PathUtil;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
||||||
@@ -146,7 +146,7 @@ public class ChenfengElasticsearchAutoConfiguration {
|
|||||||
}
|
}
|
||||||
if (properties.isSecurityHttpSslEnable()) {
|
if (properties.isSecurityHttpSslEnable()) {
|
||||||
// 开启ssl配置连接证书
|
// 开启ssl配置连接证书
|
||||||
httpAsyncClientBuilder.setSSLContext(buildSSLContext(properties.getCertificatePath())).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
|
httpAsyncClientBuilder.setSSLContext(buildSSLContext(properties)).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
|
||||||
}
|
}
|
||||||
return httpAsyncClientBuilder;
|
return httpAsyncClientBuilder;
|
||||||
};
|
};
|
||||||
@@ -156,16 +156,16 @@ public class ChenfengElasticsearchAutoConfiguration {
|
|||||||
/**
|
/**
|
||||||
* 构建ssl请求信息
|
* 构建ssl请求信息
|
||||||
*
|
*
|
||||||
* @param certificatePath 证书地址
|
* @param properties es配置
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SSLContext buildSSLContext(String certificatePath) {
|
private SSLContext buildSSLContext(EsProperties properties) {
|
||||||
SSLContext sslContext = null;
|
SSLContext sslContext = null;
|
||||||
try {
|
try {
|
||||||
Path trustStorePath = Paths.get(certificatePath);
|
Path trustStorePath = Paths.get(properties.getCertificatePath());
|
||||||
KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
||||||
try (InputStream is = FileUtil.getInputStream(trustStorePath)) {
|
try (InputStream is = PathUtil.getInputStream(trustStorePath)) {
|
||||||
trustStore.load(is, "elastic".toCharArray());
|
trustStore.load(is, properties.getPassword().toCharArray());
|
||||||
}
|
}
|
||||||
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
|
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
|
||||||
.loadTrustMaterial(trustStore, null);
|
.loadTrustMaterial(trustStore, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user