diff --git a/.github/workflows/test-and-analyze.yml b/.github/workflows/test-and-analyze.yml index 982770cac..17ac3a646 100644 --- a/.github/workflows/test-and-analyze.yml +++ b/.github/workflows/test-and-analyze.yml @@ -30,14 +30,14 @@ jobs: with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Cache SonarCloud packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~\sonar\cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache SonarCloud scanner id: cache-sonar-scanner - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: .\.sonar\scanner key: ${{ runner.os }}-sonar-scanner diff --git a/src/Altinn.App.Api/Altinn.App.Api.csproj b/src/Altinn.App.Api/Altinn.App.Api.csproj index aa4699288..1dfb35001 100644 --- a/src/Altinn.App.Api/Altinn.App.Api.csproj +++ b/src/Altinn.App.Api/Altinn.App.Api.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/Altinn.App.Core/Altinn.App.Core.csproj b/src/Altinn.App.Core/Altinn.App.Core.csproj index 1bda5bbc7..ceec3699c 100644 --- a/src/Altinn.App.Core/Altinn.App.Core.csproj +++ b/src/Altinn.App.Core/Altinn.App.Core.csproj @@ -11,10 +11,10 @@ - - + + - + diff --git a/src/Altinn.App.Core/Infrastructure/Clients/Authorization/AuthorizationClient.cs b/src/Altinn.App.Core/Infrastructure/Clients/Authorization/AuthorizationClient.cs index 03d7a37a9..2441e0f26 100644 --- a/src/Altinn.App.Core/Infrastructure/Clients/Authorization/AuthorizationClient.cs +++ b/src/Altinn.App.Core/Infrastructure/Clients/Authorization/AuthorizationClient.cs @@ -1,8 +1,10 @@ +using System.Net.Http; using System.Net.Http.Headers; using Altinn.App.Core.Configuration; using Altinn.App.Core.Constants; using Altinn.App.Core.Extensions; using Altinn.App.Core.Interface; +using Altinn.Authorization.ABAC.Xacml.JsonProfile; using Altinn.Platform.Register.Models; using AltinnCore.Authentication.Utils; @@ -24,6 +26,7 @@ public class AuthorizationClient : IAuthorization private readonly AppSettings _settings; private readonly HttpClient _client; private readonly ILogger _logger; + private const string ForwardedForHeaderName = "x-forwarded-for"; /// /// Initializes a new instance of the class @@ -44,6 +47,12 @@ public AuthorizationClient( _settings = settings.CurrentValue; _logger = logger; httpClient.BaseAddress = new Uri(platformSettings.Value.ApiAuthorizationEndpoint); + + if (!httpClient.DefaultRequestHeaders.Contains(ForwardedForHeaderName)) + { + string? clientIpAddress = _httpContextAccessor?.HttpContext?.Request?.Headers?[ForwardedForHeaderName]; + httpClient.DefaultRequestHeaders.Add(ForwardedForHeaderName, clientIpAddress); + } httpClient.DefaultRequestHeaders.Add(General.SubscriptionKeyHeaderName, platformSettings.Value.SubscriptionKey); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client = httpClient; diff --git a/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj b/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj index 48be4bbb9..b3654a173 100644 --- a/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj +++ b/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj @@ -9,12 +9,12 @@ - - - + + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj b/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj index 179391b37..f2f06dcff 100644 --- a/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj +++ b/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj @@ -19,9 +19,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj b/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj index 4149690fc..971e533e9 100644 --- a/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj +++ b/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj @@ -33,10 +33,10 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive