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

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

            return(ability.AllowsExecutionOf(command));
        }