public override void OnAuthorization(AuthorizationContext filterContext) { var ability = AbilityConfiguration.GetAbility(); if (ability == null) { throw new Exception("AbilityConfiguration has not been configured."); } var actionAndSubject = GetActionAndSubject(filterContext); if (ability.Allows(actionAndSubject.Action, actionAndSubject.Subject)) { return; } filterContext.Result = resultOnFailedAuthorization(filterContext); }
public override void OnAuthorization(AuthorizationContext filterContext) { var ability = AbilityConfiguration.GetAbility(); if (ability == null) { throw new Exception("AbilityConfiguration has not been configured."); } var command = GetCommandFrom(filterContext); if (ability.AllowsExecutionOf(command)) { return; } throw new SecurityException(exceptionMessage); }
public static bool Can(string action, object subject) { var ability = AbilityConfiguration.GetAbility(); return(ability.Allows(action, subject)); }
public static bool CanExecute(object command) { var ability = AbilityConfiguration.GetAbility(); return(ability.AllowsExecutionOf(command)); }