Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public bool Evaluate(Func <string, bool> roleMatcher, Func <string, bool> userMatcher)
 {
     return(InnerRule.Evaluate(roleMatcher, userMatcher));
 }