[英]Ldap get users in a distribution list
I'm trying to get all the users of a DL using below code.The code is working as expected. 我正在尝试使用下面的代码来获取DL的所有用户。代码按预期工作。 However, I'm not able to get AD usernames for some users.
但是,我无法为某些用户获取AD用户名。 Ex.
例如 First row of the o/p has username rkama but not the second row.
o / p的第一行具有用户名rkama,但第二行没有。 Is this LDAP data issue or is there a different way to get user name/email address in a DL.
是此LDAP数据问题,还是通过其他方式获取DL中的用户名/电子邮件地址。
O/p Entry is : CN=Ay\\,Ram(rkama),OU=Site-SJN,OU=Accounts_User,DC=corp,DC=XXX,DC=com Entry is : CN=Wang\\,Peter(),OU=Site-SJN,OU=Accounts_User,DC=corp,DC=XXX,DC=com O / p条目为:CN = Ay \\,Ram(rkama),OU = Site-SJN,OU = Accounts_User,DC = corp,DC = XXX,DC = com条目为:CN = Wang \\,Peter(),OU = Site-SJN,OU = Accounts_User,DC = corp,DC = XXX,DC = com
public ArrayList<String> getAllDLs(String dlname) throws NamingException {
ArrayList<String> dls = new ArrayList<String>();
String attributes[] = { "member", "displayName" };
createDLContext();
SearchControls ctrl = new SearchControls();
ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctrl.setReturningAttributes(attributes);
String search = "(&(objectClass=group)((sAMAccountName="+dlname+"*)))";
NamingEnumeration enumeration = dlContext.search("", search, ctrl);
while (enumeration.hasMoreElements()) {
SearchResult result = (SearchResult) enumeration.next();
System.out.println("Found match & result is : " + result);
NamingEnumeration<?> n2 = result.getAttributes().get("member").getAll();
while (n2 != null && n2.hasMore()) {
String dlList = (String) n2.next();
System.out.println("Entry is : " + dlList);
}
}
dlContext.close();
return dls;
}
I think you need to escape the \\
character. 我认为您需要转义
\\
字符。 Have a look at http://www.rlmueller.net/CharactersEscaped.htm 看看http://www.rlmueller.net/CharactersEscaped.htm
The member
element only contains a DN
for the user, this is not the username or password of the account, but a value that can be put back into the search to get the user information (including cn
- the name of the user, and sAMAccountName
- the userid of the user). member
元素仅包含用户的DN
,这不是帐户的用户名或密码,而是可以返回搜索以获取用户信息的值(包括cn
用户名和sAMAccountName
-用户的用户ID)。
So you need to feed the dlList
value into a second search (cleanly) eg 因此,您需要将
dlList
值输入第二个搜索(干净地),例如
NamingEnumeration searchResult = dlContext.search("", "(dn={1})", new Object[]{ dlList }, ctrl);
Trying to construct the search with a simple string like "(&(objectClass=group)((sAMAccountName="+dlname+"*)))"
will yield problems because the elements of the returned string will need to be escaped before putting it into the search (the \\
for example). 尝试使用
"(&(objectClass=group)((sAMAccountName="+dlname+"*)))"
类的简单字符串来构造搜索会产生问题,因为返回的字符串的元素在放入其中之前需要先进行转义搜索(例如\\
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.