Saturday, September 12, 2009

Custom Security Trimming in Sharepoint

Recently while working on one of the initiatives, I came across an developement need to restrict permissions on certain portions of an content page as against to the whole page itself. My scenario was I only needed people with Full Control and Contributors permission to see all contents of a page as against to Readers who see only some of the contents on that page. Another common example would be restricting some portion of the master page. I did explored object model role and roleassignment classes nothing looked to be promising and a complete solution for this situation.

Finally after reading through some of the msdn resources, I got aware that there is a security trimming control available to restrict permission on content page.

Wrap the following tag around the content that you want security trimmed, and SharePoint will manage security for you.

<SharePoint:SPSecurityTrimmedControl ID=”SPSecurityTrimmedControlName″ PermissionsString=”BrowseDirectories” runat=”server”>

content that needs to be security trimmed goes here.

</SharePoint:SPSecurityTrimmedControl>



Please note that whats most important here is what goes inside the PermissionsString attribute. Following is a list of possible values:

List Permissions
ManageLists
CancelCheckout
AddListItems
EditListItems
DeleteListItems
ViewListItems
ApproveItems
OpenItems
ViewVersions
DeleteVersions
CreateAlerts
ViewFormPages

Site Permissions
ManagePermissions
ViewUsageData
ManageSubwebs
ManageWeb
AddAndCustomizePages
ApplyThemeAndBorder
ApplyStyleSheets
CreateGroups
BrowseDirectories
CreateSSCSite
ViewPages
EnumeratePermissions
BrowseUserInfo
ManageAlerts
UseRemoteAPIs
UseClientIntegration
Open
EditMyUserInfo

Finally I wanted to let everyone know that I would keep exposing some of these little custom developement tips and would also share some of my developement experience as an when I come across so do keep watching this space.