Decorators

This topic contains the following sections.

Decorators are a way of sharing implementation accross multiple data providers. Sitefinity has a built-in decorator for OpenAccess. Unless you have a reason not to use OpenAccess, you won't have to worry about implementing the methods that are mentioned in this topic.

Information in this topic will be useful for provider implementors, as the decorator methods are usually implementing provider methods. This usually happens like this:

public virtual Permission CreatePermission(string permissionSet, Guid objectId, Guid principalId)
{
    if (this.providerDecorator != null)
        return this.providerDecorator.CreatePermission(permissionSet, objectId, principalId);
 
    throw new MissingDecoratorException(this, "CreatePermission<TPermission>(string permissionSet, Guid objectId, Guid principalId)");
}

CRUD operations for permissions

GetPermission

Get a uniquely identified permission

public Permission GetPermission(string permissionSet, Guid objectId, Guid principalId)
public Permission GetPermission(Guid permissionId)

GetPermissions

Get an IQueryable of permissions

public IQueryable<Permission> GetPermissions()

CreatePermission

Create a permission bound to a secured object, permission set and owner.

public Permission CreatePermission(string permissionSet, Guid objectId, Guid principalId)

DeletePermission

Delete a specific permission

public void DeletePermissions(object securedObject)

CreatePermissionInheritanceAssociation

Executes permission inheritance between a parent and a child hierarchical secured objects. The algorithm is as follows:

  • Check if the parent doesn't already have this child. If it is not, then add it to the child permissions of the parent.
    bool isChild =
       !parent
       .PermissionChildren
       .Any(p => p.ObjectId == parent.Id &&
               p.ChildObjectId == child.Id
       );
  • Copy the parent's permissions to the child. Have in mind that a child might already have a permission with the same permission set, object id and object id, so make sure you check against it.
    public virtual void CreatePermissionInheritanceAssociation(ISecuredObject parent, ISecuredObject child)

AddPermissionToObject

Adds a permission to a secured object, and handles inheritance throughout the tree. Implementation follows these steps:

  • Retrieve the object in the context of the current transaction, add the permission and commit
  • Fetch the manager in transaction again, and fetch the added permission in order to add it to the inheritors. Inheritors are got with GetPermissionsInheritors
  • For every inheritor, get its manager (and in transaction if the item's provider - IDataItem.Provider - is of different type and name). Fetch the inheritor in the context of the current open transaction, and add the permission.
  • Finally, commit the transaction.
public virtual void AddPermissionToObject(ISecuredObject securedObject, Permission permission, string tranName)
public virtual void AddPermissionToObject(ISecuredObject securedObject, IManager managerInstance, Permission permission, string tranName)

GetSecurityRoot

Get or create the security root. If security root is to be created, one can specify labeling information and/or supported permission sets.

public SecurityRoot GetSecurityRoot()
public SecurityRoot GetSecurityRoot(bool create)
public SecurityRoot GetSecurityRoot(bool create, IDictionary<string, string> permissionsetObjectTitleResKeys, params string[] permissionSets)

ConvertVoaClassToClrType

Every permission contains information about inheritance. Part of that information is the permission's child object type. If one wanted to shorten that name so that less information is stored in database, this would be the method that returns a CLR type from the shortened CLR type name string.

public Type ConvertVoaClassToClrType(string voaClassName)

ConvertClrTypeVoaClass

Every permission contains information about inheritance. Part of that information is the permission's child object type. If one wanted to shorten that name so that less information is stored in database, this would be the method that creates a shortened type name using a CLR type.

public string ConvertClrTypeVoaClass(Type ClrType)

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK