關於ldap的連線 得不到資訊,幫忙看看

Javalga發表於2006-03-24
主要程式碼如下:
初始化:
private boolean connDS() {
boolean ret = false;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, SUNDS_LDAPURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, SUNDS_USERNAME);
env.put(Context.SECURITY_CREDENTIALS, SUNDS_PASSWORD);
try {
ctx = new InitialDirContext(env);
System.out.println("LDAP INIT InitialDirContext SUCCESS");
connFlag = true;
ret = true;
} catch (Exception E) {
System.out.println("LDAP INIT InitialDirContext ERROR" + E);
connFlag = false;
ret = false;
}
return ret;
}

獲取屬性:
private byte[] getPasswordValue(String userName) {
if (ctx == null) {
connDS();
}
String filterString = "uid=" + userName;
byte ret[] = new byte[20];
SearchControls constraints = new SearchControls();
constraints.setSearchScope(2);
try {
NamingEnumeration en = ctx.search(SUNDS_SEARCHBASE, filterString,
constraints); //要查詢的UID。如果是*則可以查到所有UID的節點
if (en == null) {
System.out.println("Have no NamingEnumeration.");
}
if (!en.hasMoreElements()) {
System.out.println("Have no element." + en);
程式來是到這步 取不到東西 錯誤可能在哪兒啊?是初始化錯誤嗎?
配置檔案如下:
SUNDS_SEARCHBASE = dc=minds,dc=com
SUNDS_LDAPURL = ldap://tjis.minds.com:389
SUNDS_USERNAME = uid=amAdmin,ou=People,dc=minds,dc=com
SUNDS_PASSWORD = 2


程式執行結果:
LDAP PROPERTIES LOAD SUCCESS...

LDAP INIT InitialDirContext SUCCESS
THE PASS ERROR FOR NO ELEMENT...
Have no element.com.sun.jndi.ldap.LdapSearchEnumeration@163956

相關文章