sos,遇到了很头疼的问题

hqlbright 2007-09-28 10:15:08
我的windows 2003 server系统中安装了Active Directory,域名为myhome.brh.local
打开"Active Directory用户与计算机"的界面,在myhome.brh.local下建了一个组织机构bmp,又在该组织机构下面建了一个用户text,我要写java程序来访问该用户的每个属性.

package com.brh.myADText.text;

import java.util.Properties;
import javax.naming.*;
import javax.naming.directory.*;

//include the JNDI in the classpath. You should use the same JDK used by WebSphere Application server.

public class TextLdap {
public static void main(String[] args) {
// ***************** user information to be authenticated
// ********************************
// *****************Please modify the following three properties
// accordingly ************
String ldapHost = "ldap://192.168.0.101:389"; // ldap host +
// port number
String DN = "ExAdmin@myhome.brh.local";

// String DN = new String();
// DN to be
// authenticated
String password = "brh_123456"; // DN's password
// ***************** End of user information

Properties props = new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.SECURITY_AUTHENTICATION, "simple"); // use simple
//
// mechanism
props.put(Context.SECURITY_CREDENTIALS, password);
props.put(Context.SECURITY_PRINCIPAL, DN);
props.put(Context.PROVIDER_URL, ldapHost);

// authentication

long start = System.currentTimeMillis();
long end = 0;
long time = 0;

try {

DirContext ctx = new InitialDirContext(props);


Attributes attrsl = ctx.getAttributes ("cn=text,cn=bmp,DN=myhome,DN=hrm,DN=local");
System.out.println("ok");

// Create the search controls
SearchControls searchCtls = new SearchControls();

// Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
// specify the LDAP search filter
String searchFilter = "(&(OU=bmp)(CN=text))";
// String searchFilter = null;

// Specify the Base for the search
String searchBase = "";
// initialize counter to total the group members
int totalResults = 0;
// Specify the attributes to return
String returnedAtts[] = {"displayname","password"};
searchCtls.setReturningAttributes(returnedAtts);

// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter,
searchCtls);
// Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult) answer.next();
System.out.println(">>>" + sr.getName());
//Print out the groups
Attributes attrs = sr.getAttributes();
if (attrs != null) {
try {
for (NamingEnumeration ae = attrs.getAll(); ae.hasMore(); ) {
Attribute attr = (Attribute) ae.next();
System.out.println("AttributeID: " + attr.getID());
for (NamingEnumeration e = attr.getAll(); e.hasMore();
totalResults++) {
System.out.println("Attributes:"+e.next());
}
}
} catch (NamingException e) {
e.printStackTrace();
System.err.println("Problem listing membership: " + e);
}
}
}
//System.out.println("Total groups: " + totalResults);
ctx.close();
} catch (Exception ex) {
System.out.println("Exception is " + ex.toString());
}
}
}


程序中的searchBase,searchFilter这两个参数的值应该怎么写,我怎么该也不对,老是报错.
javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-031006C5, problem 5012 (DIR_ERROR), data 0],remaining name 'ou=bmp,DN=myhome,DN=brh,DN=local'

各位大哥大姐们,快帮帮小弟吧,我已经头疼了好几天了.
...全文
88 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wonderme33 2011-11-18
  • 打赏
  • 举报
回复
我也有这个问题啊!!!
lgyhack 2008-03-23
  • 打赏
  • 举报
回复
这么长时间了 希望有高手来解决 呵呵

6,871

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧