public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("Configuration is null");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("ActionDescriptor is null");
            }

            IEnumerable<CustomFilterInfo> customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action)).Where(i => !typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType()));
            IEnumerable<CustomFilterInfo> customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller)).Where(i => !typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType()));

            IEnumerable<CustomFilterInfo> customActionOrderedFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action)).Where(i => typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType())).OrderByDescending(i => ((IOrderedFilter)i.Instance).Order);
            IEnumerable<CustomFilterInfo> customControllerOrderedFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller)).Where(i => typeof(IOrderedFilter).IsAssignableFrom(i.Instance.GetType())).OrderByDescending(i => ((IOrderedFilter)i.Instance).Order);

            var filterList = customControllerFilters.Concat(customActionFilters).Concat(customControllerOrderedFilters).Concat(customActionOrderedFilters).Select(i => i.ConvertToFilterInfo());

            return filterList;
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            IEnumerable<FilterInfo> controllerFilters =
                actionDescriptor.ControllerDescriptor.GetFilters()
                    .Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters =
                actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            return controllerFilters.Concat(actionFilters).Select(p =>
            {
                _container.InjectProperties(p.Instance);
                return p;
            });
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
              var actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

              var filters = controllerFilters.Concat(actionFilters);

              foreach (var f in filters)
              {
            // Injection
            _kernel.Inject(f.Instance);
              }

              return filters;
        }
        /// <summary>
        /// Returns the collection of filters associated with <paramref name="actionDescriptor"/>.
        /// </summary>
        /// <remarks>
        /// The implementation invokes <see cref="HttpActionDescriptor.GetFilters()"/> and <see cref="HttpControllerDescriptor.GetFilters()"/>.
        /// </remarks>
        /// <param name="configuration">The configuration. This value is not used.</param>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <returns>A collection of filters.</returns>
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            if (actionDescriptor == null)
            {
                throw Error.ArgumentNull("actionDescriptor");
            }

            IEnumerable<FilterInfo> controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            return controllerFilters.Concat(actionFilters);
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("Configuration is null");                
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("ActionDescriptor is null");
            }

            IEnumerable<CustomFilterInfo> customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));
            IEnumerable<CustomFilterInfo> customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));

            return customControllerFilters.Concat(customActionFilters).OrderBy(i => i).Select(i => i.ConvertToFilterInfo());
        }
Example #6
0
            public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
            {
                if (configuration == null)
                {
                    throw new ArgumentNullException("API Filter Configuration");
                }

                if (actionDescriptor == null)
                {
                    throw new ArgumentNullException("API Filter Action Description");
                }

                foreach (var filter in actionDescriptor.GetFilters())
                {
                    _container.InjectProperties(filter);
                    yield return new FilterInfo(filter, FilterScope.Action);
                }
            }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("actionDescriptor");
            }

            var actionFilters = actionDescriptor.GetFilters().Select(i => new FilterInfo(i, FilterScope.Action));
            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new FilterInfo(i, FilterScope.Controller));;
            var globalFilters = configuration.Filters.Where(i => i.Scope == FilterScope.Global);

            var result = actionFilters.Concat(controllerFilters).Concat(globalFilters).Distinct().ToList();

            object filterMap;
            if (configuration.Properties.TryGetValue("FilterOrder", out filterMap))
            {
                var dictionaryFilterMap = filterMap as Dictionary<Type, int>;
                if (dictionaryFilterMap != null)
                {
                    var orderedFilters = new List<KeyValuePair<FilterInfo, int>>();
                    result.ForEach(x =>
                    {
                        int position;
                        if (dictionaryFilterMap.TryGetValue(x.Instance.GetType(), out position))
                        {
                            orderedFilters.Add(new KeyValuePair<FilterInfo, int>(x, position));
                        }
                        else
                        {
                            orderedFilters.Add(new KeyValuePair<FilterInfo, int>(x, -1));
                        }
                    });

                    result = orderedFilters.OrderBy(x => x.Value).Select(x => x.Key).ToList();
                }
            }

            return result;
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException("actionDescriptor");
            }

            var customActionFilters = actionDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Action));
            var customControllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(i => new CustomFilterInfo(i, FilterScope.Controller));
            var customGlobalFilters = configuration.Filters.Select(i => new CustomFilterInfo(i));

            var result = (customControllerFilters.Concat(customActionFilters).Concat(customGlobalFilters)).OrderBy(i => i).Select(i => i.FilterInfo);
            return result;
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            Requires.NotNull("configuration", configuration);
            Requires.NotNull("actionDescriptor", actionDescriptor);

            IEnumerable<FilterInfo> controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Controller));
            IEnumerable<FilterInfo> actionFilters = actionDescriptor.GetFilters().Select(instance => new FilterInfo(instance, FilterScope.Action));

            var allFilters = controllerFilters.Concat(actionFilters).ToList();

            bool overrideFilterPresent = allFilters.Any(x => x.Instance is IOverrideDefaultAuthLevel);

            if(!overrideFilterPresent)
            {
                allFilters.Add(new FilterInfo(new RequireHostAttribute(), FilterScope.Action));
            }

            return allFilters;
        }
        public IEnumerable<FilterInfo> GetFilters(
            HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            // Taken from ActionDescriptorFilterProvider
            var controllerFilters
                = GetFilterInfos(actionDescriptor.ControllerDescriptor.GetFilters(), FilterScope.Controller);
            var actionFilters
                = GetFilterInfos(actionDescriptor.GetFilters(), FilterScope.Action);
            // Taken from ActionDescriptorFilterProvider

            var controllerProxiedFilters
                = GetFilterInfos(actionDescriptor.ControllerDescriptor.GetCustomAttributes<IServiceAttribute>(),
                                 FilterScope.Controller);
            var actionProxiedFilters
                = GetFilterInfos(actionDescriptor.GetCustomAttributes<IServiceAttribute>(), FilterScope.Action);

            return controllerFilters
                .Concat(controllerProxiedFilters)
                .Concat(actionFilters)
                .Concat(actionProxiedFilters);
        }
        public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (actionDescriptor == null) throw new ArgumentNullException("actionDescriptor");

            var configFilters = configuration.Filters;
            foreach (var configFilter in configFilters)
                _container.InjectProperties(configFilter);

            var controllerFilters = actionDescriptor.ControllerDescriptor.GetFilters().Select(instance =>
            {
                _container.InjectProperties(instance);
                return new FilterInfo(instance, FilterScope.Controller);
            });
            var actionFilters = actionDescriptor.GetFilters().Select(instance =>
            {
                _container.InjectProperties(instance);
                return new FilterInfo(instance, FilterScope.Action);
            });

            return configFilters.Concat(controllerFilters).Concat(actionFilters);
        }
        private string GetAuthorization(HttpActionDescriptor description)
        {
            var filters = description.GetFilters().Union(description.ControllerDescriptor.GetFilters()).ToList();
            var authorizeAdmin = filters.OfType<AuthorizeAdminAttribute>().FirstOrDefault();
            var authorizeUser = filters.OfType<AuthorizeUserAttribute>().FirstOrDefault();
            var authorizeAdminOrCurrentUser = filters.OfType<AuthorizeAdminOrCurrentUser>().FirstOrDefault();
            var authorizeUserOrDevice = filters.OfType<AuthorizeUserOrDeviceAttribute>().FirstOrDefault();

            if (authorizeAdminOrCurrentUser != null)
                return "User or Key (" + authorizeAdminOrCurrentUser.CurrentUserAccessKeyAction + ")";

            if (authorizeAdmin != null)
                return "Administrator or Key (" + authorizeAdmin.AccessKeyAction + ")";

            if (authorizeUser != null)
                return "User" + (authorizeUser.AccessKeyAction == null ? null : " or Key (" + authorizeUser.AccessKeyAction + ")");

            if (authorizeUserOrDevice != null)
                return "User or Device" + (authorizeUserOrDevice.AccessKeyAction == null ? null : " or Key (" + authorizeUserOrDevice.AccessKeyAction + ")");

            return "None";
        }
Example #13
0
        private string GetAuthorization(HttpActionDescriptor description)
        {
            var filters = description.GetFilters().Union(description.ControllerDescriptor.GetFilters()).ToList();
            var authorizeUser = filters.OfType<AuthorizeUserAttribute>().FirstOrDefault();
            var authorizeDevice = filters.OfType<AuthorizeDeviceAttribute>().FirstOrDefault();
            var authorizeDeviceOrUser = filters.OfType<AuthorizeDeviceOrUserAttribute>().FirstOrDefault();

            if (authorizeDeviceOrUser != null)
                return string.Format("Device and User ({0})", authorizeDeviceOrUser.Roles ?? "All Roles");

            if (authorizeUser != null)
                return string.Format("User ({0})", authorizeUser.Roles ?? "All Roles");

            if (authorizeDevice != null)
                return "Device";

            return "None";
        }