Example #1
0
        public Role(string name, Permission[] permissions)
        {
            if (name == null)
                throw new ArgumentNullException(nameof(name));
            if (permissions == null)
                throw new ArgumentNullException(nameof(permissions));

            Name = name;
            Permissions = permissions
                .ToList()
                .AsReadOnly();
        }
Example #2
0
		public static void DemandPermission(this IPrincipal principal, Permission permission)
		{
			((ClaimsPrincipal)principal).DemandPermission(permission);
		}
Example #3
0
 /// <summary>
 /// Throws exception when principal has not been granted a permission.
 /// </summary>
 /// <param name="principal">The principal</param>
 /// <param name="permission">The permission</param>
 public static void DemandPermission(this ClaimsPrincipal principal, Permission permission)
 {
     if (!HasPermission(principal, permission))
         throw new SecurityException("Principal '" + principal.Identity.Name + "' doesn't have permission '" + permission.Name + "'");
 }
Example #4
0
		public static bool HasPermission(this IPrincipal principal, Permission permission)
		{
			return ((ClaimsPrincipal)principal).HasPermission(permission);
		}
Example #5
0
 /// <summary>
 /// Returns whether principal has been granted a permission.
 /// </summary>
 /// <param name="principal">The principal</param>
 /// <param name="permission">The permission</param>
 /// <returns>True when permission is granted, false otherwise</returns>
 public static bool HasPermission(this ClaimsPrincipal principal, Permission permission)
 {
     return principal.HasClaim(Permission.PermissionClaim, permission.Name);
 }