Hashtable env = new Hashtable(11); create environment
env.put(Context.INITIAL_CONTEXT_FACTORY, 「com.sun.jndi.ldap.LdapCtxFactory」); env.put(Context.PROVIDER_URL,「ldap:// localhost:10389/ou = system」); url Declaration
env.put(Context.SECURITY_CREDENTIALS,「secret」); env.put(Context.SECURITY_AUTHENTICATION,「simple」); env.put(Context.SECURITY_PRINCIPAL,「ou = 121,ousystem」); For this is Domain
env.put(Context.SECURITY_CREDENTIALS,「secret」); set new credential
//搜索並檢索DN。如何在Java代碼中爲ldap身份驗證設置新的安全身份驗證
DirContext ctx = null;
NamingEnumeration results = null;
try {
ctx = new InitialDirContext(env);`cant create obj here`
SearchControls controls = new SearchControls();
// Authenticate
ldap = new InitialLdapContext(env, null);
} catch (AuthenticationException ae) {
ae.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
錯誤:javax.naming.NameNotFoundException:when creating obj for context