Ejemplo n.º 1
0
        public bool IsAuthorizedFor(string roleId, string area, string controller, string action)
        {
            var _config   = Services.GetRequiredService <IConfiguration>();
            var superRole = _config["WebOption:SuperRole"].ToString().Split(',');

            if (superRole.Contains(roleId))
            {
                return(true);                           //如果是超管角色则不校验
            }
            //if (AccessorHttpContext.HttpContext.User.Identities.First(u => u.IsAuthenticated).FindFirst(MyClaimTypes.PrivilegeManage.ToString()).Value == "True") return true;

            string permission = string.Empty;

            if (string.IsNullOrEmpty(area))
            {
                permission = (controller + "/" + action).ToLower();
            }
            else
            {
                permission = (area + "/" + controller + "/" + action).ToLower();
            }

            if (!Required.ContainsKey(permission))
            {
                return(true);
            }
            var result = Permissions.ContainsKey(roleId) && Permissions[roleId].Contains(Required[permission]);

            return(result);
        }
        public Boolean IsGrantedFor(Int32?accountId, String?area, String?controller, String?action)
        {
            String permission = $"{area}/{controller}/{action}".ToLower();

            if (!Required.ContainsKey(permission))
            {
                return(true);
            }

            return(Permissions.ContainsKey(accountId ?? 0) && Permissions[accountId !.Value].Contains(Required[permission]));
        }
Ejemplo n.º 3
0
        public Boolean IsAuthorizedFor(Int32?accountId, String area, String controller, String action)
        {
            String permission = (area + "/" + controller + "/" + action).ToLower();

            if (!Required.ContainsKey(permission))
            {
                return(true);
            }

            return(Permissions.ContainsKey(accountId ?? 0) && Permissions[accountId.Value].Contains(Required[permission]));
        }
        public virtual Boolean IsAuthorizedFor(String accountId, String area, String controller, String action)
        {
            String privilege = (area + "/" + controller + "/" + action).ToLower();

            if (!Required.ContainsKey(privilege))
            {
                return(true);
            }

            if (!Privileges.ContainsKey(accountId ?? ""))
            {
                return(false);
            }

            return(Privileges[accountId].Contains(Required[privilege]));
        }