权限设计 1.0版本

初级构想设计,希望园子里的各位大佬给些意见,能完成一个通用的权限设计

数据表结构原型设计工具:网页在线版 ProcessOn

数据库表模型如下:

权限检测:自定义一个筛选器,在所有需要权限验证的方法上修饰该过滤器,传入对应的权限id,当用户访问对应功能模块时,过滤器首先验证该用户是否拥有该权限

如果没有,则中断请求直接响应

/// <summary>
    /// 权限验证
    /// </summary>
    public class AuthorityCheck : ActionFilterAttribute
    {
        //权限id
        private Guid _Authority { get; set; }//当前登录用户拥有的权限
        private List<Authority> _Authoritys { get; set; }

     //因为在过滤器中修饰只能带入常量的值,而GUID格式的值需要从string转换成Guid,则无法通过编译
        public AuthorityCheck(string Authority)
        {
      //获取session中的管理员权限信息
            _Authoritys = Tools.GetAuthoritiesBySession();
            _Authority = Guid.Parse(Authority);
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //检测该管理员是拥有该模块的对应权限
            if (_Authoritys.Where(p => p.Id == _Authority).FirstOrDefault() == null)
            {
                filterContext.Result = new JsonResult() { Data = new HApiResult() { Code = 200, Msg = "权限不足" }, 
          JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
        }
    }
 

猜你喜欢

转载自www.cnblogs.com/loyking/p/10338998.html