From caf927cbf1194ef3ade8bf8c050db29a9a6b87a0 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 23 Feb 2021 12:54:32 +0800 Subject: [PATCH] Change current tenant in AbpSecurityStampValidator. Resolve #7791 --- .../AspNetCore/AbpSecurityStampValidator.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs index cf6e1f8d50..1dcc624a47 100644 --- a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs @@ -4,29 +4,41 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; namespace Volo.Abp.Identity.AspNetCore { public class AbpSecurityStampValidator : SecurityStampValidator { + protected ITenantConfigurationProvider TenantConfigurationProvider { get; } + protected ICurrentTenant CurrentTenant { get; } + public AbpSecurityStampValidator( IOptions options, SignInManager signInManager, ISystemClock systemClock, - ILoggerFactory loggerFactory) + ILoggerFactory loggerFactory, + ITenantConfigurationProvider tenantConfigurationProvider, + ICurrentTenant currentTenant) : base( - options, + options, signInManager, systemClock, loggerFactory) { + TenantConfigurationProvider = tenantConfigurationProvider; + CurrentTenant = currentTenant; } [UnitOfWork] - public override Task ValidateAsync(CookieValidatePrincipalContext context) + public override async Task ValidateAsync(CookieValidatePrincipalContext context) { - return base.ValidateAsync(context); + var tenant = await TenantConfigurationProvider.GetAsync(saveResolveResult: false); + using (CurrentTenant.Change(tenant?.Id, tenant?.Name)) + { + await base.ValidateAsync(context); + } } } }