diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index 379a37a4c..a6d7687ce 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; using Altinn.Authorization.ABAC.Xacml.JsonProfile; @@ -23,7 +24,6 @@ internal sealed class AltinnAuthorizationClient : IAltinnAuthorization private readonly IFusionCache _partiesCache; private readonly IUser _user; private readonly ILogger _logger; - private readonly IMemoryCache _inMemoryCache; private static readonly JsonSerializerOptions SerializerOptions = new() { @@ -35,15 +35,13 @@ public AltinnAuthorizationClient( HttpClient client, IFusionCacheProvider cacheProvider, IUser user, - ILogger logger, - IMemoryCache inMemoryCache) + ILogger logger) { _httpClient = client ?? throw new ArgumentNullException(nameof(client)); _pdpCache = cacheProvider.GetCache(nameof(Authorization)) ?? throw new ArgumentNullException(nameof(cacheProvider)); _partiesCache = cacheProvider.GetCache(nameof(AuthorizedPartiesResult)) ?? throw new ArgumentNullException(nameof(cacheProvider)); _user = user ?? throw new ArgumentNullException(nameof(user)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _inMemoryCache = inMemoryCache; } public async Task GetDialogDetailsAuthorization( @@ -90,9 +88,17 @@ public async Task GetAuthorizedParties(IPartyIdentifier var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); - var inMemoryCacheValue = _inMemoryCache.TryGetValue(cacheKey, out var inMemoryCacheEntry); - _logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@InMemoryCacheEntry}", - cacheKey, inMemoryCacheValue, inMemoryCacheEntry); + var mcaField = typeof(FusionCache).GetField("_mca", BindingFlags.NonPublic | BindingFlags.Instance); + var mcaValue = mcaField?.GetValue(_partiesCache); + var mcField = mcaValue!.GetType().GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance); + var mcValue = mcField?.GetValue(mcaValue) as IMemoryCache; + + var inMemoryCacheValue = mcValue!.TryGetValue(cacheKey, out var inMemoryCacheEntry); + var inMemoryCacheEntryValue = inMemoryCacheEntry?.GetType().GetProperty("Value")?.GetValue(inMemoryCacheEntry); + + _logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}", + cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue); + // Temporary logging to debug missing authorized sub parties _logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties);