【问题标题】:javax.naming.CommunicationException: simple bind failed [duplicate]javax.naming.CommunicationException:简单绑定失败[重复]
【发布时间】:2012-08-17 11:33:21
【问题描述】:

尝试使用简单的 LDAP 应用程序连接到 LDAP 服务器时,我收到一条错误消息,提示“简单绑定失败”。我假设这与某种 BIND 有关。我在另一个应用程序的属性文件之一中有一个绑定属性,但不确定如何将该属性传递给该程序。

我需要添加更多详细信息吗?

代码

import javax.naming.directory.*;   
import javax.naming.*;   
import java.util.Vector;   
import java.util.Enumeration;   
import java.util.Properties;   
public class SearchLDAP {   
    public static void main(String[] args) {   
        String base = "";   

        String filter = "(objectclass=*)";   

        Properties env = new Properties();   

        env.put(DirContext.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");   
        env.put(DirContext.PROVIDER_URL,"ldaps://misguided.com.au:343"); 

        try {   

            System.out.println("11");
            DirContext dc = new InitialDirContext(env);
            System.out.println("22");

            SearchControls sc = new SearchControls();   
            sc.setSearchScope(SearchControls.OBJECT_SCOPE);   
            NamingEnumeration ne = null;   

            ne = dc.search(base, filter, sc);   

            while (ne.hasMore()) {   
                SearchResult sr = (SearchResult) ne.next();   
                System.out.println(sr.toString()+"\n");   
            }   
            dc.close();   
        } catch (NamingException nex) {   
            System.err.println("Error: " + nex.getMessage());   
            nex.printStackTrace();
        }   
    }   
}  

我得到的错误是

错误

11
Error: simple bind failed: XXXX.XXX.XXXX.net:808
javax.naming.CommunicationException: simple bind failed: misguided.com.au:343 [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(LdapClient.java:215)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2740)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:316)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)

【问题讨论】:

  • "sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效证书路径" 可能与它有关

标签: java ldap jndi


【解决方案1】:

这个问题现在有点老了,但很常见。试图简短地解释它:

此问题是由于 JRE 密钥库中缺少 SSL 证书而发生的。

对于 LDAPS 或 HTTPS 连接,java 运行时需要使用各自的 SSL 证书来创建与另一端服务器的安全连接。

要从其密钥库中获取 SSL 证书,该证书应首先安装在 Java 密钥库中。 “keytool”命令有助于在 Java Keystore 中导入/导出证书。

keytool –import -file adserv.crt -keystore <location to keystore> 

当它丢失时,你会得到一个:

"sun.security.provider.certpath.SunCertPathBuilderException: 
unable to find valid certification path to requested target". 

因此,您需要做的就是在建立安全连接之前安装证书。

【讨论】:

  • 我得到了同样的错误,但上面提到的命令不起作用。我已经使用“keytool -genkey -alias sonartomcat -keyalg RSA”这个命令生成了证书,但没有运气。请帮忙。
【解决方案2】:

我也遇到了同样的错误,如下所示。添加修复,如果这对某人有帮助。

我在连接到 LDAP 时从 IBM WAS 8.5 获得。

我必须确保将“密钥库名称”选择为 NodeDefaultKeystore 和别名是“无”

SSL 证书和密钥管理 > SSL 配置 > NodeDefaultSSLSettings

原因:javax.naming.CommunicationException: simple bind failed: xxxxxx-xxx.xxxxx.xxx:636 [root exception is javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake]

【讨论】:

  • 这是另一个错误。
猜你喜欢
  • 1970-01-01
  • 2018-10-17
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-22
相关资源
最近更新 更多