具有 SharePoint 用户组的 Fba 角色

发布于 2024-07-15 22:45:28 字数 1629 浏览 3 评论 0原文

我已经构建了自定义成员资格和角色提供程序。 用户是属于公司的一些客户,我使用公司作为角色。

我想创建 SharePoint 组并向其中添加更多公司(例如行业类型),然后由 SPGroup 进行重定向和安全性。

如何检索当前登录用户的 SPGroup?
我想在我的自定义登录页面中这样做,所以另一个问题是如何检索知道登录名的 SPUser 或 SPGroup ?

这就是我现在所拥有的:


private List GetGroupsForUser(List roleAccounts)
{
    List groups = new List();
    SPSecurity.RunWithElevatedPrivileges(
     delegate()
     {
         using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
         {
             SPUserCollection users = site.RootWeb.SiteUsers;
             foreach (string account in roleAccounts)
             {
                 SPGroupCollection accGroups = users[account].Groups;
                 foreach (SPGroup spg in groups)
                 {
                     groups.Add(spg);
                 }
             }
         }
     }
     );

    return groups;

}

private string GetRoleManagerName()
{
    foreach (KeyValuePair setting in SPContext.Current.Site.WebApplication.IisSettings)
    {
        if (string.IsNullOrEmpty(setting.Value.RoleManager) == false)
            return setting.Value.RoleManager.ToLower();
    }
    return null;
}

private List GetSpAccounts()
{
    List roleAccounts = new List();
    string roleProviderName = GetRoleManagerName();
    foreach (string role in Roles.GetRolesForUser(login.UserName))
    {
        roleAccounts.Add(roleProviderName + ":" + role.ToLower());
    }

    return roleAccounts;
}


// and now I can use it
List roleAccounts = GetSpAccounts();
List groups = GetGroupsForUser(roleAccounts);

但我有一种感觉,我不应该像这样手动执行此操作。 如果仅将角色添加到组中,目标受众将如何工作?

I have built custom Membership and Role providers. Users are some clients that belong to the company and I am using Company as a Role.

I would like to create SharePoint Group and add more companies to it (for example type of industry) and then do redirecting and security by the SPGroup.

How do I retrieve SPGroup for the current logged in user ?
I would like to this in my custom Login page so another problem is how do I retrieve SPUser or SPGroup knowing login name ?

This is what I have now:


private List GetGroupsForUser(List roleAccounts)
{
    List groups = new List();
    SPSecurity.RunWithElevatedPrivileges(
     delegate()
     {
         using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
         {
             SPUserCollection users = site.RootWeb.SiteUsers;
             foreach (string account in roleAccounts)
             {
                 SPGroupCollection accGroups = users[account].Groups;
                 foreach (SPGroup spg in groups)
                 {
                     groups.Add(spg);
                 }
             }
         }
     }
     );

    return groups;

}

private string GetRoleManagerName()
{
    foreach (KeyValuePair setting in SPContext.Current.Site.WebApplication.IisSettings)
    {
        if (string.IsNullOrEmpty(setting.Value.RoleManager) == false)
            return setting.Value.RoleManager.ToLower();
    }
    return null;
}

private List GetSpAccounts()
{
    List roleAccounts = new List();
    string roleProviderName = GetRoleManagerName();
    foreach (string role in Roles.GetRolesForUser(login.UserName))
    {
        roleAccounts.Add(roleProviderName + ":" + role.ToLower());
    }

    return roleAccounts;
}


// and now I can use it
List roleAccounts = GetSpAccounts();
List groups = GetGroupsForUser(roleAccounts);

But I have a felling that I should not have to do this manually like this. How will Target Audience work if only role is added to the group ?

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

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

发布评论

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

评论(1

转瞬即逝 2024-07-22 22:45:28

使用 SPUser 类的 OwnedGroups 属性返回用户拥有的组的集合。

更新误解的问题:

  1. 获取当前登录的用户:SPContext.Current.Web .CurrentUser
  2. 将该用途添加到组中: SPGroup.Users.Add([username],[email],[name],[notes]);

更新,第三次魅力。 那么您想根据用户所拥有的角色找出用户所在的组吗?
这是上述两种尝试的结合:

var matched = from r in SPContext.Current.Web.CurrentUser.Roles
              where r.Name = [Role]
              select r.Groups;

重要提示:角色属性在下一版本的 SharePoint 中将不起作用!
我个人认为 SPContext.Current.Web.CurrentUser.Groups 是一种更简单的方法来确定用户所在的组,但它忽略了您的角色要求。

Use the OwnedGroups property of the SPUser class to return the collection of groups owned by a user.

Update misunderstood the question:

  1. Get the currently logged in user: SPContext.Current.Web.CurrentUser
  2. Add that use to a group: SPGroup.Users.Add([username],[email],[name],[notes]);

Update, third times the charm. So you want to find out what group the user is in based on the roles they have?
It's a bit of a combination of the above two attempts at answering it:

var matched = from r in SPContext.Current.Web.CurrentUser.Roles
              where r.Name = [Role]
              select r.Groups;

Important note that the Roles property won't work in the next version of SharePoint!
Personally I think SPContext.Current.Web.CurrentUser.Groups would be an easier way to figure out what groups the user is in, but it ignores your role requirementment.

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