protected virtual bool VerifyControllerAttributes(ISiteMapNode node, Type controllerType, ControllerContext controllerContext)
        {
            // Get controller descriptor
            var controllerDescriptor = controllerDescriptorFactory.Create(controllerType);

            if (controllerDescriptor == null)
            {
                return(true);
            }

            // Get action descriptor
            var actionDescriptor = this.GetActionDescriptor(node.Action, controllerDescriptor, controllerContext);

            if (actionDescriptor == null)
            {
                return(true);
            }

            // Fixes #130 - Check whether we have an AllowAnonymous Attribute
            var ignoreAuthorization = this.HasAllowAnonymousAttribute(actionDescriptor);

            if (ignoreAuthorization)
            {
                return(true);
            }

            // Verify security
            var authorizeAttributes = this.GetAuthorizeAttributes(actionDescriptor, controllerContext);

            return(this.VerifyAuthorizeAttributes(authorizeAttributes, controllerContext));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the action method parameters.
        /// </summary>
        /// <param name="controllerTypeResolver">The controller type resolver.</param>
        /// <param name="areaName">Name of the area.</param>
        /// <param name="controllerName">Name of the controller.</param>
        /// <param name="actionMethodName">Name of the action method.</param>
        /// <returns>
        /// A action method parameters represented as a <see cref="string"/> instance
        /// </returns>
        public IEnumerable <string> ResolveActionMethodParameters(IControllerTypeResolver controllerTypeResolver,
                                                                  string areaName, string controllerName,
                                                                  string actionMethodName)
        {
            // Is the request cached?
            string cacheKey = areaName + "_" + controllerName + "_" + actionMethodName;

            if (Cache.ContainsKey(cacheKey))
            {
                return(Cache[cacheKey]);
            }

            // Get controller type
            Type controllerType = controllerTypeResolver.ResolveControllerType(areaName, controllerName);

            // Get action method information
            var actionParameters = new List <string>();

            if (controllerType != null)
            {
                var controllerDescriptor = controllerDescriptorFactory.Create(controllerType);

                ActionDescriptor[] actionDescriptors = controllerDescriptor.GetCanonicalActions()
                                                       .Where(a => a.ActionName == actionMethodName).ToArray();

                if (actionDescriptors != null && actionDescriptors.Length > 0)
                {
                    foreach (ActionDescriptor actionDescriptor in actionDescriptors)
                    {
                        actionParameters.AddRange(actionDescriptor.GetParameters().Select(p => p.ParameterName));
                    }
                }
            }

            // Cache the result
            if (!Cache.ContainsKey(cacheKey))
            {
                try
                {
                    Cache.Add(cacheKey, actionParameters);
                }
                catch (ArgumentException)
                {
                    // Nomnomnom... We're intentionally eating it here
                }
            }

            // Return
            return(actionParameters);
        }
        protected virtual bool VerifyControllerAttributes(ISiteMapNode node, Type controllerType, ControllerContext controllerContext)
        {
            // Get controller descriptor
            var controllerDescriptor = controllerDescriptorFactory.Create(controllerType);

            if (controllerDescriptor == null)
            {
                return(true);
            }

            // Get action descriptor
            var actionDescriptor = this.GetActionDescriptor(node.Action, controllerDescriptor, controllerContext);

            if (actionDescriptor == null)
            {
                return(true);
            }

            // Verify security
            var authorizeAttributes = this.GetAuthorizeAttributes(actionDescriptor, controllerContext);

            return(this.VerifyAuthorizeAttributes(authorizeAttributes, controllerContext, actionDescriptor));
        }