diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs index b342870270..b84c226fb8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc { + // TODO: Consider making this user a before and after pattern instead of just Invoke, same for all other filter attributes. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public abstract class ActionFilterAttribute : Attribute, IActionFilter, IFilter { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterEndPoint.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterEndPoint.cs index 11c580bbfd..d14b40273c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterEndPoint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterEndPoint.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.Filters { + // This one lives in the Filters namespace, and only intended to be consumed by folks that rewrite the action invoker. public class ReflectedActionFilterEndPoint : IActionFilter { private readonly Func> _coreMethodInvoker; diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionResultFilterEndPoint.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionResultFilterEndPoint.cs index 32ddd87cbd..06836cec5a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionResultFilterEndPoint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionResultFilterEndPoint.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.Filters { + // This one lives in the Filters namespace, and only intended to be consumed by folks that rewrite the action invoker. public class ActionResultFilterEndPoint : IActionResultFilter { public async Task Invoke(ActionResultFilterContext context, Func next) diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterEndPoint.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterEndPoint.cs index 27337e14c9..910cfe0479 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterEndPoint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterEndPoint.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.Filters { + // This one lives in the Filters namespace, and only intended to be consumed by folks that rewrite the action invoker. public class AuthorizationFilterEndPoint : IAuthorizationFilter { public bool EndPointCalled { get; private set; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs index 77a8251174..0fa858f778 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.DependencyInjection; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Filters { public class DefaultFilterProvider : INestedProvider { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterContext.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterContext.cs index 8beab4563d..ebdebbd22f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterContext.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterContext.cs @@ -2,6 +2,8 @@ namespace Microsoft.AspNet.Mvc { + // TODO: For now we have not implemented the ExceptionFilter pipeline, leaving this in until we decide if we are going + // down this path or implementing an ExceptionFilterAttribute being all three filter types with a higher scope. public class ExceptionFilterContext { public ExceptionFilterContext(ActionContext actionContext, Exception exception) diff --git a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionDescriptorProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionDescriptorProvider.cs index 22253e9e99..26dfd5b058 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionDescriptorProvider.cs @@ -127,6 +127,7 @@ namespace Microsoft.AspNet.Mvc return ad; } + // Merge filters, filters with the same order are prioritzed by origin action executes ahead of controller. private List MergeSorted(IFilter[] filtersFromAction, IFilter[] filtersFromController) { var list = new List(); diff --git a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionInvoker.cs index 2f659370e5..9fb91c9a70 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionInvoker.cs @@ -67,14 +67,13 @@ namespace Microsoft.AspNet.Mvc var authZFilters = context.AuthorizationFilters; - bool authZPassed; if (authZFilters != null && authZFilters.Count > 0) { var authZEndPoint = new AuthorizationFilterEndPoint(); authZFilters.Add(authZEndPoint); + var authZContext = new AuthorizationFilterContext(_actionContext); - var authZPipeline = new FilterPipelineBuilder(authZFilters, - authZContext); + var authZPipeline = new FilterPipelineBuilder(authZFilters, authZContext); await authZPipeline.InvokeAsync(); @@ -86,7 +85,8 @@ namespace Microsoft.AspNet.Mvc } else { - actionResult = authZContext.ActionResult ?? new HttpStatusCodeResult(401); + // User cleaned out the result but we failed or short circuited the end point. + actionResult = authZContext.ActionResult ?? new HttpStatusCodeResult(401); } } else @@ -112,7 +112,7 @@ namespace Microsoft.AspNet.Mvc await actionFilterPipeline.InvokeAsync(); - actionResult = (IActionResult)actionFilterContext.Result; + actionResult = actionFilterContext.Result; } } } diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index b5ed63ec43..f191172f4e 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.NestedProviders; using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Net.Runtime;