public void OnAuthorization(AuthorizationContext filterContext) { var ability = AbilityConfiguration.CreateAbility(); if (ability == null) { throw new Exception("CanIMvcConfiguration has not been configured."); } var action = filterContext.ActionDescriptor.ActionName; var subject = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var attributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AuthorizeForAttribute), false) .OfType <AuthorizeForAttribute>(); if (ability.Allows(action, subject) || attributes.Any(a => ability.Allows(a.RequestedActionOnSubject))) { return; } filterContext.Result = resultOnFailedAuthorization(filterContext); }
public static bool Can(string action, object subject) { var ability = AbilityConfiguration.CreateAbility(); return(ability.Allows(action, subject)); }
public static bool CanExecute(object command) { var ability = AbilityConfiguration.CreateAbility(); return(ability.AllowsExecutionOf(command)); }