我正在尝试增强我的代码,以确定用户是否是给定 AD 组的成员。它基本上可以工作,除非该组的成员碰巧来自另一个(受信任的)域,因为它被存储为 foreignsecurityprincipal。
鉴于我对要测试的组和要检查的帐户都有一个有效的 DirectoryEntry 对象,我需要一个 DirectorySearcher 过滤器字符串,它允许我确认该帐户在该组中,即使该帐户是外国安全负责人。
(演示问题的 VB.NET 代码示例)
Dim ContainerGroup as DirectoryEntry = ... Code to get Group
Dim UserToCheckFor as DirectoryEntry = ... Code to get User
DSearcher = New DirectorySearcher(ContainerGroup, "(WHATCANIPUTINHERE)", New String() {"member;Range=0-5000"}, SearchScope.Base)
DSearcher.AttributeScopeQuery = "member"
'If an object is found, the account was in the group
Return (DSearcher.FindOne() IsNot Nothing)