|
|
|
@ -1,6 +1,11 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Security.Principal; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Security.Claims; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity; |
|
|
|
@ -17,7 +22,19 @@ public class IdentityDynamicClaimsPrincipalContributor : AbpDynamicClaimsPrincip |
|
|
|
} |
|
|
|
|
|
|
|
var dynamicClaimsCache = context.GetRequiredService<IdentityDynamicClaimsPrincipalContributorCache>(); |
|
|
|
var dynamicClaims = await dynamicClaimsCache.GetAsync(userId.Value, identity.FindTenantId()); |
|
|
|
List<AbpClaimCacheItem> dynamicClaims; |
|
|
|
try |
|
|
|
{ |
|
|
|
dynamicClaims = await dynamicClaimsCache.GetAsync(userId.Value, identity.FindTenantId()); |
|
|
|
} |
|
|
|
catch (EntityNotFoundException e) |
|
|
|
{ |
|
|
|
// In case if user not found, We force to clear the claims principal.
|
|
|
|
context.ClaimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity()); |
|
|
|
var logger = context.GetRequiredService<Logger<IdentityDynamicClaimsPrincipalContributor>>(); |
|
|
|
logger.LogWarning(e, $"User not found: {userId.Value}"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await MapCommonClaimsAsync(identity, dynamicClaims); |
|
|
|
await AddDynamicClaims(identity, dynamicClaims); |
|
|
|
|