以下代码可以正常工作:
public static void main(String[] args) {
String userName = "admin";
String password = "s3cret";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=softwaredev,dc=local");
//env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, new String("softwaredev" + "\\" + userName));
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
NamingEnumeration results = null;
try {
ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(objectclass=person)", controls);
while (results.hasMore()) {
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
System.out.println(" Person Common Name = " + attributes.get("cn"));
System.out.println(" Person Display Name = " + attributes.get("displayName"));
System.out.println(" Person logonhours = " + attributes.get("logonhours"));
System.out.println(" Person MemberOf = " + attributes.get("memberOf"));
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (results != null) {
try {
results.close();
} catch (Exception e) {
}
}
if (ctx != null) {
try {
ctx.close();
} catch (Exception e) {
}
}
}
}
如果我取消注释以下行: env.put(Context.SECURITY_PROTOCOL, "ssl");
启用SSL连接并使用此URL:
ldaps://192.168.10.45:636
则程序失败,并且错误与证书有关。
*javax.naming.CommunicationException: simple bind failed: 192.168.10.45:636 [Root exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target]
at com.sun.jndi.ldap.LdapClient.authenticate(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at javax.naming.directory.InitialDirContext.<init>(Unknown Source)
at asd.LdapBasicExample.main(LdapBasicExample.java:25)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.jndi.ldap.Connection.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 13 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)*
那么,我该怎么解决这个问题呢?
引起原因:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效证书路径
您的客户端信任库不信任LDAP服务器的证书。您需要通过CA对其进行签名,或者将其从服务器导出到所有客户端信任库中。最终更容易,更便宜地进行签名。
问题内容: 我们有一个配置了SSL的网站,可托管WCF服务。服务的绑定具有,并且通信使用JSON序列化。 当我们从http请求此服务时,它返回JSONP,但是当使用HTTPS请求该服务时,它仅返回JSON。无论哪种方式我都需要JSONP,请帮忙。 当前配置是这样的: 问题答案: 如果使用此配置会发生什么: 问题是,如果要同时通过HTTP和HTTPS调用服务,则必须提供两个端点-一个端点用于HTTP
我正在尝试使用SSL证书将java客户端与JMX服务器连接。 但是不幸的是,这个连接给出了一个SSL握手错误。当我尝试使用< code >-DJ avax . net . debug = all 标志对此进行调试时,我在java客户端上得到以下错误消息。 2016-07-15T13:29:50.02-0700[APP/0]退出RMI更新清洁-[10.200.0.27:44445,javax.rmi
这很好,但没有SSL。 我已经使用OpenSSL为服务器和客户机生成了SSL证书,结果是: 服务器的证书(PEM格式) 客户端的证书(PEM格式) 服务器的私钥(PEM格式) 客户端的私钥(PEM格式) CA文件(PEM、CER和CRT格式) null 会出什么问题?
问题内容: 我正在尝试使用我的SSL证书运行socket.io,但是它将无法连接。 我基于聊天示例创建代码: 如果我删除SSL代码,它运行正常,但是与此同时,我收到了一个请求,请求http://domain.com/socket.io/1/?t=1309967919512 请注意,它没有尝试使用https,这会导致它失败。 我正在测试chrome,因为它是该应用程序的目标浏览器。 抱歉,这是一个简
目前,我正在尝试为ELB下的一个tomcat配置https,而对于SSL证书,我使用了aws证书管理器并指向ELB。 我的Elb监听器端口是 ELB端口80--- 有没有任何需要在tomcat级别的配置或者任何使用ACM的https运行我的站点的方法?
问题内容: 我需要通过带有SSL的spring-ldap与LDAP服务器进行通信,并且另一端拥有一个自签名证书。 有什么好心请给我一些指导来进行设置吗? 问题答案: 查看Spring LDAP文档以通过HTTP(S)连接到LDAP服务器: 就自签名证书而言,您可以将证书链导入信任库并设置以下VM参数: 或在运行时覆盖信任库,例如: 请记住,这两个选项都将覆盖默认的JVM信任库。因此,如果您使用不同