简体   繁体   English

如何在SharePoint文档库上设置独占权限?

[英]how to set exclusive permissions on a SharePoint document library?

I have a requirement to lock down access to a SharePoint library: Only users that belong to all the groups associated with the library should have read access; 我要求锁定对SharePoint库的访问权限:只有属于与该库相关联的所有组的用户才应具有读取访问权限; others should not be allowed to read. 不应允许他人阅读。

Let's say I have a document library that concerns three projects: 假设我有一个涉及三个项目的文档库:

12345
13579
24680

I have users that belong to one or more projects: 我的用户属于一个或多个项目:

Joe:   12345, 24680
Jane:  13579, 24680
Jim:   24680
Harry: 12345, 13579, 24680

I need to restrict access to this library to only users who belong to ALL projects. 我需要将访问该库的权限限制为仅属于所有项目的用户。 Ie, only Harry should have access; 即,只有哈利才可以访问; the others should be denied. 其他应该被拒绝。 We'd use SharePoint groups named after each project to represent the 'belongs' relationship. 我们将使用以每个项目命名的SharePoint组来表示“归属”关系。

Edited with more detail: 详细编辑:

We plan to create the doc lib and set up the initial security via a workflow. 我们计划创建文档库并通过工作流设置初始安全性。 However, more projects may be associated with the doclib after it's created, based on info entered in a form, and people can get moved in and out of project groups by admins (eg for promotions, new hires....) 但是,基于doclib表单中输入的信息,文档库在创建后可能会与更多项目相关联,并且管理员可以将人员移入或移出项目组(例如,晋升,新聘人员...。)

For now, if a form submission adds a new project after inital setup, an admin will probably create a new group if necessary, and assign it access to the doclib. 目前,如果表单提交在初始设置后添加了新项目,则管理员可能会在必要时创建一个新组,并将其访问权限分配给doclib。 Eventually, we'd do this in a workflow. 最终,我们将在工作流中执行此操作。

Currently, we're writing code to assign the initial security state for the site: 当前,我们正在编写代码以分配站点的初始安全状态:

We scan a list of projects entered by a user into a form, create new project groups if necessary, create a site and a couple of doclibs, break role inheritance and assign our groups read access to the doclib. 我们扫描用户输入到表单中的项目列表,如有必要,创建新的项目组,创建站点和几个doclib,中断角色继承,并为我们的组分配对doclib的读取权限。 We add some users to each project group. 我们向每个项目组添加一些用户。

At this point, any of those users have read access. 此时,所有这些用户都具有读取访问权限。 What we don't know how to do is restrict access to only users who are members of all the groups. 我们不知道该怎么做,就是将访问权限限制为仅属于所有组成员的用户。

You've made it hard on yourself.. SharePoint nor AD works this way, I'd go back to the drawing board because this will only cause pain ;) 您已使自己烦恼了。SharePoint和AD都采用这种方式,我会回到画板上,因为这只会造成痛苦;)

I would decouple management of groups and their assignment to document libraries and sync rights throughout SharePoint like Koen mentioned. 我会像Koen提到的那样,将组的管理及其对文档库的分配和对整个SharePoint的同步权限分离。 eg you manage group membership separate from the groups you use to connect them to document libraries. 例如,您可以独立于用于将其连接到文档库的组来管理组成员身份。 Then you need a process to enumerate over these separate groups and assign the users in there to the document libraries individually according to your business rules. 然后,您需要一个过程来枚举这些单独的组,并根据您的业务规则将其中的用户分别分配给文档库。 Brittle at best. 最好是脆。

You could set your document library to BreakRoleInheritance and set permissions to your items individually. 您可以将文档库设置为BreakRoleInheritance并分别设置对项目的权限。

This is a example: 这是一个例子:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite("http://..."))
    {
        using (SPWeb web = site.OpenWeb())
        {
            web.AllowUnsafeUpdates = true;
            SPRoleType role = SPRoleType.Reader;
            SPRoleAssignment assignment = 
                new SPRoleAssignment(web.Groups["groupname"]);
            assignment.RoleDefinitionBindings.Add(
                web.RoleDefinitions.GetByType(role));

            SPList list = web.Lists["name"];
            SPListItemCollection items = list.GetItems(new SPQuery());
            foreach (SPListItem item in items)
            {
                if (!item.HasUniqueRoleAssignments)
                     item.BreakRoleInheritance(false);

                while (item.RoleAssignments.Count != 0) // remove all
                       item.RoleAssignments.Remove(
                       item.RoleAssignments.Count - 1);

                item.RoleAssignments.Add(assignment);
            }
        }
    }
});

The only way I can think of achieving this is to create a custom timer job that updates your document library every day by deleting all the rights, and then adding them again overnight. 我能想到的唯一方法是创建一个自定义计时器作业,该作业每天都会通过删除所有权限,然后在一夜之间再次添加它们来更新您的文档库。 That would mean that people who join those projects will have to wait 1 day to get acces. 这意味着加入这些项目的人将不得不等待1天才能获得访问权限。 You would just create a collection of all the users of group1, and check for each one if they exist in group 2, 3, ... and if they don't remove them from the collection. 您只需创建一个所有group1用户的集合,并检查每个用户是否存在于第2、3,...组中,以及是否没有将他们从集合中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM