Code cleanup
This commit is contained in:
parent
7cf40c8a50
commit
1bcd35f5f1
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
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)]
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||||
public abstract class ActionFilterAttribute : Attribute, IActionFilter, IFilter
|
public abstract class ActionFilterAttribute : Attribute, IActionFilter, IFilter
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Filters
|
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
|
public class ReflectedActionFilterEndPoint : IActionFilter
|
||||||
{
|
{
|
||||||
private readonly Func<object[], Task<object>> _coreMethodInvoker;
|
private readonly Func<object[], Task<object>> _coreMethodInvoker;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Filters
|
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 class ActionResultFilterEndPoint : IActionResultFilter
|
||||||
{
|
{
|
||||||
public async Task Invoke(ActionResultFilterContext context, Func<Task> next)
|
public async Task Invoke(ActionResultFilterContext context, Func<Task> next)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Filters
|
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 class AuthorizationFilterEndPoint : IAuthorizationFilter
|
||||||
{
|
{
|
||||||
public bool EndPointCalled { get; private set; }
|
public bool EndPointCalled { get; private set; }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc.Filters
|
||||||
{
|
{
|
||||||
public class DefaultFilterProvider : INestedProvider<FilterProviderContext>
|
public class DefaultFilterProvider : INestedProvider<FilterProviderContext>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
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 class ExceptionFilterContext
|
||||||
{
|
{
|
||||||
public ExceptionFilterContext(ActionContext actionContext, Exception exception)
|
public ExceptionFilterContext(ActionContext actionContext, Exception exception)
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return ad;
|
return ad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge filters, filters with the same order are prioritzed by origin action executes ahead of controller.
|
||||||
private List<IFilter> MergeSorted(IFilter[] filtersFromAction, IFilter[] filtersFromController)
|
private List<IFilter> MergeSorted(IFilter[] filtersFromAction, IFilter[] filtersFromController)
|
||||||
{
|
{
|
||||||
var list = new List<IFilter>();
|
var list = new List<IFilter>();
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
var authZFilters = context.AuthorizationFilters;
|
var authZFilters = context.AuthorizationFilters;
|
||||||
|
|
||||||
bool authZPassed;
|
|
||||||
if (authZFilters != null && authZFilters.Count > 0)
|
if (authZFilters != null && authZFilters.Count > 0)
|
||||||
{
|
{
|
||||||
var authZEndPoint = new AuthorizationFilterEndPoint();
|
var authZEndPoint = new AuthorizationFilterEndPoint();
|
||||||
authZFilters.Add(authZEndPoint);
|
authZFilters.Add(authZEndPoint);
|
||||||
|
|
||||||
var authZContext = new AuthorizationFilterContext(_actionContext);
|
var authZContext = new AuthorizationFilterContext(_actionContext);
|
||||||
var authZPipeline = new FilterPipelineBuilder<AuthorizationFilterContext>(authZFilters,
|
var authZPipeline = new FilterPipelineBuilder<AuthorizationFilterContext>(authZFilters, authZContext);
|
||||||
authZContext);
|
|
||||||
|
|
||||||
await authZPipeline.InvokeAsync();
|
await authZPipeline.InvokeAsync();
|
||||||
|
|
||||||
|
|
@ -86,7 +85,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
|
|
@ -112,7 +112,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
await actionFilterPipeline.InvokeAsync();
|
await actionFilterPipeline.InvokeAsync();
|
||||||
|
|
||||||
actionResult = (IActionResult)actionFilterContext.Result;
|
actionResult = actionFilterContext.Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using Microsoft.AspNet.ConfigurationModel;
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.DependencyInjection.NestedProviders;
|
using Microsoft.AspNet.DependencyInjection.NestedProviders;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileSystems;
|
||||||
|
using Microsoft.AspNet.Mvc.Filters;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.Net.Runtime;
|
using Microsoft.Net.Runtime;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue