|
|
@ -1,6 +1,8 @@ |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using System.Linq; |
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Volo.Abp.AspNetCore.MultiTenancy; |
|
|
using Volo.Abp.AspNetCore.MultiTenancy; |
|
|
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
|
|
|
|
|
namespace Microsoft.AspNetCore.Builder; |
|
|
namespace Microsoft.AspNetCore.Builder; |
|
|
|
|
|
|
|
|
@ -11,14 +13,22 @@ public static class AbpAspNetCoreMultiTenancyApplicationBuilderExtensions |
|
|
|
|
|
|
|
|
public static IApplicationBuilder UseMultiTenancy(this IApplicationBuilder app) |
|
|
public static IApplicationBuilder UseMultiTenancy(this IApplicationBuilder app) |
|
|
{ |
|
|
{ |
|
|
var authenticationMiddlewareSet = app.Properties.TryGetValue(AuthenticationMiddlewareSetKey, out var value) && value is true; |
|
|
var multiTenancyOptions = app.ApplicationServices.GetRequiredService<AbpTenantResolveOptions>(); |
|
|
if (!authenticationMiddlewareSet) |
|
|
var hasCurrentUserTenantResolveContributor = multiTenancyOptions.TenantResolvers.Any(r => r is CurrentUserTenantResolveContributor); |
|
|
|
|
|
if (hasCurrentUserTenantResolveContributor) |
|
|
{ |
|
|
{ |
|
|
var logger = app.ApplicationServices.GetService<ILogger<MultiTenancyMiddleware>>(); |
|
|
var authenticationMiddlewareSet = app.Properties.TryGetValue(AuthenticationMiddlewareSetKey, out var value) && value is true; |
|
|
logger?.LogWarning("MultiTenancyMiddleware is being registered before the authentication middleware. " + |
|
|
if (!authenticationMiddlewareSet) |
|
|
"This may lead to incorrect tenant resolution. " + |
|
|
{ |
|
|
"Ensure that app.UseAuthentication() is called before app.UseMultiTenancy()."); |
|
|
var logger = app.ApplicationServices.GetService<ILogger<MultiTenancyMiddleware>>(); |
|
|
|
|
|
logger?.LogWarning( |
|
|
|
|
|
"MultiTenancyMiddleware is being registered before the authentication middleware. " + |
|
|
|
|
|
"This may lead to incorrect tenant resolution if the resolution depends on the authenticated user. " + |
|
|
|
|
|
"Ensure app.UseAuthentication() is called before app.UseMultiTenancy()." |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return app.UseMiddleware<MultiTenancyMiddleware>(); |
|
|
return app.UseMiddleware<MultiTenancyMiddleware>(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|