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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public static bool Can(string action, object subject)
        {
            var ability = AbilityConfiguration.GetAbility();

            return(ability.Allows(action, subject));
        }
Exemple #4
0
        public static bool CanExecute(object command)
        {
            var ability = AbilityConfiguration.GetAbility();

            return(ability.AllowsExecutionOf(command));
        }