|
1 | | -using Altinn.AccessManagement.Api.Enduser; |
| 1 | +using Altinn.AccessManagement.Api.Enduser; |
2 | 2 | using Altinn.AccessManagement.Api.Enduser.Authorization.AuthorizationHandler; |
3 | 3 | using Altinn.AccessManagement.Api.Enduser.Authorization.AuthorizationRequirement; |
4 | 4 | using Altinn.AccessManagement.Api.Internal; |
|
32 | 32 | using AltinnCore.Authentication.JwtCookie; |
33 | 33 | using Azure.Monitor.OpenTelemetry.AspNetCore; |
34 | 34 | using Microsoft.AspNetCore.Authorization; |
| 35 | +using Microsoft.Extensions.DependencyInjection; |
35 | 36 | using Microsoft.FeatureManagement; |
36 | 37 | using Microsoft.IdentityModel.Tokens; |
37 | 38 | using Microsoft.OpenApi.Models; |
@@ -297,27 +298,27 @@ private static void ConfigureAuthorization(this WebApplicationBuilder builder) |
297 | 298 | .AddPolicy(AuthzConstants.INTERNAL_AUTHORIZATION, policy => policy.Requirements.Add(new ClaimAccessRequirement("urn:altinn:app", "internal.authorization"))) |
298 | 299 | .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_DELEGATION_READ, policy => policy.Requirements.Add(new ResourceAccessRequirement("read", "altinn_maskinporten_scope_delegation"))) |
299 | 300 | .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_DELEGATION_WRITE, policy => policy.Requirements.Add(new ResourceAccessRequirement("write", "altinn_maskinporten_scope_delegation"))) |
300 | | - .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_DELEGATIONS_PROXY, policy => policy.Requirements.Add(new ScopeAccessRequirement(["altinn:maskinporten/delegations", "altinn:maskinporten/delegations.admin"]))) |
301 | | - .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_CONSENT_READ, policy => policy.Requirements.Add(new ScopeAccessRequirement(["altinn:maskinporten/consent.read"]))) |
| 301 | + .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_DELEGATIONS_PROXY, policy => policy.RequireAnyScopeOf("altinn:maskinporten/delegations", "altinn:maskinporten/delegations.admin")) |
| 302 | + .AddPolicy(AuthzConstants.POLICY_MASKINPORTEN_CONSENT_READ, policy => policy.RequireAnyScopeOf("altinn:maskinporten/consent.read")) |
302 | 303 | .AddPolicy(AuthzConstants.POLICY_ACCESS_MANAGEMENT_READ, policy => policy.Requirements.Add(new ResourceAccessRequirement("read", "altinn_access_management"))) |
303 | 304 | .AddPolicy(AuthzConstants.POLICY_ACCESS_MANAGEMENT_WRITE, policy => policy.Requirements.Add(new ResourceAccessRequirement("write", "altinn_access_management"))) |
304 | 305 | .AddPolicy(AuthzConstants.POLICY_ACCESS_MANAGEMENT_ENDUSER_READ, policy => policy.Requirements.Add(new EndUserResourceAccessRequirement("read", "altinn_access_management", false))) |
305 | 306 | .AddPolicy(AuthzConstants.POLICY_ACCESS_MANAGEMENT_ENDUSER_WRITE, policy => policy.Requirements.Add(new EndUserResourceAccessRequirement("write", "altinn_access_management", false))) |
306 | 307 | .AddPolicy(AuthzConstants.POLICY_ACCESS_MANAGEMENT_ENDUSER_READ_WITH_PASS_TROUGH, policy => policy.Requirements.Add(new EndUserResourceAccessRequirement("read", "altinn_access_management", true))) |
307 | | - .AddPolicy(AuthzConstants.POLICY_RESOURCEOWNER_AUTHORIZEDPARTIES, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_AUTHORIZEDPARTIES_RESOURCEOWNER, AuthzConstants.SCOPE_AUTHORIZEDPARTIES_ADMIN]))) |
308 | | - .AddPolicy(AuthzConstants.POLICY_CONSENTREQUEST_WRITE, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_CONSENTREQUEST_ORG, AuthzConstants.SCOPE_CONSENTREQUEST_WRITE]))) |
309 | | - .AddPolicy(AuthzConstants.POLICY_CONSENTREQUEST_READ, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_CONSENTREQUEST_ORG, AuthzConstants.SCOPE_CONSENTREQUEST_READ, AuthzConstants.SCOPE_CONSENTREQUEST_WRITE]))) |
| 308 | + .AddPolicy(AuthzConstants.POLICY_RESOURCEOWNER_AUTHORIZEDPARTIES, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_AUTHORIZEDPARTIES_RESOURCEOWNER, AuthzConstants.SCOPE_AUTHORIZEDPARTIES_ADMIN)) |
| 309 | + .AddPolicy(AuthzConstants.POLICY_CONSENTREQUEST_WRITE, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_CONSENTREQUEST_ORG, AuthzConstants.SCOPE_CONSENTREQUEST_WRITE)) |
| 310 | + .AddPolicy(AuthzConstants.POLICY_CONSENTREQUEST_READ, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_CONSENTREQUEST_ORG, AuthzConstants.SCOPE_CONSENTREQUEST_READ, AuthzConstants.SCOPE_CONSENTREQUEST_WRITE)) |
310 | 311 | .AddPolicy(AuthzConstants.POLICY_CLIENTDELEGATION_READ, policy => policy.Requirements.Add(new EndUserResourceAccessRequirement("read", "altinn_client_administration"))) |
311 | 312 | .AddPolicy(AuthzConstants.POLICY_CLIENTDELEGATION_WRITE, policy => policy.Requirements.Add(new EndUserResourceAccessRequirement("write", "altinn_client_administration"))) |
312 | | - .AddPolicy(AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_READ, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_PORTAL_ENDUSER, AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_READ]))) |
313 | | - .AddPolicy(AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_WRITE, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_PORTAL_ENDUSER, AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_WRITE]))) |
314 | | - .AddPolicy(AuthzConstants.SCOPE_PORTAL_ENDUSER, policy => policy.Requirements.Add(new ScopeAccessRequirement([AuthzConstants.SCOPE_PORTAL_ENDUSER]))); |
| 313 | + .AddPolicy(AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_READ, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_PORTAL_ENDUSER, AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_READ)) |
| 314 | + .AddPolicy(AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_WRITE, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_PORTAL_ENDUSER, AuthzConstants.SCOPE_ENDUSER_CLIENTDELEGATION_WRITE)) |
| 315 | + .AddPolicy(AuthzConstants.SCOPE_PORTAL_ENDUSER, policy => policy.RequireAnyScopeOf(AuthzConstants.SCOPE_PORTAL_ENDUSER)); |
315 | 316 |
|
316 | 317 | builder.Services.AddScoped<IAuthorizationHandler, AccessTokenHandler>(); |
317 | 318 | builder.Services.AddScoped<IAuthorizationHandler, ClaimAccessHandler>(); |
318 | 319 | builder.Services.AddScoped<IAuthorizationHandler, ResourceAccessHandler>(); |
319 | 320 | builder.Services.AddScoped<IAuthorizationHandler, EndUserResourceAccessHandler>(); |
320 | | - builder.Services.AddScoped<IAuthorizationHandler, ScopeAccessHandler>(); |
| 321 | + builder.Services.AddAltinnScopesAuthorizationHandlers(); |
321 | 322 | } |
322 | 323 |
|
323 | 324 | private static void ConfigurePostgreSqlConfiguration(this WebApplicationBuilder builder) |
|
0 commit comments