/// <summary>
        /// Test if the current user identity and roles matches
        /// </summary>
        /// <returns></returns>
        public bool Evaluate(ConditionArgs args)
        {
            if (args == null) {
                throw new ArgumentNullException("args");
            }

            // Get user identity 
            IPrincipal userPrincipal = Esapi.SecurityConfiguration.CurrentUser;
            IIdentity userIdentity = (userPrincipal != null ? userPrincipal.Identity : null);
            
            if (userIdentity == null) {
                return false;
            }

            // Get user name
            string userName = userIdentity.Name;
            if (string.IsNullOrEmpty(userName)) {
                return false;
            }

            // Match user name
            if (!_userName.IsMatch(userName)) {
                return false;
            }

            // Match roles
            foreach (string role in _roles) {
                if (!userPrincipal.IsInRole(role)) {
                    return false;
                }
            }

            // Roles match
            return true;
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="args"></param>
		/// <returns></returns>
        public bool Evaluate(ConditionArgs args)
        {
            if (args == null) {
                throw new ArgumentNullException("args");
            }

            //TODO
            return false;
        }
        /// <summary>
        /// Verify URL condition
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool Evaluate(ConditionArgs args)
        {
            if (args == null) {
                throw new ArgumentNullException();
            }
            

            HttpRequest request = HttpContext.Current != null ? HttpContext.Current.Request : null;
            if (request != null) {
                return _url.IsMatch(request.Url.ToString());
            }
            return false;
        }
示例#4
0
        /// <summary>
        /// Check if the context is matched
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private bool IsMatch(RuntimeEventArgs args)
        {
            bool isMatch = true;

            // Check context match cache first
            if (args.MatchCache.TryGetValue(this, out isMatch))
            {
                return(isMatch);
            }

            // Initialize condition arguments
            isMatch = true;
            ConditionArgs conditionArgs = new ConditionArgs()
            {
                RuntimeArgs = args
            };

            // Evaluate each condition
            foreach (IContextCondition contextCondition in _conditions)
            {
                bool result = true;

                // Check condition eval cache first
                if (!args.EvalCache.TryGetValue(contextCondition.Condition, out result))
                {
                    // Eval
                    result = (contextCondition.Condition.Evaluate(conditionArgs) == contextCondition.Result);
                    args.EvalCache.SetValue(contextCondition.Condition, result);
                }

                // Shortcut match if false
                if (!result)
                {
                    isMatch = false;
                    break;
                }
            }

            // Cache
            args.MatchCache.SetValue(this, isMatch);

            // Return
            return(isMatch);
        }
示例#5
0
        /// <summary>
        ///     Check if the context is matched
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private bool IsMatch(RuntimeEventArgs args)
        {
            bool isMatch = true;

            // Check context match cache first
            if (args.MatchCache.TryGetValue(this, out isMatch))
            {
                return isMatch;
            }

            // Initialize condition arguments
            isMatch = true;
            ConditionArgs conditionArgs = new ConditionArgs { RuntimeArgs = args };

            // Evaluate each condition
            foreach (IContextCondition contextCondition in this._conditions)
            {
                bool result = true;

                // Check condition eval cache first
                if (!args.EvalCache.TryGetValue(contextCondition.Condition, out result))
                {
                    // Eval
                    result = (contextCondition.Condition.Evaluate(conditionArgs) == contextCondition.Result);
                    args.EvalCache.SetValue(contextCondition.Condition, result);
                }

                // Shortcut match if false
                if (!result)
                {
                    isMatch = false;
                    break;
                }
            }

            // Cache
            args.MatchCache.SetValue(this, isMatch);

            // Return
            return isMatch;
        }