-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a105864
commit acc1e00
Showing
44 changed files
with
3,189 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"local>Altinn/renovate-config" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<Project> | ||
|
||
<Import Project="..\Directory.Build.props" /> | ||
|
||
</Project> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
src/pkgs/Altinn.Authorization.PEP/Altinn.Authorization.PEP.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DA970EDE-848F-4A7A-8F67-13835BD4DA89}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP", "src\Altinn.Authorization.PEP\Altinn.Authorization.PEP.csproj", "{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DDA3BB50-F068-4BDB-8684-CBF68ECDE9FC}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP.Tests", "tests\Altinn.Authorization.PEP.Tests\Altinn.Authorization.PEP.Tests.csproj", "{9005F003-ECD8-4EA7-9149-F47F4FEC5697}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C} = {DA970EDE-848F-4A7A-8F67-13835BD4DA89} | ||
{9005F003-ECD8-4EA7-9149-F47F4FEC5697} = {DDA3BB50-F068-4BDB-8684-CBF68ECDE9FC} | ||
EndGlobalSection | ||
EndGlobal |
25 changes: 25 additions & 0 deletions
25
...kgs/Altinn.Authorization.PEP/src/Altinn.Authorization.PEP/Altinn.Authorization.PEP.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<!-- NuGet package properties --> | ||
<IsPackageProject>true</IsPackageProject> | ||
<PackageId>Altinn.Authorization.PEP</PackageId> | ||
<PackageTags>Altinn;Studio;Authorization;Policy;Enforcement;Point</PackageTags> | ||
<Description> | ||
Policy Enforcement Point for Attribute-based authorization using | ||
Altinn.Authorization.ABAC in ASP.Net apps. | ||
See our repository for the full documentation. | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" /> | ||
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="all" /> | ||
<PackageReference Include="Altinn.Authorization.ABAC" /> | ||
</ItemGroup> | ||
|
||
</Project> |
71 changes: 71 additions & 0 deletions
71
...s/Altinn.Authorization.PEP/src/Altinn.Authorization.PEP/Authorization/AppAccessHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Altinn.Authorization.ABAC.Xacml.JsonProfile; | ||
using Altinn.Common.PEP.Helpers; | ||
using Altinn.Common.PEP.Interfaces; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.HttpOverrides; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Altinn.Common.PEP.Authorization | ||
{ | ||
/// <summary> | ||
/// AuthorizationHandler that is created for handling access to app. | ||
/// Authorizes based om AppAccessRequirement and app id from route | ||
/// <see href="https://docs.asp.net/en/latest/security/authorization/policies.html"/> for details about authorization | ||
/// in asp.net core | ||
/// </summary> | ||
public class AppAccessHandler : AuthorizationHandler<AppAccessRequirement> | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly IPDP _pdp; | ||
private readonly ILogger _logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AppAccessHandler"/> class. | ||
/// </summary> | ||
/// <param name="httpContextAccessor">The http context accessor</param> | ||
/// <param name="pdp">The pdp</param> | ||
/// <param name="logger">The logger. </param> | ||
public AppAccessHandler( | ||
IHttpContextAccessor httpContextAccessor, | ||
IPDP pdp, | ||
ILogger<AppAccessHandler> logger) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_pdp = pdp; | ||
_logger = logger; | ||
} | ||
|
||
/// <summary> | ||
/// This method authorize access bases on context and requirement | ||
/// Is triggered by annotation on MVC action and setup in startup. | ||
/// </summary> | ||
/// <param name="context">The context</param> | ||
/// <param name="requirement">The requirement</param> | ||
/// <returns>A Task</returns> | ||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, AppAccessRequirement requirement) | ||
{ | ||
HttpContext httpContext = _httpContextAccessor.HttpContext; | ||
|
||
XacmlJsonRequestRoot request = DecisionHelper.CreateDecisionRequest(context, requirement, _httpContextAccessor.HttpContext.GetRouteData()); | ||
|
||
XacmlJsonResponse response = await _pdp.GetDecisionForRequest(request); | ||
|
||
if (response?.Response == null) | ||
{ | ||
throw new ArgumentNullException("response"); | ||
} | ||
|
||
if (!DecisionHelper.ValidatePdpDecision(response.Response, context.User)) | ||
{ | ||
context.Fail(); | ||
} | ||
|
||
context.Succeed(requirement); | ||
await Task.CompletedTask; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tinn.Authorization.PEP/src/Altinn.Authorization.PEP/Authorization/AppAccessRequirement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace Altinn.Common.PEP.Authorization | ||
{ | ||
/// <summary> | ||
/// Requirement for authorization policies used for accessing apps. | ||
/// <see href="https://docs.asp.net/en/latest/security/authorization/policies.html"/> for details about authorization | ||
/// in asp.net core. | ||
/// </summary> | ||
public class AppAccessRequirement : IAuthorizationRequirement | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AppAccessRequirement"/> class | ||
/// </summary> | ||
/// <param name="actionType">The Action type for this requirement</param> | ||
public AppAccessRequirement(string actionType) | ||
{ | ||
this.ActionType = actionType; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets The Action type defined for the policy using this requirement | ||
/// </summary> | ||
public string ActionType { get; set; } | ||
} | ||
} |
Oops, something went wrong.