Can anyone please explain me with proper examples (not code) the difference between role assignments, role definitions, role definition bindings and roles? The MSDN documentation is not very useful here. Though these are object model classes, I would like to understand them from a SharePoint UI standpoint.
According to this article on MSDN:
A role consists of two parts: a role definition and a role assignment.
So that (mostly?) answers your question of what is a role. But to get into the details:
The role definition, or permission level, is the list of rights associated with the role.
So from a UI perspective, these are things like "Contribute", "Full Control", etc. If you create a new custom permission level (instructions here), you are essentially creating a new role definition.
The role assignment is what ties together the role definition (permission level) with the specific user or group, and the scope that that permission level will be applied to (i.e. site, list, folder, etc.). It gets a little complicated but it kind of works like this:
- The role assignment holds a role definition binding that links the permission level (role definition) to a user or group.
- The object the permissions are going to be applied to (web, list, etc.) holds the role assignment.
So again, from a UI perspective, you are working with role definitions when you are working with permission levels (Contribute, Full Control, etc.). The role definition binding and role assignments happen hand-in-hand when you assign a user or group permissions to a specific object (site, list, folder, etc.).
Hope that clears it up at least a little bit!
Most Probable answer to your question,
Role definition class defines the RoleType of user, it may be reader or contributor.
RoleDefinition roleDefinition = web.RoleDefinitions.GetByType(RoleType.Contributor);
To assign a user to a particular role on a Web site, create a RoleDefinitionBindingCollection object for the Web site context,add a role definition to the binding collection object,
RoleDefinitionBindingCollection roleDefinitionBindingCollection = new RoleDefinitionBindingCollection(clientContext); roleDefinitionCollection.Add(roleDefinition);
and then use the Add(principal,RoleDefinitionBindingCollection) method to add the user together with the binding collection to the role assignments for the Web site.
Role Assignments is use to assign principal and RoleDefinitionBindingCollection using Add property for e.g.