Browse Source

Merge pull request #23483 from abpframework/MvcRemoteTenantStore

Add logging warnings for missing cache in `MvcRemoteTenantStore` and `RemoteDynamicClaimsPrincipalContributorCacheBase`
pull/23518/head
Engincan VESKE 6 months ago
committed by GitHub
parent
commit
e9102ea7ff
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs
  2. 3
      framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs

32
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Pages.Abp.MultiTenancy.ClientProxies;
using Volo.Abp.Caching;
@ -13,6 +15,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
{
public ILogger<MvcRemoteTenantStore> Logger { get; set; }
protected AbpTenantClientProxy TenantAppService { get; }
protected IHttpContextAccessor HttpContextAccessor { get; }
protected IDistributedCache<TenantConfigurationCacheItem> Cache { get; }
@ -24,6 +28,8 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
IDistributedCache<TenantConfigurationCacheItem> cache,
IOptions<AbpAspNetCoreMvcClientCacheOptions> options)
{
Logger = NullLogger<MvcRemoteTenantStore>.Instance;
TenantAppService = tenantAppService;
HttpContextAccessor = httpContextAccessor;
Cache = cache;
@ -45,6 +51,11 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
{
var tenant = await TenantAppService.FindTenantByNameAsync(normalizedName);
tenantConfiguration = await Cache.GetAsync(cacheKey);
if (tenant.Success && tenantConfiguration?.Value == null)
{
Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " +
"Ensure all applications use the same distributed cache and the same cache key prefix");
}
}
if (httpContext != null)
@ -68,8 +79,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
var tenantConfiguration = await Cache.GetAsync(cacheKey);
if (tenantConfiguration?.Value == null)
{
await TenantAppService.FindTenantByIdAsync(id);
var tenant = await TenantAppService.FindTenantByIdAsync(id);
tenantConfiguration = await Cache.GetAsync(cacheKey);
if (tenant.Success && tenantConfiguration?.Value == null)
{
Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " +
"Ensure all applications use the same distributed cache and the same cache key prefix");
}
}
if (httpContext != null)
@ -98,8 +114,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
var tenantConfiguration = Cache.Get(cacheKey);
if (tenantConfiguration?.Value == null)
{
AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName));
var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByNameAsync(normalizedName));
tenantConfiguration = Cache.Get(cacheKey);
if (tenant.Success && tenantConfiguration?.Value == null)
{
Logger.LogWarning($"Tenant with name '{normalizedName}' was found, but not present in the distributed cache, " +
"Ensure all applications use the same distributed cache and the same cache key prefix");
}
}
if (httpContext != null)
@ -123,8 +144,13 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency
var tenantConfiguration = Cache.Get(cacheKey);
if (tenantConfiguration?.Value == null)
{
AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id));
var tenant = AsyncHelper.RunSync(async () => await TenantAppService.FindTenantByIdAsync(id));
tenantConfiguration = Cache.Get(cacheKey);
if (tenant.Success && tenantConfiguration?.Value == null)
{
Logger.LogWarning($"Tenant with ID '{id}' was found, but not present in the distributed cache, " +
"Ensure all applications use the same distributed cache and the same cache key prefix");
}
}
if (httpContext != null)

3
framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs

@ -42,7 +42,8 @@ public abstract class RemoteDynamicClaimsPrincipalContributorCacheBase<TContribu
dynamicClaims = await GetCacheAsync(userId, tenantId);
if (dynamicClaims == null)
{
throw new AbpException($"Failed to refresh remote claims for user: {userId}");
throw new AbpException($"Failed to get dynamic claims for user: {userId} from cache after refreshing, " +
$"Ensure all applications use the same distributed cache and the same cache key prefix.");
}
return dynamicClaims;

Loading…
Cancel
Save