Sitefinity CMS

Security API of Lists Module Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Lists > Security API of Lists Module

Glossary Item Box

In addition to exposing methods for data-related work, ListModule API also exposes several security functions. The way security works in Sitefinity is very simple. A new instance of GlobalPermission object should be instantiated and Demand() or CheckDemand() functions should be called. The Demand() function will throw a security exception in case currently-logged-in user has no permissions for the given operation, while CheckDemand() will return false if user does NOT have permissions for the requested action, and true if user has the permissions for the required action.


Usually, the CheckDemand() function is used for showing/hiding UI elements (for example, if user has no permissions for creating new list item, we should hide the “Create new list item” button), while Demand() is used prior to executing the actual action.


The way in which the GlobalPermission object is instantiated is very important because, ultimately, this is how we define what kind of permission we are looking for.


ListManager exposes two different ways for getting the GlobalPermission object for ListsModule:

Every GetPermission function returns an object of GlobalPermission, which has Demand() and CheckDemand() functions.


The following examples demonstrate how to use the ListModule Security API:


Get user’s permission to work with the provider with which ListManager has been instantiated:

GetPermission() Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
      
// obtain provider permission for currently-logged-in user
Telerik.Lists.Security.GlobalPermission providerPermission = listManager.GetPermission();
// check if user has permission to work with the current provider
bool userCanWorkWithCurrentProvider = providerPermission.CheckDemand();
// ... perform some logic here based on the user's provider permission
// demand user's permission to work with the current provider
// note that security exception will be thrown if user has no provider permissions
// use CheckDemand() if you only need to check if user has permission
providerPermission.Demand();

 

Get user’s permission to do specific work with the List module:

GetPermission(int requestRights) Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
// obtain deleting permission for currently-logged-in user
Telerik.Lists.Security.GlobalPermission deletePermission = listManager.GetPermission(Telerik.Security.Permissions.CrudRights.Delete);
// check if user has permission to perform delete operations in ListModule
bool userCanDelete = deletePermission.CheckDemand();
// ... perform some logic here based on the user's provider permission
// demand user's permission to perform delete operations in ListModule
// note that security exception will be thrown if user has no such permission
// use CheckDemand() if you only need to check if user has permission
deletePermission.Demand();


 

See Also