0

我有点卡住试图在我的代码中工作的东西。检查某人是使用部分群组名称的多个群组之一的成员

我想要做的是要弄清楚某人是否是任何一个组的集合的成员。我并不担心具体哪个组,我只想知道:

“用户”X“是否是这组集合中的至少一个的成员?”

  • 谷歌-FullAccess
  • 谷歌,RestrictedAccess
  • 谷歌,MailOnly
  • 谷歌,企业等
  • 好消息是,所有这些组的名字以同样的方式启动

下面是我用来检查特定组的内容:

Dim ctx As DirectoryServices.AccountManagement.PrincipalContext = New DirectoryServices.AccountManagement.PrincipalContext(DirectoryServices.AccountManagement.ContextType.Domain, "net.mydomain.co.uk") 
Dim user As DirectoryServices.AccountManagement.UserPrincipal = DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(ctx, tbxuserID.Text) 
Dim googleFull As DirectoryServices.AccountManagement.GroupPrincipal = DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(ctx, "Google-FullAccess") 
If user.IsMemberOf(googleFull) Then 
    GoogleAccess = 1 
    GoTo Proceed 
End If 

然后我重复这段代码来检查下一个组,等等。

有没有办法让我适应这个检查任何组“Google-”?这是我想要做的,但显然不起作用:

Dim googleCheck As DirectoryServices.AccountManagement.GroupPrincipal = DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(ctx, "Google-*") 

帮助非常感谢!

回答

0

我找到了解决方案!以下工作适用于我(在制作并存储来自先前查询的字符串变量中的DistinguishedName后 - 我也事先声明GoogleCheck为布尔变量):

Dim rootEntry As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://DC=net,DC=mydomain,DC=co,DC=uk") 
Dim srch As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(rootEntry) 
srch.SearchScope = DirectoryServices.SearchScope.Subtree 
srch.Filter = "(&(CN=Google-*)(objectCategory=group)(member=" + DistinguishedName + "))" 
Dim res = srch.FindOne() 
If res IsNot Nothing Then 
    GoogleCheck = True 
Else 
    GoogleCheck = False 
End If