예제 #1
0
        public FilterItem(FilterDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            Descriptor = descriptor;
        }
예제 #2
0
        public FilterItem(FilterDescriptor descriptor, IFilterMetadata filter)
            : this(descriptor)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            Filter = filter;
        }
예제 #3
0
        private void InsertControllerAsFilter(FilterProviderContext context, IFilter controllerFilter)
        {
            var descriptor = new FilterDescriptor(controllerFilter, FilterScope.Controller);
            var item       = new FilterItem(descriptor, controllerFilter);

            // BinarySearch will return the index of where the item _should_be_ in the list.
            //
            // If index > 0:
            //      Other items in the list have the same order and scope - the item was 'found'.
            //
            // If index < 0:
            //      No other items in the list have the same order and scope - the item was not 'found'
            //      Index will be the bitwise compliment of of the 'right' location.
            var index = context.Results.BinarySearch(item, FilterItemOrderComparer.Comparer);

            if (index < 0)
            {
                index = ~index;
            }

            context.Results.Insert(index, item);
        }
        private AuthorizationContext GetAuthorizationContext(
            FilterDescriptor[] filterDescriptors,
            RequestHeaders headers = null,
            bool isPreflight = false)
        {

            // HttpContext
            var httpContext = new DefaultHttpContext();
            if (headers != null)
            {
                httpContext.Request.Headers.Add(CorsConstants.AccessControlRequestHeaders, headers.Headers.Split(','));
                httpContext.Request.Headers.Add(CorsConstants.AccessControlRequestMethod,  new[] { headers.Method });
                httpContext.Request.Headers.Add(CorsConstants.AccessControlExposeHeaders, headers.ExposedHeaders.Split(','));
                httpContext.Request.Headers.Add(CorsConstants.Origin, new[] { headers.Origin });
            }

            var services = new ServiceCollection();
            services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
            httpContext.RequestServices = services.BuildServiceProvider();

            var method = isPreflight ? CorsConstants.PreflightHttpMethod : "GET";
            httpContext.Request.Method = method;

            // AuthorizationContext
            var actionContext = new ActionContext(
                httpContext: httpContext,
                routeData: new RouteData(),
                actionDescriptor: new ActionDescriptor() { FilterDescriptors = filterDescriptors });

            var authorizationContext = new AuthorizationContext(
                actionContext,
                filterDescriptors.Select(filter => filter.Filter).ToList()
            );

            return authorizationContext;
        }
예제 #5
0
 public FilterItem([NotNull] FilterDescriptor descriptor, [NotNull] IFilterMetadata filter)
     : this(descriptor)
 {
     Filter = filter;
 }
예제 #6
0
 public FilterItem([NotNull] FilterDescriptor descriptor)
 {
     Descriptor = descriptor;
 }