コード例 #1
0
ファイル: Parser.cs プロジェクト: javadch/VWF.Mvc
        public static bool EvaluateRole(Func <string, bool> roleMatcher, Func <string, bool> userMatcher, string rule)
        {
            RoleParser  parser    = new RoleParser();
            IAccessRule evaluator = parser.Parse(rule);

            return(evaluator.Evaluate(roleMatcher, userMatcher));
        }
コード例 #2
0
        public bool IsAuthorized(AuthorizationContext filterContext, string accessRule, string actionKey, string parentActionKey)
        {
            bool?result = null;

            try
            {
                RoleParser  parser        = new RoleParser();
                IAccessRule accessRuleObj = parser.Parse(accessRule);
                result = accessRuleObj.Evaluate(
                    role => filterContext.HttpContext.User.IsInRole(role)
                    , userName => filterContext.HttpContext.User.Identity.Name.ToLowerInvariant() == userName.ToLowerInvariant()
                    );
            }
            catch
            {
                result = false;
            }
            return(result.HasValue? result.Value: false);
        }
コード例 #3
0
ファイル: GroupRule.cs プロジェクト: javadch/VWF.Mvc
 public bool Evaluate(Func <string, bool> roleMatcher, Func <string, bool> userMatcher)
 {
     return(InnerRule.Evaluate(roleMatcher, userMatcher));
 }