【发布时间】:2017-11-26 08:25:55
【问题描述】:
我有一个用 C# 编写的测试实用程序。使用 System.DirectoryServices.AccountManagement;我正在从虚拟服务器 (LDAP) 创建到远程计算机上的 Active Directory 的 PrincipalContext 连接。
我 100% 能够连接到 Active Directory,并使用用户名和密码(UserPrincipal.FindByIdentity,然后是 context.ValidateCredentials)进行身份验证。
但我无法阅读这些组。它会拉回默认值,例如域用户。 如果我以虚拟服务器的本地管理员(而不是 AD 中存在的用户)的身份运行该实用程序,那么我突然可以使用相同的确切参数从 Active Directory 中获取所有指定用户的组。
这怎么可能?我错过了什么?
我的代码如下,尽管我认为问题与代码完全无关,如前所述,它在提升运行时运行良好。
g_context = new PrincipalContext(ContextType.Domain, this.USERDOMAIN);
g_principal = UserPrincipal.FindByIdentity(g_context, IdentityType.SamAccountName, this.USERNAME);
this.g_entry = (DirectoryEntry)g_principal.GetUnderlyingObject();
this.AUTHENTICATED = g_context.ValidateCredentials(this.USERNAME, this.USERPASS);
这就是设置。然后我们稍后使用 g_context..
List<String> memberships=GetGroups(this.g_principal, true); // get a list of all possible groups for user
对递归组扫描函数的调用..
private List<String> GetGroups(Principal source, bool debug, int depth=0, List<String> resultset=null) {
if (resultset==null) resultset = new List<String>();
depth++;
foreach (GroupPrincipal group in source.GetGroups()) {
if (!resultset.Contains(group.Name)) {
resultset.Add(group.Name);
if (debug) {
log.Debug((String.Join("\t",new String[depth-1]))+"Located group("+group.Name+") at depth: "+depth);
}
resultset=GetGroups(group, debug, depth, resultset);
}
}
return resultset;
}
当以管理员身份运行时,AD 以用户名的所有可能组成员身份进行响应。当不作为提升程序运行时,AD 以更少的组(仅基本组)响应。
关于我需要在哪里寻找解决方案有什么建议吗?虚拟 Windows 机器 o/s 上是否有一些隐藏的本地策略,为非管理员隐藏 ldap 连接上的活动目录数据?
【问题讨论】:
标签: c# asp.net active-directory ldap elevated-privileges