Example #1
0
        /// <summary>
        /// Checks per-property authorization rules.
        /// </summary>
        /// <param name="action">Authorization action.</param>
        /// <param name="element">Property or method to check.</param>
        public bool HasPermission(AuthorizationActions action, Csla.Core.IMemberInfo element)
        {
            if (_suppressRuleChecking)
            {
                return(true);
            }

            if (action == AuthorizationActions.CreateObject ||
                action == AuthorizationActions.DeleteObject ||
                action == AuthorizationActions.GetObject ||
                action == AuthorizationActions.EditObject)
            {
                throw new ArgumentOutOfRangeException("action");
            }

            bool result = true;
            var  rule   =
                TypeAuthRules.Rules.FirstOrDefault(c => c.Element != null && c.Element.Name == element.Name && c.Action == action);

            if (rule != null)
            {
                var context = new AuthorizationContext {
                    Rule = rule, Target = this.Target, TargetType = this.Target.GetType()
                };
                rule.Execute(context);
                result = context.HasPermission;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets a value indicating whether the permission
        /// result can be cached.
        /// </summary>
        /// <param name="action">Authorization action.</param>
        /// <param name="element">Property or method to check.</param>
        public bool CachePermissionResult(AuthorizationActions action, Csla.Core.IMemberInfo element)
        {
            bool result = true;
            var  rule   =
                TypeAuthRules.Rules.
                Where(c => c.Element != null && c.Element.Name == element.Name && c.Action == action).FirstOrDefault();

            if (rule != null)
            {
                result = rule.CacheResult;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Gets a value indicating whether the permission
        /// result can be cached.
        /// </summary>
        /// <param name="action">Authorization action.</param>
        /// <param name="element">Property or method to check.</param>
        public bool CachePermissionResult(AuthorizationActions action, Csla.Core.IMemberInfo element)
        {
            // cannot cache result when suppressRuleChecking as HasPermission is then short circuited to return true.
            if (_suppressRuleChecking)
            {
                return(false);
            }

            bool result = true;
            var  rule   =
                TypeAuthRules.Rules.FirstOrDefault(c => c.Element != null && c.Element.Name == element.Name && c.Action == action);

            if (rule != null)
            {
                result = rule.CacheResult;
            }
            return(result);
        }