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(); }
public static void DemandPermission(this IPrincipal principal, Permission permission) { ((ClaimsPrincipal)principal).DemandPermission(permission); }
/// <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 + "'"); }
public static bool HasPermission(this IPrincipal principal, Permission permission) { return ((ClaimsPrincipal)principal).HasPermission(permission); }
/// <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); }