package com.lzx.test;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.core.Search;
import io.searchbox.core.Search.Builder;
import io.searchbox.core.SearchResult;
/**
*
* @author lizx
* @date 2018年11月21日下午5:43:13
*/
public class JestSSLTest {
public static void main(String[] args) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder("https://127.0.0.1:9200")
.defaultSchemeForDiscoveredNodes("https") // required, otherwise uses http
.defaultCredentials("liones", "kirk")
.sslSocketFactory(sslSocketFactory) // this only affects sync calls
.httpsIOSessionStrategy(httpsIOSessionStrategy) // this only affects async calls
.build()
);
JestClient client = factory.getObject();
Builder build = new Search.Builder("{\"query\": {\"match_all\": {}}}").addIndex("news");
Search search = build.build();
try {
SearchResult execute = client.execute(search);
System.out.println(execute.getJsonString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Search-Guard安装详细教程
共39个文件
jks:9个
sh:8个
java:4个
5星 · 超过95%的资源 需积分: 35 34 下载量 8 浏览量
2018-11-23
17:51:22
上传
评论
收藏 3.64MB RAR 举报
温馨提示
Search-Guard 是Elasticsearch的一个免费安全插件,它提供身份验证和授权 ,这里上传的是居于elasticsearch2.3的安装详细教程,包括java中如何连接都有完整的例子,网上很多都不完整,这是作者踩过了无数的坑后整理出来的,希望对大家有帮助。
资源推荐
资源详情
资源评论
收起资源包目录
search-guard-2插件安装.rar (39个子文件)
search-guard-2插件安装
Search-Guard-2安装教程.htm 14KB
search-guard-2-2.3.1.0-beta1.zip 129KB
证书
node-0-keystore.jks 4KB
kirk-keystore.jks 4KB
truststore.jks 1KB
example-pki-scripts
gen_node_cert_openssl.sh 2KB
gen_client_node_cert.sh 2KB
example.sh 1KB
gen_root_ca.sh 2KB
gen_node_cert.sh 3KB
gen_unittest_certs.sh 676B
gen_revoked_cert_openssl.sh 2KB
etc
root-ca.conf 4KB
signing-ca.conf 5KB
clean.sh 169B
search guard权限详解.mhtml 4.24MB
search-guard-ssl-2.3.1.8.1.zip 1.43MB
Java连接示例
JestSSLTest.java 3KB
es-ssl
pom.xml 2KB
config
node-0-keystore.jks 4KB
kirk-keystore.jks 4KB
truststore.jks 1KB
target
test-classes
classes
node-0-keystore.jks 4KB
META-INF
maven
com.lzx.frame
es-ssl
pom.xml 2KB
pom.properties 210B
MANIFEST.MF 114B
kirk-keystore.jks 4KB
com
lzx
test
TransportClientSSLTest.class 4KB
JestSSLTest$1.class 753B
JestSSLTest.class 4KB
truststore.jks 1KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 191B
org.eclipse.jdt.core.prefs 243B
src
test
resources
java
main
resources
java
com
lzx
test
JestSSLTest.java 2KB
TransportClientSSLTest.java 2KB
.project 558B
.classpath 1KB
TransportClientSSLTest.java 2KB
共 39 条
- 1
资源评论
- xiao45678902019-06-26可以做参考,不错
_执着_
- 粉丝: 379
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功