Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for access packages in policy editor #13921

Draft
wants to merge 74 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
674a216
access packages in policy editor WIP
mgunnerud Oct 3, 2024
e6bf5ed
Merge remote-tracking branch 'origin/main' into feat/13686-support-ac…
mgunnerud Oct 5, 2024
7c78ca7
show number of available packages in accordion heading
mgunnerud Oct 7, 2024
5637ef8
minor changes
mgunnerud Oct 7, 2024
d79fa21
add mock data to fix tests
mgunnerud Oct 7, 2024
19f5013
accessPackages are optional
mgunnerud Oct 7, 2024
451930f
accessPackages are optional
mgunnerud Oct 7, 2024
48de24f
Merge remote-tracking branch 'origin/main' into feat/13686-support-ac…
mgunnerud Oct 7, 2024
fbb1af5
move test code for access packages to backend
mgunnerud Oct 8, 2024
1f021a1
show services in use for each access package
mgunnerud Oct 9, 2024
3289c07
refactor access package hierarcy
mgunnerud Oct 10, 2024
0c047df
fix test data
mgunnerud Oct 10, 2024
f8e3056
show service owner in list of access package services
mgunnerud Oct 10, 2024
6dd588c
Merge remote-tracking branch 'origin/main' into feat/13686-support-ac…
mgunnerud Oct 19, 2024
76dcd78
add access package accordion
mgunnerud Oct 21, 2024
017ecd6
add accordions for access package + category icons
mgunnerud Oct 21, 2024
aaba8eb
minor changes + better testdata
mgunnerud Oct 21, 2024
f3aebd4
Merge remote-tracking branch 'origin/main' into feat/13686-support-ac…
mgunnerud Oct 22, 2024
68e7d39
show icon for resources in access package
mgunnerud Oct 23, 2024
c54461c
add test data
mgunnerud Oct 23, 2024
cc1e5ef
rollback change
mgunnerud Oct 23, 2024
7d05441
simplification
mgunnerud Oct 23, 2024
04b98d9
refactor
mgunnerud Oct 23, 2024
3dc3e72
add translations for access packages
mgunnerud Oct 23, 2024
b8ed9d1
accessibility improvements
mgunnerud Oct 23, 2024
b654d88
accesspackage can be in several categories
mgunnerud Oct 23, 2024
f3e91a3
replace category with tag
mgunnerud Oct 23, 2024
7c841d7
add tagGroup headings
mgunnerud Oct 23, 2024
94410a4
more testdata
mgunnerud Oct 23, 2024
36e7bdf
refactor after model change
mgunnerud Oct 24, 2024
b33411c
refactor variable name
mgunnerud Oct 24, 2024
261de72
refactor
mgunnerud Oct 24, 2024
03b1852
add tests for access packages in policy editor
mgunnerud Oct 25, 2024
04cad4e
dotnet format
mgunnerud Oct 25, 2024
4345d1d
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Oct 25, 2024
015d9d7
null check
mgunnerud Oct 25, 2024
471e8de
Merge branch 'feat/13686-support-access-packages-in-policy-editor-v1'…
mgunnerud Oct 25, 2024
e46058f
add feature flag for access packages
mgunnerud Oct 25, 2024
5f06c17
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Oct 25, 2024
888efe8
replace iconUrl with logoUrl
mgunnerud Oct 28, 2024
c947ac9
Merge branch 'feat/13686-support-access-packages-in-policy-editor-v1'…
mgunnerud Oct 28, 2024
a1d783f
add min-height to resources in access package row
mgunnerud Oct 28, 2024
cc1047f
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Oct 31, 2024
0e51e0c
testdata + WIP
mgunnerud Oct 31, 2024
def690f
styling changes + show chosen access packages first
mgunnerud Nov 1, 2024
76e6827
fix tests
mgunnerud Nov 1, 2024
46a8958
fix text
mgunnerud Nov 1, 2024
55f5cac
hide specialized access packages
mgunnerud Nov 4, 2024
115d843
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Nov 4, 2024
e7ee6d8
text change
mgunnerud Nov 4, 2024
d466a7b
Merge branch 'feat/13686-support-access-packages-in-policy-editor-v1'…
mgunnerud Nov 4, 2024
ccabe4e
fix type
mgunnerud Nov 4, 2024
7ce6bf3
fix spelling error + better test coverage
mgunnerud Nov 4, 2024
537844f
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Nov 10, 2024
4601a44
improve coverage
mgunnerud Nov 10, 2024
99838b4
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Nov 18, 2024
28867e0
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Nov 26, 2024
d63d36d
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Dec 9, 2024
b4932e5
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Dec 9, 2024
0007f70
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Dec 11, 2024
e35d810
always show all access packages
mgunnerud Dec 11, 2024
5aaa3d1
Merge branch 'feat/13686-support-access-packages-in-policy-editor-v1'…
mgunnerud Dec 11, 2024
cde8d18
fix after merge
mgunnerud Dec 11, 2024
b2cca3a
prepare for loading access packages through json file
mgunnerud Dec 12, 2024
fcf6a09
use real data!
mgunnerud Dec 12, 2024
eb66b8d
fix rendering of chosen access packages
mgunnerud Dec 12, 2024
782440f
fixes
mgunnerud Dec 13, 2024
c312f89
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
mgunnerud Dec 13, 2024
b0d84f4
fix tests (?)
mgunnerud Dec 13, 2024
de5af30
improve coverage
mgunnerud Dec 13, 2024
a58366b
change labels
mgunnerud Dec 13, 2024
9f8cc29
show default icon if access package area has no icon
mgunnerud Dec 13, 2024
b0347f6
update path to json file
mgunnerud Dec 13, 2024
826ee9b
enable access packages for apps
mgunnerud Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/PolicyAdmin/Models/AccessPackageArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#nullable enable

namespace PolicyAdmin.Models
{
public class AccessPackageArea
{
public required string Id { get; set; }

public required string Urn { get; set; }

public string Name { get; set; }

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Description { get; set; }

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Icon { get; set; }

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Icon' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Icon' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Icon' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Icon' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Icon' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string AreaGroup { get; set; }

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'AreaGroup' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'AreaGroup' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'AreaGroup' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'AreaGroup' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'AreaGroup' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public IEnumerable<AccessPackageOption> Packages { get; set; }

Check warning on line 19 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Packages' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in backend/PolicyAdmin/Models/AccessPackageArea.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Packages' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
19 changes: 19 additions & 0 deletions backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#nullable enable

namespace PolicyAdmin.Models
{
public class AccessPackageAreaGroup
{
public required string Id { get; set; }

public required string Urn { get; set; }

public string Name { get; set; }

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Description { get; set; }

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Type { get; set; }

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public IEnumerable<AccessPackageArea> Areas { get; set; }

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Areas' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Areas' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Areas' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 17 in backend/PolicyAdmin/Models/AccessPackageAreaGroup.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'Areas' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
15 changes: 15 additions & 0 deletions backend/PolicyAdmin/Models/AccessPackageOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable

namespace PolicyAdmin.Models
{
public class AccessPackageOption
{
public required string Id { get; set; }

public required string Urn { get; set; }

public string Name { get; set; }

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Description { get; set; }

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run integration tests against actual gitea and db

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in backend/PolicyAdmin/Models/AccessPackageOption.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
2 changes: 2 additions & 0 deletions backend/PolicyAdmin/Models/PolicyRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class PolicyRule

public List<string>? Subject { get; set; }

public List<string>? AccessPackages { get; set; }

public List<string>? Actions { get; set; }

public List<List<string>>? Resources { get; set; }
Expand Down
15 changes: 14 additions & 1 deletion backend/PolicyAdmin/PolicyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static ResourcePolicy ConvertPolicy(XacmlPolicy xacmlPolicy)
rule.Description = xr.Description;

rule.Subject = new List<string>();
rule.AccessPackages = new List<string>();
rule.Actions = new List<string>();
rule.Resources = new List<List<string>>();

Expand All @@ -31,7 +32,9 @@ public static ResourcePolicy ConvertPolicy(XacmlPolicy xacmlPolicy)
{
foreach (XacmlAllOf allOf in anyOf.AllOf)
{
List<string>? subject = GetRuleSubjects(allOf);
List<string>? subject = GetRuleSubjects(allOf)?.Where(x => !x.StartsWith("urn:altinn:accesspackage")).ToList();

List<string>? accessPackages = GetRuleSubjects(allOf)?.Where(x => x.StartsWith("urn:altinn:accesspackage")).ToList();

List<string>? resource = GetRuleResources(allOf);

Expand All @@ -42,6 +45,11 @@ public static ResourcePolicy ConvertPolicy(XacmlPolicy xacmlPolicy)
rule.Subject.AddRange(subject);
}

if (accessPackages != null)
{
rule.AccessPackages.AddRange(accessPackages);
}

if (action != null)
{
rule.Actions.AddRange(action);
Expand Down Expand Up @@ -195,6 +203,11 @@ private static XacmlRule ConvertRule(PolicyRule policyRule)
ruleAnyOfs.Add(GetSubjectAnyOfs(policyRule.Subject));
}

if (policyRule.AccessPackages != null && policyRule.AccessPackages.Count > 0)
{
ruleAnyOfs.Add(GetSubjectAnyOfs(policyRule.AccessPackages));
}

if (policyRule.Resources != null && policyRule.Resources.Count > 0)
{
ruleAnyOfs.Add(GetResourceAnyOfs(policyRule.Resources));
Expand Down
8 changes: 8 additions & 0 deletions backend/src/Designer/Controllers/PolicyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ public async Task<ActionResult> GetActionOptions(string org, string app, Cancell
return Ok(actionOptions);
}

[HttpGet]
[Route("accesspackageoptions")]
public async Task<ActionResult> GetAccessPackageOptions(string org, string app, CancellationToken cancellationToken)
{
List<AccessPackageAreaGroup> accessPackageOptions = await _policyOptions.GetAccessPackageOptions(cancellationToken);
return Ok(accessPackageOptions);
}


private ValidationProblemDetails ValidatePolicy(ResourcePolicy policy)
{
Expand Down
64 changes: 64 additions & 0 deletions backend/src/Designer/Controllers/ResourceAdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,70 @@ public async Task<ActionResult<List<EuroVocTerm>>> GetEuroVoc(CancellationToken
return sectors;
}

[HttpGet]
[Route("designer/api/accesspackageservices/{accesspackage}/{env}")]
public async Task<ActionResult<List<AccessPackageService>>> GetServicesForAccessPackage(string org, string accesspackage, string env)
{
// 2. POST to get all resources per access package
List<SubjectResources> subjectResources = await _resourceRegistry.GetSubjectResources([accesspackage], env);

// start test data
subjectResources.Add(new SubjectResources()
{
Subject = new AttributeMatchV2()
{
Type = "",
Value = "",
Urn = "urn:altinn:accesspackage:akvakultur"
},
Resources = new List<AttributeMatchV2>() {
new AttributeMatchV2() {
Type = "",
Value = "innsyn-i-driftsplaner-for-akvakulturanlegg-i-sj-vann",
Urn = ""
},
new AttributeMatchV2() {
Type = "",
Value = "ske-innrapportering-omsetning-raafisk",
Urn = ""
},
new AttributeMatchV2() {
Type = "",
Value = "mat-maskinportenschema-lakselusrapportering",
Urn = ""
},
}
});
// end test data

// 3. GET full list of resources
List<ServiceResource> environmentResources = await _resourceRegistry.GetResourceList(env, false, true);
List<AttributeMatchV2> resources = subjectResources.Find(x => x.Subject.Urn == accesspackage)?.Resources;

OrgList orgList = await GetOrgList();
List<AccessPackageService> result = [];

resources?.ForEach(resourceMatch =>
{
ServiceResource fullResource = environmentResources.Find(x => x.Identifier == resourceMatch.Value);

if (fullResource != null)
{
orgList.Orgs.TryGetValue(fullResource.HasCompetentAuthority.Orgcode.ToLower(), out Org organization);
Fixed Show fixed Hide fixed

result.Add(new AccessPackageService()
{
Identifier = resourceMatch.Value,
Title = fullResource?.Title,
HasCompetentAuthority = fullResource.HasCompetentAuthority,
LogoUrl = organization.Logo
});
}
});

return result;
}

[HttpGet]
[Route("designer/api/{org}/resources/altinn2linkservices/{env}")]
public async Task<ActionResult<List<AvailableService>>> GetAltinn2LinkServices(string org, string env)
Expand Down
15 changes: 15 additions & 0 deletions backend/src/Designer/Models/AccessPackageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Altinn.Studio.Designer.Models
{
public class AccessPackageService
{
public string Identifier { get; set; }

public Dictionary<string, string> Title { get; set; }

public CompetentAuthority HasCompetentAuthority { get; set; }

public string LogoUrl { get; set; }
}
}
28 changes: 28 additions & 0 deletions backend/src/Designer/Models/AttributeMatchV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;

namespace Altinn.Studio.Designer.Models
{
/// <summary>
/// This model describes a pair of AttributeId and AttributeValue for use in matching in XACML policies, for instance a resource, a user, a party or an action.
/// </summary>
public class AttributeMatchV2
{
/// <summary>
/// Gets or sets the attribute id for the match
/// </summary>
[Required]
public required string Type { get; set; }

/// <summary>
/// Gets or sets the attribute value for the match
/// </summary>
[Required]
public required string Value { get; set; }

/// <summary>
/// The urn for the attribute
/// </summary>
[Required]
public required string Urn { get; set; }
}
}
9 changes: 9 additions & 0 deletions backend/src/Designer/Models/Dto/SubjectResourcesDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Altinn.Studio.Designer.Models.Dto
{
public class SubjectResourcesDto
{
public List<SubjectResources> Data { get; set; }
}
}
21 changes: 21 additions & 0 deletions backend/src/Designer/Models/SubjectResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#nullable enable
using System.Collections.Generic;

namespace Altinn.Studio.Designer.Models
{
/// <summary>
/// Defines resources that a given subject have access to
/// </summary>
public class SubjectResources
{
/// <summary>
/// The subject
/// </summary>
public required AttributeMatchV2 Subject { get; set; }

/// <summary>
/// List of resources that the given subject has access to
/// </summary>
public required List<AttributeMatchV2> Resources { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ public async Task<List<ServiceResource>> GetResources(string env)
/// Get resource list
/// </summary>
/// <returns>List of all resources</returns>
public async Task<List<ServiceResource>> GetResourceList(string env, bool includeAltinn2)
public async Task<List<ServiceResource>> GetResourceList(string env, bool includeAltinn2, bool includeApps = false)
{

string endpointUrl;

//Checks if not tested locally by passing dev as env parameter
if (!env.ToLower().Equals("dev"))
{
endpointUrl = $"{GetResourceRegistryBaseUrl(env)}{_platformSettings.ResourceRegistryUrl}/resourcelist/?includeApps=false&includeAltinn2={includeAltinn2}";
endpointUrl = $"{GetResourceRegistryBaseUrl(env)}{_platformSettings.ResourceRegistryUrl}/resourcelist/?includeApps={includeApps}&includeAltinn2={includeAltinn2}";
}
else
{
endpointUrl = $"{_platformSettings.ResourceRegistryDefaultBaseUrl}{_platformSettings.ResourceRegistryUrl}/resourcelist/?includeApps=false&includeAltinn2={includeAltinn2}";
endpointUrl = $"{_platformSettings.ResourceRegistryDefaultBaseUrl}{_platformSettings.ResourceRegistryUrl}/resourcelist/?includeApps={includeApps}&includeAltinn2={includeAltinn2}";
}

JsonSerializerOptions options = new JsonSerializerOptions
Expand Down Expand Up @@ -627,6 +627,25 @@ string env
return removeResourceAccessListResponse.StatusCode;
}

public async Task<List<SubjectResources>> GetSubjectResources(List<string> subjects, string env)
{
string resourceRegisterUrl = GetResourceRegistryBaseUrl(env);
string url = $"{resourceRegisterUrl}/resourceregistry/api/v1/resource/bysubjects";

string serializedContent = JsonSerializer.Serialize(subjects, _serializerOptions);
using HttpRequestMessage getSubjectResourcesRequest = new HttpRequestMessage()
{
RequestUri = new Uri(url),
Method = HttpMethod.Post,
Content = new StringContent(serializedContent, Encoding.UTF8, "application/json"),
};
using HttpResponseMessage response = await _httpClient.SendAsync(getSubjectResourcesRequest);
response.EnsureSuccessStatusCode();

SubjectResourcesDto responseContent = await response.Content.ReadAsAsync<SubjectResourcesDto>();
return responseContent.Data;
}

private async Task<List<BrregParty>> GetBrregParties(string url)
{
HttpResponseMessage enheterResponse = await _httpClient.GetAsync(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IResourceRegistry
/// Integration point for retrieving the full list of resources
/// </summary>
/// <returns>The resource full list of all resources if exists</returns>
Task<List<ServiceResource>> GetResourceList(string env, bool includeAltinn2);
Task<List<ServiceResource>> GetResourceList(string env, bool includeAltinn2, bool includeApps = false);

/// <summary>
/// Get Resource from Altinn 2 service
Expand Down Expand Up @@ -169,5 +169,7 @@ public interface IResourceRegistry
/// <param name="env">Chosen environment</param>
/// <returns>HTTP status code of the operation. 204 No content if remove was successful</returns>
Task<HttpStatusCode> RemoveResourceAccessList(string org, string resourceId, string listId, string env);

Task<List<SubjectResources>> GetSubjectResources(List<string> subjects, string env);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public interface IPolicyOptions
public Task<List<ActionOption>> GetActionOptions(CancellationToken cancellationToken = default);

public Task<List<SubjectOption>> GetSubjectOptions(CancellationToken cancellationToken = default);

public Task<List<AccessPackageAreaGroup>> GetAccessPackageOptions(CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
Expand All @@ -20,6 +21,31 @@
_logger = logger;
}

public async Task<List<AccessPackageAreaGroup>> GetAccessPackageOptions(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
// Temp location. Will be moved to CDN
string url = "https://raw.githubusercontent.com/Altinn/altinn-studio-docs/master/content/authorization/architecture/resourceregistry/accesspackages_hier.json";

List<AccessPackageAreaGroup> accessPackageOptions;
JsonSerializerOptions options = new()
{
PropertyNameCaseInsensitive = true,
};

try
{
HttpResponseMessage response = await _client.GetAsync(url, cancellationToken);
string accessPackageOptionsString = await response.Content.ReadAsStringAsync(cancellationToken);
accessPackageOptions = JsonSerializer.Deserialize<List<AccessPackageAreaGroup>>(accessPackageOptionsString, options);
return accessPackageOptions;
}
catch (Exception ex)
{
throw new Exception($"Something went wrong when retrieving Action options", ex);
}
Comment on lines +43 to +46

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

public async Task<List<ActionOption>> GetActionOptions(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task GetFilteredLinkServices()
ExternalServiceCode = "Test2",
ExternalServiceEditionCode = 123
});
ResourceRegistryMock.Setup(r => r.GetResourceList(It.IsAny<string>(), It.IsAny<bool>())).ReturnsAsync(new List<ServiceResource>());
ResourceRegistryMock.Setup(r => r.GetResourceList(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(new List<ServiceResource>());
Altinn2MetadataClientMock.Setup(r => r.AvailableServices(It.IsAny<int>(), It.IsAny<string>())).ReturnsAsync(services);

// Act
Expand Down
Loading
Loading