Removing OverrideAuthorization attribute and related
This commit is contained in:
@@ -30,7 +30,6 @@ namespace Umbraco.Extensions
|
||||
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder)
|
||||
{
|
||||
builder.Services.AddAntiforgery();
|
||||
builder.Services.AddSingleton<IFilterProvider, OverrideAuthorizationFilterProvider>();
|
||||
|
||||
builder.Services
|
||||
.AddAuthentication() // This just creates a builder, nothing more
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Filters
|
||||
{
|
||||
// TODO: This should probably be deleted, anything requiring this should move to a different controller
|
||||
public class OverrideAuthorizationAttribute : ActionFilterAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures a special type of authorization filter is ignored. Defaults to <see cref="IAuthorizationFilter"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of authorization filter to override. if null then <see cref="IAuthorizationFilter"/> is used.</param>
|
||||
/// <remarks>
|
||||
/// https://stackoverflow.com/questions/33558095/overrideauthorizationattribute-in-asp-net-5
|
||||
/// </remarks>
|
||||
public OverrideAuthorizationAttribute(Type filtersToOverride = null)
|
||||
{
|
||||
FiltersToOverride = filtersToOverride ?? typeof(IAuthorizationFilter);
|
||||
}
|
||||
|
||||
public Type FiltersToOverride { get;}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Filters
|
||||
{
|
||||
// TODO: This should be deleted, anything requiring this should move to a different controller
|
||||
public class OverrideAuthorizationFilterProvider : IFilterProvider, IFilterMetadata
|
||||
{
|
||||
public void OnProvidersExecuted(FilterProviderContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnProvidersExecuting(FilterProviderContext context)
|
||||
{
|
||||
if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
|
||||
{
|
||||
//Does the action have any UmbracoAuthorizeFilter?
|
||||
var overrideFilters = context.Results.Where(filterItem => filterItem.Filter is OverrideAuthorizationAttribute).ToArray();
|
||||
foreach (var overrideFilter in overrideFilters)
|
||||
{
|
||||
context.Results.RemoveAll(filterItem =>
|
||||
//Remove any filter for the type indicated in the UmbracoAuthorizeFilter attribute
|
||||
filterItem.Descriptor.Filter.GetType() == ((OverrideAuthorizationAttribute)overrideFilter.Filter).FiltersToOverride &&
|
||||
//Remove filters with lower scope (ie controller) than the override filter (ie action method)
|
||||
filterItem.Descriptor.Scope < overrideFilter.Descriptor.Scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//all framework providers have negative orders, so ours will come later
|
||||
public int Order => 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user