Beispiel #1
0
        public static bool CheckPermission(this ClaimsPrincipal user, AppArea area, Access access)
        {
            Claim adminClaim = user.Claims.FirstOrDefault(c => c.Type == AuthConst.AdminClaim);

            if (adminClaim?.Value.Equals(true.ToString()) == true)
            {
                return(true);
            }

            Claim permissionClaim = user.Claims
                                    .FirstOrDefault(c => c.Type == AuthHelper.PermissionToClaim(area.GetAttributeOfType <PermissionNameAttribute>().Name));

            if (permissionClaim == null)
            {
                return(false);
            }

            string accessString = permissionClaim.Value;
            Access userAccess   = AuthHelper.StringToAccess(accessString);

            return((userAccess & access) == access);
        }
Beispiel #2
0
 public static string PermissionToPolicy(AppArea area, Access access)
 {
     return(AuthConst.PolicyPrefix + area.GetAttributeOfType <PermissionNameAttribute>().Name + "," + AccessToString(access));
 }