如何过滤包含特定用户的组的LDAP查询?

问题描述:

如何将Active Directory LDAP查询过滤到包含已验证/绑定用户(或任何用户)的组?这工作得很好:如何过滤包含特定用户的组的LDAP查询?

(&(objectClass=group)(member=*)) 
>>> lots of results 

但我不能去任何更多的细节:

(&(objectClass=group)(member=*S*)) 
>>> nothing 

的MSDN提到使用这样的过滤器:

(member:1.2.840.113556.1.4.1941:=(cn=user1,cn=users,DC=x)) 

但是,即使忽略了疯狂超幻数参与,我总是得到0结果,当我尝试过滤(即使用我自己的distinguishedName替换cn=user1,cn=users,DC=x,甚至重新把它与*)。

+0

在@链接的MSDN搜索过滤语法页JPBlanc的回答下面*列表*疯狂的超神奇的数字,但它并没有*解释*它。 *解释*是它是由ISO和ITU-T管理的模糊全球[OID](https://en.wikipedia.org/wiki/Object_identifier)标准中的一个节点,其中LDAP是少数几个突出的用途](https://en.wikipedia.org/wiki/Object_identifier#Usage)。请参阅http://www.oid-info.com/cgi-bin/display?tree=1.2.840.113556.1.4.1941了解每个数字意义的结构分解。 – 2017-03-08 01:52:11

您需要的用户即

(&(member=CN=Your Name,OU=Your OU,DC=company,DC=com)(objectClass=group)) 

的完整DN注意不能使用*在这一个

+3

“当我尝试过滤时,我总是得到0个结果(**甚至用我自己的distinguishedName **替换了cn = user1,cn = users,DC = x'” – 2011-05-18 21:39:30

所以参与递归搜索疯狂的超幻数Search Filter Syntax解释。

要查找一个搜索(递归地)所有的基团“USER1”是其成员:

  • 设置基座到组容器DN;例如根DN(DC = DOM,DC = FR)
  • 设置的范围,以子树
  • 使用以下滤波器:(member:1.2.840.113556.1.4.1941:=cn=user1,cn=users,DC=x)

explicited使用LDIFDE.EXE包括在Windows Server它的命令行工具得出:

ldifde -f user1Grps.ldf -d "dc=societe,dc=local" -r "(member:1.2.840.113556.1.4.1941:=cn=user1,ou=Monou,dc=societe,dc=local)" 

如果您正在运行在W2K8或W2K8 R2服务器要小心,以管理员身份运行。

如果在C#编程,你可以使用:

/* Retreiving a principal context 
*/ 
Console.WriteLine("Retreiving a principal context"); 
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "dc=dom,dc=fr", "jpb", "PWD"); 


/* Look for all the groups a user belongs to 
*/ 
UserPrincipal aUser = UserPrincipal.FindByIdentity(domainContext, "user1"); 
PrincipalSearchResult<Principal> a = aUser.GetAuthorizationGroups(); 

foreach (GroupPrincipal gTmp in a) 
{ 
    Console.WriteLine(gTmp.Name);  
}