使用 Sharepoint API 获取 AD 域组的成员
在我的 Sharepoint 代码中,我通过以下方式显示所有已定义用户的列表:
foreach (SPUser user in SPContext.Current.Web.AllUsers)
{
...
}
最重要的是,我可以将域安全组添加到 Sharepoint 组(如访客),从而一次添加许多用户(更简单的管理)。但我的代码至少在他们第一次登录之前看不到这些用户(如果他们有足够的权限)。在这种情况下,我只能看到域安全组 SPUser
对象实例,其 IsDomainGroup
设置为 true
。
是否可以通过 Sharepoint 获取域组成员,而无需诉诸 Active Directory 查询(这是我宁愿避免的事情,因为您可能需要足够的权限来执行此类操作 = 更多管理:Sharepoint 权限 +广告权)。
In my Sharepoint code I display a list of all defined users via:
foreach (SPUser user in SPContext.Current.Web.AllUsers)
{
...
}
The great part is, I can add a domain security group to a Sharepoint group (like Visitors) thus adding many users at once (simpler administration). But my code doesn't see those users at least not until they log-in for the first time (if they have sufficient rights). In this case I can only see the domain security group SPUser
object instance with its IsDomainGroup
set to true
.
Is it possible to get domain group members by means of Sharepoint without resorting to Active Directory querying (which is something I would rather avoid because you probably need sufficient rights to do such operations = more administration: Sharepoint rights + AD rights).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用方法
SPUtility.GetPrincipalsInGroup
(MSDN)。除
字符串输入
(安全组的 NT 帐户名称)之外的所有参数都是不言自明的:请注意,此方法不解析嵌套安全组。此外,执行用户需要具有当前 Web 上的浏览用户信息权限 (
SPBasePermissions.BrowseUserInfo
)。更新:
编辑:
当然,这是事实,但 SharePoint 也必须查找 AD。就是这样为什么应用程序池服务帐户需要对 AD 具有读取权限。
换句话说,如果您运行恢复到进程帐户的代码,您应该可以安全地对 AD 执行查询。
You can use the method
SPUtility.GetPrincipalsInGroup
(MSDN).All parameters are self-explaining except
string input
, which is the NT account name of the security group:Please note that this method does not resolve nested security groups. Further the executing user is required to have browse user info permission (
SPBasePermissions.BrowseUserInfo
) on the current web.Update:
Edit:
That's true, of course, but SharePoint has to lookup the AD as well. That's why a application pool service account is required to have read access to the AD.
In other words, you should be safe executing queries against the AD if you run your code reverted to the process account.
我建议您直接查询 Active Directory。您花费了大量精力来尝试让 SharePoint 为您调用 AD。每个具有域用户访问权限的帐户都应该能够查询您嵌套在 SharePoint 中的 AD 组。我只想去源头。
这样您就不必担心浏览用户权限或其他任何问题。在我看来,尝试通过 SharePoint 代理这一点只会让您的生活变得更加困难。
I would suggest you just query Active Directory directly. You are spending a lot of effort to try to get SharePoint to make this call to AD for you. Every account that has Domain User access should be able to query the AD groups you have nested in SharePoint. I would just go to the source.
This way you don't have to worry about Browse User Permissions or anything else. In my opinion trying to proxy this through SharePoint is just making your life more difficult.