Browse Source

Merge pull request #18638 from abpframework/DisableInterceptorAndFilter

Introduce the `DisableAbpFeatures`.
pull/18891/head
Halil İbrahim Kalkan 2 years ago
committed by GitHub
parent
commit
4400d0de05
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/MultiTenancyMiddleware.cs
  2. 5
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
  3. 31
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs
  4. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs
  5. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs
  6. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs
  7. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs
  8. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs
  9. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs
  10. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs
  11. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs
  12. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Response/AbpNoContentActionFilter.cs
  13. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs
  14. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs
  15. 3
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs
  16. 5
      framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogMiddleware.cs
  17. 5
      framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs
  18. 7
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAuditingMiddleware.cs
  19. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs
  20. 6
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/IAbpFilter.cs
  21. 19
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs
  22. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs
  23. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/AbpClaimsMapMiddleware.cs
  24. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/AbpDynamicClaimsMiddleware.cs
  25. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs
  26. 7
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AbpUnitOfWorkMiddleware.cs
  27. 17
      framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
  28. 25
      framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs
  29. 5
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/FakeAuthenticationMiddleware.cs
  30. 74
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Filters/MvcDisableAbpFeaturesAttribute_Tests.cs
  31. 31
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs
  32. 11
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AlwaysExceptionAsyncInterceptor.cs
  33. 41
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/DisableInterceptionTargetClass.cs

5
framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/MultiTenancyMiddleware.cs

@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
@ -15,7 +16,7 @@ using Volo.Abp.Settings;
namespace Volo.Abp.AspNetCore.MultiTenancy;
public class MultiTenancyMiddleware : IMiddleware, ITransientDependency
public class MultiTenancyMiddleware : AbpMiddlewareBase, ITransientDependency
{
public ILogger<MultiTenancyMiddleware> Logger { get; set; }
@ -38,7 +39,7 @@ public class MultiTenancyMiddleware : IMiddleware, ITransientDependency
_options = options.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
TenantConfiguration? tenant = null;
try

5
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

@ -14,6 +14,7 @@ using System.Linq;
using System.Net;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.RazorPages;
@ -25,6 +26,7 @@ using Volo.Abp.ApiVersioning;
using Volo.Abp.Application;
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
using Volo.Abp.AspNetCore.Mvc.ApiExploring;
using Volo.Abp.AspNetCore.Mvc.ApplicationModels;
using Volo.Abp.AspNetCore.Mvc.Conventions;
using Volo.Abp.AspNetCore.Mvc.DataAnnotations;
using Volo.Abp.AspNetCore.Mvc.DependencyInjection;
@ -176,6 +178,7 @@ public class AbpAspNetCoreMvcModule : AbpModule
context.Services.Replace(ServiceDescriptor.Singleton<IValidationAttributeAdapterProvider, AbpValidationAttributeAdapterProvider>());
context.Services.AddSingleton<ValidationAttributeAdapterProvider>();
context.Services.TryAddEnumerable(ServiceDescriptor.Transient<IActionDescriptorProvider, AbpMvcActionDescriptorProvider>());
context.Services.AddOptions<MvcOptions>()
.Configure<IServiceProvider>((mvcOptions, serviceProvider) =>
{
@ -247,7 +250,7 @@ public class AbpAspNetCoreMvcModule : AbpModule
.Distinct();
AddToApplicationParts(partManager, controllerAssemblies);
var additionalAssemblies = moduleContainer
.Modules
.SelectMany(m => m.GetAdditionalAssemblies())

31
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs

@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Controllers;
using Volo.Abp.AspNetCore.Filters;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationModels;
public class AbpMvcActionDescriptorProvider : IActionDescriptorProvider
{
public virtual int Order => -1000 + 10;
public virtual void OnProvidersExecuting(ActionDescriptorProviderContext context)
{
}
public virtual void OnProvidersExecuted(ActionDescriptorProviderContext context)
{
foreach (var action in context.Results.Where(x => x is ControllerActionDescriptor).Cast<ControllerActionDescriptor>())
{
var disableAbpFeaturesAttribute = action.ControllerTypeInfo.GetCustomAttribute<DisableAbpFeaturesAttribute>(true);
if (disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMvcFilters)
{
action.FilterDescriptors.RemoveAll(x => x.Filter is ServiceFilterAttribute serviceFilterAttribute &&
typeof(IAbpFilter).IsAssignableFrom(serviceFilterAttribute.ServiceType));
}
}
}
}

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs

@ -5,12 +5,13 @@ using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.Auditing;
public class AbpAuditActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpAuditActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs

@ -5,12 +5,13 @@ using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.Auditing;
public class AbpAuditPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpAuditPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs

@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
@ -18,7 +19,7 @@ using Volo.Abp.Json;
namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
public class AbpExceptionFilter : IAsyncExceptionFilter, ITransientDependency
public class AbpExceptionFilter : IAsyncExceptionFilter, IAbpFilter, ITransientDependency
{
public virtual async Task OnExceptionAsync(ExceptionContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs

@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
@ -18,7 +19,7 @@ using Volo.Abp.Json;
namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
public class AbpExceptionPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpExceptionPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs

@ -2,12 +2,13 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
namespace Volo.Abp.AspNetCore.Mvc.Features;
public class AbpFeatureActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpFeatureActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs

@ -2,12 +2,13 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
namespace Volo.Abp.AspNetCore.Mvc.Features;
public class AbpFeaturePageFilter : IAsyncPageFilter, ITransientDependency
public class AbpFeaturePageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs

@ -6,12 +6,13 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.GlobalFeatures;
namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures;
public class GlobalFeatureActionFilter : IAsyncActionFilter, ITransientDependency
public class GlobalFeatureActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs

@ -6,12 +6,13 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.GlobalFeatures;
namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures;
public class GlobalFeaturePageFilter : IAsyncPageFilter, ITransientDependency
public class GlobalFeaturePageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Response/AbpNoContentActionFilter.cs

@ -2,11 +2,12 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.Response;
public class AbpNoContentActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpNoContentActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs

@ -4,12 +4,13 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Mvc.Uow;
public class AbpUowActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpUowActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs

@ -4,13 +4,14 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.AspNetCore.Uow;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Mvc.Uow;
public class AbpUowPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpUowPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{

3
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs

@ -3,13 +3,14 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Reflection;
using Volo.Abp.Validation;
namespace Volo.Abp.AspNetCore.Mvc.Validation;
public class AbpValidationActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpValidationActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{

5
framework/src/Volo.Abp.AspNetCore.Serilog/Volo/Abp/AspNetCore/Serilog/AbpSerilogMiddleware.cs

@ -5,6 +5,7 @@ using Microsoft.Extensions.Options;
using Serilog.Context;
using Serilog.Core;
using Serilog.Core.Enrichers;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
@ -13,7 +14,7 @@ using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Serilog;
public class AbpSerilogMiddleware : IMiddleware, ITransientDependency
public class AbpSerilogMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly ICurrentClient _currentClient;
private readonly ICurrentTenant _currentTenant;
@ -35,7 +36,7 @@ public class AbpSerilogMiddleware : IMiddleware, ITransientDependency
_options = options.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var enrichers = new List<ILogEventEnricher>();

5
framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs

@ -4,11 +4,12 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
namespace Microsoft.AspNetCore.RequestLocalization;
public class AbpRequestLocalizationMiddleware : IMiddleware, ITransientDependency
public class AbpRequestLocalizationMiddleware : AbpMiddlewareBase, ITransientDependency
{
public const string HttpContextItemName = "__AbpSetCultureCookie";
@ -23,7 +24,7 @@ public class AbpRequestLocalizationMiddleware : IMiddleware, ITransientDependenc
_loggerFactory = loggerFactory;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var middleware = new RequestLocalizationMiddleware(
next,

7
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAuditingMiddleware.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
@ -11,7 +12,7 @@ using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Auditing;
public class AbpAuditingMiddleware : IMiddleware, ITransientDependency
public class AbpAuditingMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly IAuditingManager _auditingManager;
protected AbpAuditingOptions AuditingOptions { get; }
@ -34,9 +35,9 @@ public class AbpAuditingMiddleware : IMiddleware, ITransientDependency
AspNetCoreAuditingOptions = aspNetCoreAuditingOptions.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (!AuditingOptions.IsEnabled || IsIgnoredUrl(context))
if (await ShouldSkipAsync(context, next) || !AuditingOptions.IsEnabled || IsIgnoredUrl(context))
{
await next(context);
return;

5
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpExceptionHandlingMiddleware.cs

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
@ -14,7 +15,7 @@ using Volo.Abp.Json;
namespace Volo.Abp.AspNetCore.ExceptionHandling;
public class AbpExceptionHandlingMiddleware : IMiddleware, ITransientDependency
public class AbpExceptionHandlingMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly ILogger<AbpExceptionHandlingMiddleware> _logger;
@ -27,7 +28,7 @@ public class AbpExceptionHandlingMiddleware : IMiddleware, ITransientDependency
_clearCacheHeadersDelegate = ClearCacheHeaders;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{

6
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/IAbpFilter.cs

@ -0,0 +1,6 @@
namespace Volo.Abp.AspNetCore.Filters;
public interface IAbpFilter
{
}

19
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs

@ -0,0 +1,19 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Controllers;
namespace Volo.Abp.AspNetCore.Middleware;
public abstract class AbpMiddlewareBase : IMiddleware
{
protected Task<bool> ShouldSkipAsync(HttpContext context, RequestDelegate next)
{
var endpoint = context.GetEndpoint();
var controllerActionDescriptor = endpoint?.Metadata.GetMetadata<ControllerActionDescriptor>();
var disableAbpFeaturesAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute<DisableAbpFeaturesAttribute>();
return Task.FromResult(disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMiddleware);
}
public abstract Task InvokeAsync(HttpContext context, RequestDelegate next);
}

5
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs

@ -5,11 +5,12 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Security;
public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency
public class AbpSecurityHeadersMiddleware : AbpMiddlewareBase, ITransientDependency
{
public IOptions<AbpSecurityHeadersOptions> Options { get; set; }
protected const string ScriptSrcKey = "script-src";
@ -20,7 +21,7 @@ public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency
Options = options;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
/*X-Content-Type-Options header tells the browser to not try and “guess” what a mimetype of a resource might be, and to just take what mimetype the server has returned as fact.*/
AddHeader(context, "X-Content-Type-Options", "nosniff");

5
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/AbpClaimsMapMiddleware.cs

@ -4,14 +4,15 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.AspNetCore.Security.Claims;
public class AbpClaimsMapMiddleware : IMiddleware, ITransientDependency
public class AbpClaimsMapMiddleware : AbpMiddlewareBase, ITransientDependency
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var currentPrincipalAccessor = context.RequestServices
.GetRequiredService<ICurrentPrincipalAccessor>();

5
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/Claims/AbpDynamicClaimsMiddleware.cs

@ -2,14 +2,15 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.AspNetCore.Security.Claims;
public class AbpDynamicClaimsMiddleware : IMiddleware, ITransientDependency
public class AbpDynamicClaimsMiddleware : AbpMiddlewareBase, ITransientDependency
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (context.User.Identity?.IsAuthenticated == true)
{

5
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs

@ -3,12 +3,13 @@ using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Tracing;
namespace Volo.Abp.AspNetCore.Tracing;
public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency
public class AbpCorrelationIdMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly AbpCorrelationIdOptions _options;
private readonly ICorrelationIdProvider _correlationIdProvider;
@ -20,7 +21,7 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency
_correlationIdProvider = correlationIdProvider;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var correlationId = GetCorrelationIdFromRequest(context);
using (_correlationIdProvider.Change(correlationId))

7
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AbpUnitOfWorkMiddleware.cs

@ -3,12 +3,13 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Uow;
public class AbpUnitOfWorkMiddleware : IMiddleware, ITransientDependency
public class AbpUnitOfWorkMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly AbpAspNetCoreUnitOfWorkOptions _options;
@ -21,9 +22,9 @@ public class AbpUnitOfWorkMiddleware : IMiddleware, ITransientDependency
_options = options.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (IsIgnoredUrl(context))
if (await ShouldSkipAsync(context, next) || IsIgnoredUrl(context))
{
await next(context);
return;

17
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs

@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Autofac.Core;
using Autofac.Extras.DynamicProxy;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Autofac;
using Volo.Abp.Castle.DynamicProxy;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Modularity;
namespace Autofac.Builder;
@ -75,11 +78,15 @@ public static class AbpRegistrationBuilderExtensions
if (serviceRegistredArgs.Interceptors.Any())
{
registrationBuilder = registrationBuilder.AddInterceptors(
registrationActionList,
serviceType,
serviceRegistredArgs.Interceptors
);
var disableAbpFeaturesAttribute = serviceRegistredArgs.ImplementationType.GetCustomAttribute<DisableAbpFeaturesAttribute>(true);
if (disableAbpFeaturesAttribute == null || !disableAbpFeaturesAttribute.DisableInterceptors)
{
registrationBuilder = registrationBuilder.AddInterceptors(
registrationActionList,
serviceType,
serviceRegistredArgs.Interceptors
);
}
}
return registrationBuilder;

25
framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs

@ -0,0 +1,25 @@
using System;
namespace Volo.Abp;
[AttributeUsage(AttributeTargets.Class)]
public class DisableAbpFeaturesAttribute : Attribute
{
/// <summary>
/// The framework will not register any interceptors for the class.
/// This will cause the all features that depend on interceptors to not work.
/// </summary>
public bool DisableInterceptors { get; set; } = true;
/// <summary>
/// The framework middleware will skip the class.
/// This will cause the all features that depend on middleware to not work.
/// </summary>
public bool DisableMiddleware { get; set; } = true;
/// <summary>
/// The framework will not remove all built-in filters for the class.
/// This will cause the all features that depend on filters to not work.
/// </summary>
public bool DisableMvcFilters { get; set; } = true;
}

5
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/FakeAuthenticationMiddleware.cs

@ -3,11 +3,12 @@ using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc;
public class FakeAuthenticationMiddleware : IMiddleware, ITransientDependency
public class FakeAuthenticationMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly FakeUserClaims _fakeUserClaims;
@ -16,7 +17,7 @@ public class FakeAuthenticationMiddleware : IMiddleware, ITransientDependency
_fakeUserClaims = fakeUserClaims;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (_fakeUserClaims.Claims.Any())
{

74
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Filters/MvcDisableAbpFeaturesAttribute_Tests.cs

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Shouldly;
using Volo.Abp.AspNetCore.Mvc.Auditing;
using Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.Features;
using Volo.Abp.AspNetCore.Mvc.GlobalFeatures;
using Volo.Abp.AspNetCore.Mvc.Response;
using Volo.Abp.AspNetCore.Mvc.Uow;
using Volo.Abp.AspNetCore.Mvc.Validation;
using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.Filters;
[Route("api/enabled-features-test")]
public class EnabledAbpFeaturesController : AbpController, IRemoteService
{
[HttpGet]
public Task<List<string>> GetAsync()
{
var filters = HttpContext.GetEndpoint().Metadata.GetMetadata<ControllerActionDescriptor>()
.FilterDescriptors.Where(x => x.Filter is ServiceFilterAttribute)
.Select(x => x.Filter.As<ServiceFilterAttribute>().ServiceType.FullName).ToList();
return Task.FromResult(filters);
}
}
[Route("api/disabled-features-test")]
[DisableAbpFeatures]
public class DisabledAbpFeaturesController : AbpController, IRemoteService
{
[HttpGet]
public Task<List<string>> GetAsync()
{
var filters = HttpContext.GetEndpoint().Metadata.GetMetadata<ControllerActionDescriptor>()
.FilterDescriptors.Where(x => x.Filter is ServiceFilterAttribute)
.Select(x => x.Filter.As<ServiceFilterAttribute>().ServiceType.FullName).ToList();
return Task.FromResult(filters);
}
}
public class MvcDisableAbpFeaturesAttribute_Tests : AspNetCoreMvcTestBase
{
[Fact]
public async Task Should_Disable_MVC_Filters()
{
var filters = await GetResponseAsObjectAsync<List<string>>("/api/enabled-features-test");
filters.ShouldContain(typeof(GlobalFeatureActionFilter).FullName);
filters.ShouldContain(typeof(AbpAuditActionFilter).FullName);
filters.ShouldContain(typeof(AbpNoContentActionFilter).FullName);
filters.ShouldContain(typeof(AbpFeatureActionFilter).FullName);
filters.ShouldContain(typeof(AbpValidationActionFilter).FullName);
filters.ShouldContain(typeof(AbpUowActionFilter).FullName);
filters.ShouldContain(typeof(AbpExceptionFilter).FullName);
filters = await GetResponseAsObjectAsync<List<string>>("/api/disabled-features-test");
filters.ShouldNotContain(typeof(GlobalFeatureActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpAuditActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpNoContentActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpFeatureActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpValidationActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpUowActionFilter).FullName);
filters.ShouldNotContain(typeof(AbpExceptionFilter).FullName);
}
}

31
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs

@ -15,22 +15,34 @@ public abstract class AbpInterceptionTestBase<TStartupModule> : AbpAsyncIntegrat
services.AddTransient<SimpleAsyncInterceptor>();
services.AddTransient<SimpleAsyncInterceptor2>();
services.AddTransient<SimpleInterceptionTargetClass>();
services.AddTransient<DisableInterceptionTargetClass>();
services.AddTransient<SimpleResultCacheTestInterceptor>();
services.AddTransient<CachedTestObject>();
services.AddTransient<AlwaysExceptionAsyncInterceptor>();
services.OnRegistered(registration =>
{
if (typeof(SimpleInterceptionTargetClass) == registration.ImplementationType)
{
registration.Interceptors.Add<SimpleAsyncInterceptor>();
registration.Interceptors.Add<SimpleAsyncInterceptor2>();
registration.Interceptors.Add<SimpleResultCacheTestInterceptor>();
}
if (typeof(CachedTestObject) == registration.ImplementationType)
{
registration.Interceptors.Add<SimpleResultCacheTestInterceptor>();
}
if (typeof(DisableInterceptionTargetClass) == registration.ImplementationType)
{
registration.Interceptors.Add<SimpleAsyncInterceptor>();
registration.Interceptors.Add<SimpleAsyncInterceptor2>();
registration.Interceptors.Add<SimpleResultCacheTestInterceptor>();
registration.Interceptors.Add<AlwaysExceptionAsyncInterceptor>();
}
});
return Task.CompletedTask;
@ -96,4 +108,23 @@ public abstract class AbpInterceptionTestBase<TStartupModule> : AbpAsyncIntegrat
(await target.GetValueAsync(43)).ShouldBe(42); //First run, cached previous value
(await target.GetValueAsync(44)).ShouldBe(42); //First run, cached previous value
}
[Fact]
public async Task Should_Disable_Interceptors()
{
//Arrange
var target = ServiceProvider.GetService<DisableInterceptionTargetClass>();
//Act
await target.DoItAsync();
//Assert
target.Logs.Count.ShouldBe(3);
target.Logs[0].ShouldBe("EnterDoItAsync");
target.Logs[1].ShouldBe("MiddleDoItAsync");
target.Logs[2].ShouldBe("ExitDoItAsync");
}
}

11
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AlwaysExceptionAsyncInterceptor.cs

@ -0,0 +1,11 @@
using System.Threading.Tasks;
namespace Volo.Abp.DynamicProxy;
public class AlwaysExceptionAsyncInterceptor : AbpInterceptor
{
public override Task InterceptAsync(IAbpMethodInvocation invocation)
{
throw new AbpException("This interceptor should not be executed!");
}
}

41
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/DisableInterceptionTargetClass.cs

@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.TestBase.Logging;
namespace Volo.Abp.DynamicProxy;
[DisableAbpFeatures]
public class DisableInterceptionTargetClass : ICanLogOnObject
{
public List<string> Logs { get; } = new List<string>();
public virtual void DoIt()
{
Logs.Add("ExecutingDoIt");
}
public virtual int GetValue()
{
Logs.Add("ExecutingGetValue");
return 42;
}
public virtual async Task<int> GetValueAsync()
{
Logs.Add("EnterGetValueAsync");
await Task.Delay(5);
Logs.Add("MiddleGetValueAsync");
await Task.Delay(5);
Logs.Add("ExitGetValueAsync");
return 42;
}
public virtual async Task DoItAsync()
{
Logs.Add("EnterDoItAsync");
await Task.Delay(5);
Logs.Add("MiddleDoItAsync");
await Task.Delay(5);
Logs.Add("ExitDoItAsync");
}
}
Loading…
Cancel
Save