通过 Web 服务判断用户是否存在于 SharePoint 组中

发布于 2024-08-14 09:32:48 字数 464 浏览 1 评论 0原文

我正在开发一个内部 Web 应用程序,该应用程序将使用预定义的 SharePoint 组来确定用户的安全级别。我做了一些研究,发现 SharePoint 的“用户组”Web 服务具有“GetUserCollectionFromGroup()”方法,该方法将列出给定 SharePoint 组中的所有用户。

我遇到的问题是一些预定义的 SharePoint 组添加了 Active Directory 组,而不是单个用户。因此,当我调用 GetUserCollectionFromGroup("Members") 时,我会返回 Active Directory 组“DOMAIN\domain users\”的单个条目。有没有办法检查用户或用户所属的 Active Directory 组是否是仅使用 SharePoint Web 服务的 SharePoint 组的成员?或者我是否需要检查 SharePoint 组,然后查找所有 Active Directory 组以查看该用户是否也是该组的成员?

I am working on an internal web application that will use predefined SharePoint groups for determining a user's security level. I have done some research and found SharePoint's "usergroup" web service which has the method "GetUserCollectionFromGroup()" which will list all of the users in a given SharePoint group.

The problem I am having is some of the predefined SharePoint groups have Active Directory groups added to them, not the individual users. So, when I call GetUserCollectionFromGroup("Members") I get back a single entry for the Active Directory group "DOMAIN\domain users\". Is there a way to check if either a user or an Active Directory group that the user belongs to is a member of a SharePoint group using only SharePoint web services? Or will I need to check the SharePoint group and then lookup any and all Active Directory groups to see if this user is a member there also?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神也荒唐 2024-08-21 09:32:48

Active Directory 安全组在 SharePoint 中被视为“用户”。你无法以你想要的方式实现这一点。

但由于您确实拥有 DOMAIN\group,因此您可以在使用 SharePoint Webservices API 并使用 System.DirectoryServices 命名空间来解析用户后扩展您的代码。您可以在此处找到有关如何从组中获取用户的好示例。

Active Directory Security Groups are seen as "Users" in SharePoint. You cannot achieve that in the way you want.

But since you do have the DOMAIN\group you can extend your code after you hit the SharePoint webservices API and use the System.DirectoryServices namespace to resolve your users. You can find a good example on how to get users from a group here.

无言温柔 2024-08-21 09:32:48

下面的代码将检查用户是否属于特定组。这包括检查任何成员 AD 组。您将需要构建自定义 SharePoint Web 服务才能从远程计算机调用此代码。华泰

public static bool UserIsInGroup(SPUser user, SPGroup group)
        {
            try
            {
                using (SPSite site = new SPSite(group.ParentWeb.Site.ID, user.UserToken))
                {
                    using (SPWeb web = site.OpenWeb(group.ParentWeb.ID))
                    {
                        SPGroup impersonatedGroup = web.SiteGroups[group.Name];

                        return impersonatedGroup.ContainsCurrentUser;

                    }

                }



            }
            catch (Exception e)
            {

                 ///TODO: Log the exception
                  return false;

            }
        }

The code below will check if the user is in a particular group. This includes checking any member AD groups. You will need to build a custom SharePoint webservice to call this code from a remote machine. HTH

public static bool UserIsInGroup(SPUser user, SPGroup group)
        {
            try
            {
                using (SPSite site = new SPSite(group.ParentWeb.Site.ID, user.UserToken))
                {
                    using (SPWeb web = site.OpenWeb(group.ParentWeb.ID))
                    {
                        SPGroup impersonatedGroup = web.SiteGroups[group.Name];

                        return impersonatedGroup.ContainsCurrentUser;

                    }

                }



            }
            catch (Exception e)
            {

                 ///TODO: Log the exception
                  return false;

            }
        }
稀香 2024-08-21 09:32:48

请参阅以下内容以获取用户的所有 AD 组
http://urenjoy.blogspot.com/2009/ 04/getting-active-directory-groups-from.html
并使用 AD 组作为共享点用户来获取共享点组。

See following to get all AD groups from a user
http://urenjoy.blogspot.com/2009/04/getting-active-directory-groups-from.html
and use the AD Groups as a sharepoint user to get the sharepoint groups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文