From 2372429051b266c75617eb3c61bf9078af57826a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 11:59:02 +0100 Subject: [PATCH 1/8] psuh --- .../Altinn/Authorization/AltinnAuthorizationClient.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index 71cc487b9..b2974e5aa 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -82,11 +82,11 @@ public async Task GetAuthorizedParties(IPartyIdentifier { var authorizedPartiesRequest = new AuthorizedPartiesRequest(authenticatedParty); - // Disabled until this bug is fixed: https://github.com/digdir/dialogporten/issues/1226 - // var authorizedParties = await _partiesCache.GetOrSetAsync(authorizedPartiesRequest.GenerateCacheKey(), async token - // => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); + var authorizedParties = await _partiesCache.GetOrSetAsync(authorizedPartiesRequest.GenerateCacheKey(), async token + => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); - var authorizedParties = await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, cancellationToken); + // Temporary logging to debug missing authorized sub parties + _logger.LogInformation("Authorized parties for {Party}: {AuthorizedParties}", authenticatedParty, JsonSerializer.Serialize(authorizedParties, SerializerOptions)); return flatten ? GetFlattenedAuthorizedParties(authorizedParties) : authorizedParties; } From 0977d3c09c84f50835a6ff778dafcce17ae00204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 12:53:54 +0100 Subject: [PATCH 2/8] set loglevel info --- .../appsettings.test.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json b/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json index 59e0d4d46..6b3a6961e 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json +++ b/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json @@ -62,5 +62,12 @@ } ] } - } + }, + "Serilog": { + "MinimumLevel": { + "Override": { + "Digdir.Domain.Dialogporten.Infrastructure.Altinn.Authorization": "Information" + } + } + }, } From 368f36b676d6c189376f6eae4c193f70d6e5f779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 14:20:21 +0100 Subject: [PATCH 3/8] test --- .../EndUser/PartyQueries.cs | 16 ++++++++++++++++ .../appsettings.test.json | 10 +++++++++- .../appsettings.test.json | 7 ------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs index d2fea28c2..b543d5d74 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs @@ -1,4 +1,8 @@ +using System.Text.Json; +using System.Text.Json.Serialization; using AutoMapper; +using Digdir.Domain.Dialogporten.Application.Common.Extensions; +using Digdir.Domain.Dialogporten.Application.Externals.Presentation; using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Parties.Queries.Get; using Digdir.Domain.Dialogporten.GraphQL.EndUser.Parties; using MediatR; @@ -7,14 +11,26 @@ namespace Digdir.Domain.Dialogporten.GraphQL.EndUser; public partial class Queries { + private static readonly JsonSerializerOptions SerializerOptions = new() + { + PropertyNameCaseInsensitive = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault + }; + public async Task> GetParties( [Service] ISender mediator, [Service] IMapper mapper, + [Service] ILogger logger, + [Service] IUser user, CancellationToken cancellationToken) { var request = new GetPartiesQuery(); var result = await mediator.Send(request, cancellationToken); + user.GetPrincipal().TryGetPid(out var pid); + logger.LogInformation("GraphQL handler, app result for party {Party}: {AuthorizedParties}", + pid, JsonSerializer.Serialize(result, SerializerOptions)); + return mapper.Map>(result.AuthorizedParties); } } diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/appsettings.test.json b/src/Digdir.Domain.Dialogporten.GraphQL/appsettings.test.json index 970b290f9..3b9341d43 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/appsettings.test.json +++ b/src/Digdir.Domain.Dialogporten.GraphQL/appsettings.test.json @@ -59,5 +59,13 @@ } ] } - } + }, + "Serilog": { + "MinimumLevel": { + "Override": { + "Digdir.Domain.Dialogporten.Infrastructure.Altinn.Authorization.AltinnAuthorizationClient": "Information", + "Digdir.Domain.Dialogporten.GraphQL.EndUser.Queries": "Information" + } + } + }, } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json b/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json index 6b3a6961e..577adb54a 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json +++ b/src/Digdir.Domain.Dialogporten.WebApi/appsettings.test.json @@ -63,11 +63,4 @@ ] } }, - "Serilog": { - "MinimumLevel": { - "Override": { - "Digdir.Domain.Dialogporten.Infrastructure.Altinn.Authorization": "Information" - } - } - }, } From 9055ae7f0b442304a480434a7bb028cccd132b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 14:28:13 +0100 Subject: [PATCH 4/8] kjekt --- .../EndUser/PartyQueries.cs | 12 ++---------- .../Authorization/AltinnAuthorizationClient.cs | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs index b543d5d74..5e8056b6d 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/PartyQueries.cs @@ -1,5 +1,3 @@ -using System.Text.Json; -using System.Text.Json.Serialization; using AutoMapper; using Digdir.Domain.Dialogporten.Application.Common.Extensions; using Digdir.Domain.Dialogporten.Application.Externals.Presentation; @@ -11,12 +9,6 @@ namespace Digdir.Domain.Dialogporten.GraphQL.EndUser; public partial class Queries { - private static readonly JsonSerializerOptions SerializerOptions = new() - { - PropertyNameCaseInsensitive = true, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault - }; - public async Task> GetParties( [Service] ISender mediator, [Service] IMapper mapper, @@ -28,8 +20,8 @@ public async Task> GetParties( var result = await mediator.Send(request, cancellationToken); user.GetPrincipal().TryGetPid(out var pid); - logger.LogInformation("GraphQL handler, app result for party {Party}: {AuthorizedParties}", - pid, JsonSerializer.Serialize(result, SerializerOptions)); + logger.LogInformation("GraphQL handler, app result for party {Party}: {@Result}", + pid, result); return mapper.Map>(result.AuthorizedParties); } diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index b2974e5aa..91f06d609 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -86,7 +86,7 @@ public async Task GetAuthorizedParties(IPartyIdentifier => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); // Temporary logging to debug missing authorized sub parties - _logger.LogInformation("Authorized parties for {Party}: {AuthorizedParties}", authenticatedParty, JsonSerializer.Serialize(authorizedParties, SerializerOptions)); + _logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties); return flatten ? GetFlattenedAuthorizedParties(authorizedParties) : authorizedParties; } From 734fb56e9c913d110f666b7da8a8397f098285e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 14:56:06 +0100 Subject: [PATCH 5/8] arst --- .../Authorization/AltinnAuthorizationClient.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index 91f06d609..379a37a4c 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -8,6 +8,7 @@ using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; using Digdir.Domain.Dialogporten.Domain.Parties.Abstractions; using Digdir.Domain.Dialogporten.Infrastructure.Common.Exceptions; +using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using ZiggyCreatures.Caching.Fusion; @@ -22,6 +23,7 @@ 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() { @@ -33,13 +35,15 @@ public AltinnAuthorizationClient( HttpClient client, IFusionCacheProvider cacheProvider, IUser user, - ILogger logger) + ILogger logger, + IMemoryCache inMemoryCache) { _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( @@ -82,9 +86,14 @@ public async Task GetAuthorizedParties(IPartyIdentifier { var authorizedPartiesRequest = new AuthorizedPartiesRequest(authenticatedParty); - var authorizedParties = await _partiesCache.GetOrSetAsync(authorizedPartiesRequest.GenerateCacheKey(), async token + var cacheKey = authorizedPartiesRequest.GenerateCacheKey(); + 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); + // Temporary logging to debug missing authorized sub parties _logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties); From 49c659367875f75bd31db84110baa6dc320087ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 16:07:32 +0100 Subject: [PATCH 6/8] ??? --- .../Authorization/AltinnAuthorizationClient.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index 379a37a4c..a01dd8901 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; @@ -90,9 +91,22 @@ public async Task GetAuthorizedParties(IPartyIdentifier var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); +<<<<<<< HEAD + 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); +======= var inMemoryCacheValue = _inMemoryCache.TryGetValue(cacheKey, out var inMemoryCacheEntry); _logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@InMemoryCacheEntry}", cacheKey, inMemoryCacheValue, inMemoryCacheEntry); +>>>>>>> main // Temporary logging to debug missing authorized sub parties _logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties); From 917d825ae80cd35ed5acf39f5d1648c64eb99363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 16:10:00 +0100 Subject: [PATCH 7/8] fx --- .../Altinn/Authorization/AltinnAuthorizationClient.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index a01dd8901..c3981a292 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -91,7 +91,6 @@ public async Task GetAuthorizedParties(IPartyIdentifier var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token => await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken); -<<<<<<< HEAD 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); @@ -102,11 +101,7 @@ public async Task GetAuthorizedParties(IPartyIdentifier _logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}", cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue); -======= - var inMemoryCacheValue = _inMemoryCache.TryGetValue(cacheKey, out var inMemoryCacheEntry); - _logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@InMemoryCacheEntry}", - cacheKey, inMemoryCacheValue, inMemoryCacheEntry); ->>>>>>> main + // Temporary logging to debug missing authorized sub parties _logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties); From efeda90e77e399afdaff3639ac33065cda7efb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 25 Nov 2024 16:11:23 +0100 Subject: [PATCH 8/8] fx --- .../Altinn/Authorization/AltinnAuthorizationClient.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs index c3981a292..a6d7687ce 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/AltinnAuthorizationClient.cs @@ -24,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() { @@ -36,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(