當試圖使用簡單的LDAP應用程序連接到LDAP服務器時,出現一個錯誤,指出「簡單綁定失敗」。我假設這與某種BIND有關。我在其中一個屬性文件中爲不同的應用程序綁定了屬性,但不知道如何將該屬性傳遞給此程序。javax.naming.CommunicationException:簡單綁定失敗
我需要添加更多詳細信息嗎?
代碼
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:無法找到要求的目標的有效證書路徑「可能與它有關 –