SECURITY

Sharepoint 2010 : The SharePoint Security Object Model (part 1)

7/24/2012 3:53:16 PM
The SharePoint object model also implements security all the way through.You should have a site collection with three users, namely the administrator, John Doe, and Jane Doe set up in your SharePoint environment. John Doe and Jane Doe are restricted users in your site collection. If you do not have such a site collection, please create such a site collection.

Now examine the class diagram shown in Figure 1.

Figure 1. SPMember based objects in the SharePoint object model

This is a class diagram of some standard SharePoint objects available inside the SharePoint object model. As you can see from this object model, there are two internal classes, namely SPMember and SPPrincipal. SPPrincipal inherits from SPMember. In short, anything that can be given a security right within SharePoint in one way or the other inherits from the SPMember base class. Therefore, there are SPGroup, SPUser, and SPRole. These three objects are what can be given permissions inside of SharePoint. As you will see shortly, SPRole has been deprecated since SharePoint 2007.

Now examine the class diagram shown in Figure 2.

At the heart of this class diagram is an internal abstract base class called SPSecurableObject. Anything inside of SharePoint that be given a permission is an SPSecurableObject. Any SPSecurableObject implements the ISecurableObject interface. Examples of such object are SPWeb, SPSite, SPList, and SPListItem. Let's take the example of SPWeb. SPWeb inherits from SPSecurableObject. Therefore, it is an object that permissions can be given to. The next question is how exactly do you give permissions to this object? The SPWeb object has different properties on it. These properties represent the roles (SPRole), the group's (SPGroup), and the user's (SPUser) that have access to this particular SPWeb. Note that I haven't talked about what level of access yet. I'll discuss this shortly.

Figure 2. SPSecurableObject based objects in the SharePoint object model

Let's take the example of users. There are three properties representing the users that have access to this particular SPWeb. They are SiteUsers, Allusers, and Users.

  • Users: Users explicitly added to the SPWeb.

  • AllUsers: All users that have anything to do with the SPWeb. Users plus users SharePoint saw through Groups.

  • Site Users: Aggregation of AllUsers at the SiteCollection level.

The SiteUsers is a superset of AllUsers is a super set of Users. And all three of these are a collection of the SPUser object. This can be seen in Figure 3.

Figure 3. The relationship between Users, AllUsers, and SiteUsers

Obviously, it is the SiteCollection which is the eventual security boundary. All SPWeb inherit the users from SiteCollection, unless of course such inheritance has been broken. Similarly, there are two properties representing groups, which are Groups and SiteGroups. You can probably guess what these are: the groups are also inherited from parent to SPWeb. As before, both Groups and SiteGroups represent collections of the SPGroup object.

Finally, there is also a property called Roles. This is a collection of type SPRole. However, as mentioned earlier, that SPRole has been deprecated since SharePoint 2007. To replace these, two new objects have been introduced, namely SPRoleDefinition and SPRoleAssignment, which can be seen in the class diagram in Figure 4.

In order to understand these two objects, visit your site collection. In your site collection, go to site settings, and then under users and permissions click site permissions. You should see the various groups and users added to this SiteCollection, along with their associated permission levels. This can be seen in Figure 5.

Figure 4. The permissioning model in SharePoint 2010

Figure 5. The various SharePoint groups

In the ribbon, you will also find a button called permission levels, so click that button. Clicking this button will show you the defined permission levels inside a SiteCollection, as shown in Figure 6.

Figure 6. The various permission levels

Click the full control link and it should show you the various permissions you can configure in any SharePoint permission level. Some of these permissions can be seen in Figure 7.

Figure 7. Details of a permission level

Specifically, in the object model, the permissions you see as check boxes are represented by an Enumerator called SPBasePermissions. SPRoleDefinition represents the levels such as "Full Control", "Contribute", while a Role Assignment contains a collection of Role Definitions.

Any object that inherits from SPPrincipal can be assigned a SPRoleAssignment. This becomes clearer when you observe all the objects in one single class diagram, as shown in Figure 8.

Figure 8. Overall security-related object model in SharePoint 2010

As you can see, the SPRole assignment object has a property on it called Member that points to an SPPrincipal. Therefore, an SPPrincipal such as an SPUser called "smalik", can have a role assignment that points you to two SPRoleDefinitions, "Full Control" and "Design", thereby giving you a union of SPBasePermissions between Full Control and Design. Please read the last sentence one more time because it is incredibly important to remember.

You can verify all the preceding by running the code shown in Listing 1 on your SharePoint site collection.

Example 1. Code to Browse the Security Setup of Your Site Collection
private static void BrowseSecurity()
{
  using (SPSite site = new SPSite(siteUrl))
  {
    SPWeb web = site.OpenWeb();

    Console.WriteLine("\n\nUsers:");
    foreach (SPUser user in web.Users)
    {
      Console.WriteLine(user.Name);
    }

Console.ReadLine();

    Console.WriteLine("\n\n All Users:");
    foreach (SPUser user in web.AllUsers)
    {
      Console.WriteLine(user.Name);
    }
    Console.ReadLine();

    Console.WriteLine("\n\n Site Users:");
    foreach (SPUser user in web.AllUsers)
    {
      Console.WriteLine(user.Name);
    }
    Console.ReadLine();

    Console.WriteLine("\n\n Roles:");
    foreach (SPRole role in web.Roles)
    {
      Console.WriteLine(role.Name);
    }
    Console.ReadLine();

    Console.WriteLine("\n\n Roles Definitions:");
    foreach (SPRoleDefinition roledef in web.RoleDefinitions)
    {
      Console.WriteLine(roledef.Name);
    }
    Console.ReadLine();

    Console.WriteLine("\n\n Roles Assignments:");
    foreach (SPRoleAssignment roleA in web.RoleAssignments)
    {
      Console.WriteLine("The following Role definition bindings exist for " +
roleA.Member.Name);
      foreach (SPRoleDefinition roledef in roleA.RoleDefinitionBindings)
      {
        Console.WriteLine(roledef.Name);
      }
    }
    Console.ReadLine();

    Console.WriteLine("\n\n Groups:");
    foreach (SPGroup group in web.Groups)
    {
      Console.WriteLine(group.Name);
    }
    Console.ReadLine();
  }
}	  
Other  
 
Top 10
Review : Sigma 24mm f/1.4 DG HSM Art
Review : Canon EF11-24mm f/4L USM
Review : Creative Sound Blaster Roar 2
Review : Philips Fidelio M2L
Review : Alienware 17 - Dell's Alienware laptops
Review Smartwatch : Wellograph
Review : Xiaomi Redmi 2
Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
REVIEW
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
Popular Tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8