我正在嘗試在使用java的本地活動目錄上查找用戶。
當我嘗試執行代碼,我得到以下錯誤:嘗試在活動目錄中執行LDAP查找時出錯
錯誤:
Lookup failed: javax.naming.NamingException: [LDAP: error code 1 - 000004DC: Lda pErr: DSID-0C0906DC, comment: In order to perform this operation a successful bi nd must be completed on the connection., data 0, v1db1 ]; remaining name: 'CN= John Doe, OU=Accounts'
誰能告訴我什麼,我做錯了嗎?
我的代碼:
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.ldap.LdapContext;
/**
* Demonstrates how to look up an object.
*
* usage: java Lookup
*/
class Lookup {
public static void main(String[] args) {
// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://localhost:389/DC=PORTAL-UAT,DC=COMPANY,DC=COM");
try {
// Create the initial context
Context ctx = new InitialContext(env);
// Perform lookup and cast to target type
LdapContext b = (LdapContext) ctx
.lookup("CN=John Doe,OU=Accounts");
System.out.println(b);
// Close the context
ctx.close();
} catch (NamingException e) {
System.out.println("Lookup failed: " + e);
}
}
}
得到了綁定認證工作。 – Andreas 2012-03-12 09:56:44