关于ldap的连接 得不到信息,帮忙看看

06-03-24 Javalga
主要代码如下:

初始化:

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

Javalga
2006-03-25 21:42
问题已解决部分,能得到用户部分属性,但是还是得不到密码属性,该如何设置才能获取??? 请指教

Javalga
2006-03-25 21:46
已得到属性为:

attrIDName:telephoneNumber

attrIDName:mail

attrIDName:uid

attrIDName:objectClass

attrIDName:givenName

attrIDName:sn

attrIDName:cn

想要密码属性呀,哭………………………………该怎么办呀

猜你喜欢