# Grant and deny permissions

When creating permission, you can grant or deny actions for specific user or role. Granting an action is permitting users to perform it on the specified `ISecuredObject` item. Denying an action is prohibiting it for the users. For more information, see [Overview: Permissions](https://www.progress.com/documentation/sitefinity-cms/overview-permissions) in Installation and administration guide.

To store the granted or denied actions for the secured object, the permissions use integral bit masks. For more information, see [For developers: Permissions API](https://www.progress.com/documentation/sitefinity-cms/for-developers-permissions-api). Sitefinity CMS provides you with helper methods in the `Permissions` class that you use to grant and deny permissions.

When granting and denying actions, first, you must create or get the permission. For more information, see [For developers: CRUD operations with permissions](https://www.progress.com/documentation/sitefinity-cms/for-developers-crud-operations-with-permissions).\
After you get the permissions, to grant actions, you use the `GrantActions` method. The first parameter of the method defines whether to remove any previously granted actions. If set to `true`, the specified actions are granted without removing any previously set actions. If set to `false` any previously set actions are cleared and the new actions are set. The next parameters of `GrantActions` specify the granted actions.

The following example grants the view, create and delete blog actions for `permission`.

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.Security.Permissions.GrantingDenyingPermissions
{
   public partial class PermissionsApiSnippets
   {
       public static void GrantPermissionsForUser(string userName)
       {
           UserManager usersManager = UserManager.GetManager();
           BlogsManager blogsManager = BlogsManager.GetManager();

           Permission permission = blogsManager.GetPermission(
               BlogsPermissions.Sets.Blog.SetName,
               blogsManager.GetSecurityRoot(false).Id,
               usersManager.GetUser(userName).Id
           );

           permission.GrantActions(
               false,
               BlogsPermissions.Sets.Blog.View,
               BlogsPermissions.Sets.Blog.Create,
               BlogsPermissions.Sets.Blog.Delete
           );

           blogsManager.SaveChanges();
       }
   }
}

```

To reset specific granted actions, you use the `UngrantActions` method.\
The following example ungrants the delete blog action for `permission`.

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.Security.Permissions.GrantingDenyingPermissions
{
   public partial class PermissionsApiSnippets
   {
       public static void UngrantPermissionsForUser(string userName)
       {
           UserManager usersManager = UserManager.GetManager();
           BlogsManager blogsManager = BlogsManager.GetManager();

           Permission permission = blogsManager.GetPermission(
               BlogsPermissions.Sets.Blog.SetName,
               blogsManager.GetSecurityRoot(false).Id,
               usersManager.GetUser(userName).Id
           );

           permission.UngrantActions(
               BlogsPermissions.Sets.Blog.Delete
           );

           blogsManager.SaveChanges();
       }
   }
}

```

To deny actions, you use the `DenyActions` method. The first parameter of the method defines whether to remove any previously denied actions. If set to `true`, the specified actions are denied without removing any previously set actions. If set to `false` any previously set actions are cleared and the new actions are set. The next parameters of `DenyActions` specify the denied actions. \
The following example denies the change permissions blog action for `permission`.

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.Security.Permissions.GrantingDenyingPermissions
{
   public partial class PermissionsApiSnippets
   {
       public static void DenyPermissionsForUser(string userName)
       {
           UserManager usersManager = UserManager.GetManager();
           BlogsManager blogsManager = BlogsManager.GetManager();

           Permission permission = blogsManager.GetPermission(
               BlogsPermissions.Sets.Blog.SetName,
               blogsManager.GetSecurityRoot(false).Id,
               usersManager.GetUser(userName).Id
           );

           permission.DenyActions(
               false,
               BlogsPermissions.Sets.Blog.ChangePermissions
           );

           blogsManager.SaveChanges();
       }
   }
}

```

To reset specific denied actions, you use the `UndenyActions` method.  \
The following example undenies the change permissions blog action for `permission`.

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.Security.Permissions.GrantingDenyingPermissions
{
   public partial class PermissionsApiSnippets
   {
       public static void UndenyPermissionsForUser(string userName)
       {
           UserManager usersManager = UserManager.GetManager();
           BlogsManager blogsManager = BlogsManager.GetManager();

           Permission permission = blogsManager.GetPermission(
               BlogsPermissions.Sets.Blog.SetName,
               blogsManager.GetSecurityRoot(false).Id,
               usersManager.GetUser(userName).Id
           );

           permission.UndenyActions(
               BlogsPermissions.Sets.Blog.ChangePermissions
           );

           blogsManager.SaveChanges();
       }
   }
}

```
