c#LDAP成员资格枚举
这是我的问题:我需要枚举Active Directory中某些组的成员。复杂的是,组的“membersOf”属性中的对象的DN不包含我需要的标识符。具体地说,用户对象的c#LDAP成员资格枚举,c#,active-directory,ldap,C#,Active Directory,Ldap,这是我的问题:我需要枚举Active Directory中某些组的成员。复杂的是,组的“membersOf”属性中的对象的DN不包含我需要的标识符。具体地说,用户对象的CN对我来说是无用的,只有用户对象的一个属性(userID)是有用的 因此,我想到了三种方法: 我可以首先枚举组以获得组中DN的列表,然后对每个用户DN进行查找以找到他们的userID 我可以列举广告中的每个用户,获取他们的用户ID&他们的集合成员,然后检查他们是否拥有正确的成员资格 我可以用CN和userID获取所有用户的列表,
CN
对我来说是无用的,只有用户对象的一个属性(userID
)是有用的
因此,我想到了三种方法:
DN
的列表,然后对每个用户DN进行查找以找到他们的userID
用户ID
&他们的集合成员,然后检查他们是否拥有正确的成员资格
CN
和userID
获取所有用户的列表,然后枚举组以获得成员CN。然后,我可以加入原始列表中的列表,以获得我的成员用户ID的列表
System.DirectoryServices
工具完成这项工作
提前感谢您的时间和考虑。也许还有一个选择#4:
- 您可以设置一个枚举用户的
DirectorySearcher
- 您可以将
定义为搜索条件之一memberOf=….
- 您可以很容易地从目录搜索器中定义所需的属性
// define the "root" of your search (where to begin)
DirectoryEntry searchRoot = new DirectoryEntry("LDAP://cn=users,dc=yourcompany,dc=com");
DirectorySearcher searcher = new DirectorySearcher(searchRoot);
// set properties
searcher.SearchScope = SearchScope.Subtree;
// define search filter
searcher.Filter = "(&(objectCategory=Person)(memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com))";
// define attributes to load
searcher.PropertiesToLoad.Add("userid");
... add more if needed .....
foreach(SearchResult entry in searcher.FindAll())
{
string userid = entry.Properties["userid"][0].ToString();
}
也许还有一个选择#4:
- 您可以设置一个枚举用户的
DirectorySearcher
- 您可以将
定义为搜索条件之一memberOf=….
- 您可以很容易地从目录搜索器中定义所需的属性
// define the "root" of your search (where to begin)
DirectoryEntry searchRoot = new DirectoryEntry("LDAP://cn=users,dc=yourcompany,dc=com");
DirectorySearcher searcher = new DirectorySearcher(searchRoot);
// set properties
searcher.SearchScope = SearchScope.Subtree;
// define search filter
searcher.Filter = "(&(objectCategory=Person)(memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com))";
// define attributes to load
searcher.PropertiesToLoad.Add("userid");
... add more if needed .....
foreach(SearchResult entry in searcher.FindAll())
{
string userid = entry.Properties["userid"][0].ToString();
}