-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate PDP with OED as external authorization source (#474)
* Integrate PDP with OED as external authorization source #343 - Added new OedAuthzClient for integration with the oed-authz API - Added new dependency to Altinn.ApiClients.Maskinporten v9.0.0 - Added new OedAuthzMaskinportenClientDefinition and Configuration - Added new OedRoleAssignmentWrapper service - Added new SBL bridge API client and service for getting SSN from UserId and PartyId Other relevant changes: - ContextHandler will now retrieve and evaluate policy for the App or Resource and evaluate the subjects of the rules. If any 'urn:altinn:rolecode' subjects are found Altinn roles will be retrieved. If any 'urn:oed:rolecode' subjects are found OED roles will be retrieved. Additional PR made for studio-ops repo for both new (Maskinporten client config) and changes existing to configuration values (SBL bridge API path) * Update for PR comments * Added caching for getting the subjects from the policy * NB!: This will change will fail until ABAC project is updated with the new helper on XacmlPolicy for getting attribute values by category. - Changed some references from OED to Digitalt Dødsbo to match new naming - Renamed "urn:oed:rolecode" attributeId to "urn:digitaltdodsbo:rolecode" - Logic for extracting AttributeIds and Values reimplemented as a generic helper method on the XacmlPolicy object in ABAC project * Fix datatype returned by XacmlPolicy * Update ABAC package version to 0.0.6 * Marked OedRoleAssignmentWrapper excluded from codecoverage as integration tests rely on mock implementation * removed quotes character from log statement --------- Co-authored-by: Jon Kjetil Øye <[email protected]>
- Loading branch information
1 parent
4581c94
commit b0839f1
Showing
49 changed files
with
1,658 additions
and
18 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,47 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Altinn.Platform.Authorization.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.Platform.Authorization.Clients | ||
{ | ||
/// <summary> | ||
/// Client configuration for Oed Authz API integration | ||
/// </summary> | ||
public class OedAuthzClient | ||
{ | ||
/// <summary> | ||
/// Gets an instance of httpclient from httpclientfactory | ||
/// </summary> | ||
public HttpClient Client { get; } | ||
|
||
/// <summary> | ||
/// Initializes the http client for retrieving Oed Authz role-assignments | ||
/// </summary> | ||
/// <param name="client">the http client</param> | ||
/// <param name="settings">the general settings configured for the authorization component</param> | ||
public OedAuthzClient(HttpClient client, IOptions<GeneralSettings> settings) | ||
{ | ||
GeneralSettings generalSettings = settings.Value; | ||
Client = client; | ||
Client.BaseAddress = new Uri(generalSettings.OedAuthzApiEndpoint); | ||
Client.DefaultRequestHeaders.Clear(); | ||
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
} | ||
|
||
/// <summary> | ||
/// post request that gets OED roleassignments | ||
/// </summary> | ||
/// <param name="requestBody">the request body</param> | ||
/// <param name="token">the bearer token</param> | ||
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns> | ||
public async Task<HttpResponseMessage> GetOedRoleAssignments(StringContent requestBody, AuthenticationHeaderValue token) | ||
{ | ||
Client.DefaultRequestHeaders.Authorization = token; | ||
string endpoint = Client.BaseAddress + "v1/pip"; | ||
return await Client.PostAsync(endpoint, requestBody); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Authorization/Clients/OedAuthzMaskinportenClientDefinition.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,36 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Altinn.ApiClients.Maskinporten.Interfaces; | ||
using Altinn.ApiClients.Maskinporten.Models; | ||
using Altinn.Platform.Authorization.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.Platform.Authorization.Clients | ||
{ | ||
/// <summary> | ||
/// Maskinporten client definition for OED Authz API integration | ||
/// </summary> | ||
public class OedAuthzMaskinportenClientDefinition : IClientDefinition | ||
{ | ||
/// <inheritdoc/> | ||
public IMaskinportenSettings ClientSettings { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OedAuthzMaskinportenClientDefinition"/> class | ||
/// </summary> | ||
/// <param name="clientSettings">Maskinporten client settings</param> | ||
public OedAuthzMaskinportenClientDefinition(IOptions<OedAuthzMaskinportenClientSettings> clientSettings) => ClientSettings = clientSettings.Value; | ||
|
||
/// <inheritdoc/> | ||
public Task<ClientSecrets> GetClientSecrets() | ||
{ | ||
ClientSecrets clientSecrets = new ClientSecrets(); | ||
|
||
byte[] bytesFromBase64Jwk = Convert.FromBase64String(ClientSettings.EncodedJwk); | ||
string jwkJson = Encoding.UTF8.GetString(bytesFromBase64Jwk); | ||
clientSecrets.ClientKey = new Microsoft.IdentityModel.Tokens.JsonWebKey(jwkJson); | ||
return Task.FromResult(clientSecrets); | ||
} | ||
} | ||
} |
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,34 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using Altinn.Platform.Authorization.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.Platform.Authorization.Clients | ||
{ | ||
/// <summary> | ||
/// Client configuration for profile api | ||
/// </summary> | ||
public class ProfileClient | ||
{ | ||
/// <summary> | ||
/// Gets an instance of httpclient from httpclientfactory | ||
/// </summary> | ||
public HttpClient Client { get; } | ||
|
||
/// <summary> | ||
/// Initializes the http client for actor | ||
/// </summary> | ||
/// <param name="client">the http client</param> | ||
/// <param name="generalSettings">the general settings configured for the authorization component</param> | ||
public ProfileClient(HttpClient client, IOptions<GeneralSettings> generalSettings) | ||
{ | ||
GeneralSettings settings = generalSettings.Value; | ||
Client = client; | ||
Client.BaseAddress = new Uri(settings.GetBridgeApiEndpoint); | ||
Client.Timeout = new TimeSpan(0, 0, 30); | ||
Client.DefaultRequestHeaders.Clear(); | ||
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
} | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
src/Authorization/Configuration/OedAuthzMaskinportenClientSettings.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,61 @@ | ||
using Altinn.ApiClients.Maskinporten.Interfaces; | ||
|
||
namespace Altinn.Platform.Authorization.Configuration | ||
{ | ||
/// <summary> | ||
/// Configuration for Maskinporten Client for Oed role-assignments API integration | ||
/// </summary> | ||
public class OedAuthzMaskinportenClientSettings : IMaskinportenSettings | ||
{ | ||
/// <inheritdoc/> | ||
public string Environment { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string ClientId { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string Scope { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string EncodedJwk { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string Resource { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string CertificatePkcs12Path { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string CertificatePkcs12Password { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string CertificateStoreThumbprint { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string EncodedX509 { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string ConsumerOrgNo { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string EnterpriseUserName { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string EnterpriseUserPassword { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public bool? ExhangeToAltinnToken { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public string TokenExchangeEnvironment { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public bool? UseAltinnTestOrg { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public bool? EnableDebugLogging { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public bool? OverwriteAuthorizationHeader { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Altinn.Platform.Authorization.Models.Oed | ||
{ | ||
/// <summary> | ||
/// Model for OED role assignment | ||
/// </summary> | ||
public class OedRoleAssignment | ||
{ | ||
/// <summary> | ||
/// The OED/Digitalt dødsbo role code | ||
/// </summary> | ||
[JsonPropertyName("urn:digitaltdodsbo:rolecode")] | ||
public string OedRoleCode { get; set; } | ||
|
||
/// <summary> | ||
/// The deceased person's pid | ||
/// </summary> | ||
public string From { get; set; } | ||
|
||
/// <summary> | ||
/// The inheriting person's pid | ||
/// </summary> | ||
public string To { get; set; } | ||
|
||
/// <summary> | ||
/// The datetime created | ||
/// </summary> | ||
public DateTime Created { get; set; } | ||
} | ||
} |
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,18 @@ | ||
namespace Altinn.Platform.Authorization.Models | ||
{ | ||
/// <summary> | ||
/// Model for requesting OED/Digitalt dødsbo role assignments between two persons | ||
/// </summary> | ||
public class OedRoleAssignmentRequest | ||
{ | ||
/// <summary> | ||
/// The person the OED/Digitalt dødsbo role if provided from (the deceased) | ||
/// </summary> | ||
public string From { get; set; } | ||
|
||
/// <summary> | ||
/// The person the OED/Digitalt dødsbo role if provided to | ||
/// </summary> | ||
public string To { get; set; } | ||
} | ||
} |
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,16 @@ | ||
using System.Collections.Generic; | ||
using Altinn.Platform.Authorization.Models.Oed; | ||
|
||
namespace Altinn.Platform.Authorization.Models | ||
{ | ||
/// <summary> | ||
/// Model for a list of OED/Digitalt dødsbo role assignment | ||
/// </summary> | ||
public class OedRoleAssignments | ||
{ | ||
/// <summary> | ||
/// The list of OED/Digitalt dødsbo role assignments | ||
/// </summary> | ||
public List<OedRoleAssignment> RoleAssignments { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.