Browse Source
Handle the case where `DynamicClaims` is empty.
pull/18175/head
maliming
3 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
4 changed files with
25 additions and
2 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteDynamicClaimsPrincipalContributor.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteDynamicClaimsPrincipalContributorCache.cs
-
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributor.cs
-
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache.cs
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Security.Principal; |
|
|
|
@ -39,6 +40,11 @@ public class RemoteDynamicClaimsPrincipalContributor : AbpDynamicClaimsPrincipal |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (dynamicClaims.Claims.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await AddDynamicClaimsAsync(context, identity, dynamicClaims.Claims); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -62,11 +62,11 @@ public class RemoteDynamicClaimsPrincipalContributorCache : ITransientDependency |
|
|
|
} |
|
|
|
|
|
|
|
dynamicClaims = await Cache.GetAsync(AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId)); |
|
|
|
if (dynamicClaims == null || dynamicClaims.Claims.IsNullOrEmpty()) |
|
|
|
if (dynamicClaims == null) |
|
|
|
{ |
|
|
|
throw new AbpException($"Failed to refresh remote claims for user: {userId}"); |
|
|
|
} |
|
|
|
|
|
|
|
return dynamicClaims!; |
|
|
|
return dynamicClaims; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Security.Principal; |
|
|
|
@ -34,6 +35,11 @@ public class IdentityDynamicClaimsPrincipalContributor : AbpDynamicClaimsPrincip |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (dynamicClaims.Claims.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await AddDynamicClaimsAsync(context, identity, dynamicClaims.Claims); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -47,6 +47,17 @@ public class IdentityDynamicClaimsPrincipalContributorCache : ITransientDependen |
|
|
|
{ |
|
|
|
Logger.LogDebug($"Get dynamic claims cache for user: {userId}"); |
|
|
|
|
|
|
|
if (AbpClaimsPrincipalFactoryOptions.Value.DynamicClaims.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
var emptyCacheItem = new AbpDynamicClaimCacheItem(); |
|
|
|
await Cache.SetAsync(AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId), emptyCacheItem, new DistributedCacheEntryOptions |
|
|
|
{ |
|
|
|
AbsoluteExpirationRelativeToNow = CacheOptions.Value.CacheAbsoluteExpiration |
|
|
|
}); |
|
|
|
|
|
|
|
return emptyCacheItem; |
|
|
|
} |
|
|
|
|
|
|
|
return await Cache.GetOrAddAsync(AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId), async () => |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(tenantId)) |
|
|
|
|