Removing Role Definitions from a Role Assignment
Role assignments can be exposed ala ISecurableObject and pretty much everything, in order to support Securable Objects (for item level security,etc.), is an ISecurableObject in SharePoint 2007. So, to begin with, we are going to use ISecurableObject to get assignments in combination with a SPPrincipal (representing a user or group) via the GetAssignmentByPrincipal method available off a RoleAssignments collection (it doesn't even require casting!).
-
SPRoleAssignment assignment = ISecurableObject.RoleAssignments.GetAssignmentByPrincipal(SPPrincipal);
Following, a new SPRoleAssignment object is hydrated based on the SPPrincipal object, and that SPRoleAssignment object has a RoleDefinitionBindings collection that exposes the Remove method. Therefore, if you had an array or typed collection of SPRoleDefinitions you wanted to iterate, you could do something like (of course after testing whether the SPRoleAssignment object created is not null):
-
foreach (SPRoleDefinition definition in List<SPRoleDefinition>)
-
{
-
assignment.RoleDefinitionBindings.Remove(definition);
-
}
Gone! :)
Related posts:
- Easy Way To Add Role Assignments
- SharePoint Security Helper Class
- Removing Duplicate SPList Objects From Typed Collections
- Testing Whether A User Has SPBasePermission On SPList Object
- Best Practice: Don’t Iterate SPListItems for IQueryable Support
2 Comments »
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 

[...] Removing Role Definitions from a Role Assignment [...]
Pingback by Links (3/19/2009 « Steve Pietrek - Everything SharePoint) — March 19, 2009 @ 6:40 pm
A static method would have been more helpful, but the content is still useful.
Comment by James R. — April 14, 2009 @ 8:35 am