-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add model for delegation request * add step builder for delegation request * add scaffold for delegation client * add scaffold to signing delegation service * temp solution for const instead of magic strings * add delegation client * weird state * update handling of party id to use party uuid * rm sign delegate rights from access management client
- Loading branch information
Showing
20 changed files
with
430 additions
and
37 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
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
5 changes: 4 additions & 1 deletion
5
src/Altinn.App.Core/Features/Signing/Interfaces/ISigningDelegationService.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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
using Altinn.App.Core.Features.Signing.Models; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
|
||
namespace Altinn.App.Core.Features.Signing.Interfaces; | ||
|
||
internal interface ISigningDelegationService | ||
{ | ||
internal Task<List<SigneeContext>> DelegateSigneeRights( | ||
string taskId, | ||
Instance instance, | ||
List<SigneeContext> signeeContexts, | ||
CancellationToken? ct = null | ||
CancellationToken ct | ||
); | ||
} |
12 changes: 9 additions & 3 deletions
12
src/Altinn.App.Core/Features/Signing/Interfaces/ISigningService.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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
using Altinn.App.Core.Features.Signing.Models; | ||
using Altinn.App.Core.Internal.Sign; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
|
||
namespace Altinn.App.Core.Features.Signing.Interfaces; | ||
|
||
internal interface ISigningService | ||
{ | ||
Task<List<SigneeContext>> InitializeSignees(string taskId, CancellationToken? ct = null); | ||
Task<List<SigneeContext>> InitializeSignees(string taskId, CancellationToken ct); | ||
|
||
Task<List<SigneeContext>> ProcessSignees(List<SigneeContext> signeeContexts, CancellationToken? ct = null); | ||
Task<List<SigneeContext>> ProcessSignees( | ||
string taskId, | ||
Instance instance, | ||
List<SigneeContext> signeeContexts, | ||
CancellationToken ct | ||
); | ||
|
||
List<Signee> ReadSignees(); | ||
List<SigneeContext> ReadSignees(); | ||
} |
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
33 changes: 30 additions & 3 deletions
33
src/Altinn.App.Core/Features/Signing/SigningDelegationService.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
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,9 @@ | ||
namespace Altinn.App.Core.Helpers; | ||
|
||
internal sealed class AppIdHelper | ||
{ | ||
internal string ToResourceId(string appId) | ||
{ | ||
return ""; //TODO | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/Altinn.App.Core/Internal/AccessManagement/AccessManagementClient.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,89 @@ | ||
using System.Net.Http.Headers; | ||
using System.Text.Json; | ||
using Altinn.App.Core.Configuration; | ||
using Altinn.App.Core.Features; | ||
using Altinn.App.Core.Internal.AccessManagement.Exceptions; | ||
using Altinn.App.Core.Internal.AccessManagement.Helpers; | ||
using Altinn.App.Core.Internal.AccessManagement.Models; | ||
using Altinn.App.Core.Internal.AccessManagement.Models.Shared; | ||
using Altinn.App.Core.Internal.App; | ||
using Altinn.Common.AccessTokenClient.Services; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Altinn.App.Core.Internal.AccessManagement; | ||
|
||
internal interface IAccessManagementClient | ||
{ | ||
public Task<DelegationResponse> DelegateRights(DelegationRequest delegation, CancellationToken ct); | ||
} | ||
|
||
internal sealed class AccessManagementClient( | ||
ILogger<AccessManagementClient> logger, | ||
HttpClient httpClient, | ||
IAppMetadata appMetadata, | ||
IAccessTokenGenerator accessTokenGenerator, | ||
PlatformSettings platformSettings, | ||
Telemetry? telemetry = null | ||
) : IAccessManagementClient | ||
{ | ||
internal void DelegationCheck() { } | ||
|
||
public async Task<DelegationResponse> DelegateRights(DelegationRequest delegation, CancellationToken ct) | ||
{ | ||
// TODO: telemetry | ||
HttpResponseMessage? httpResponseMessage = null; | ||
string? httpContent = null; | ||
UrlHelper urlHelper = new(platformSettings); | ||
try | ||
{ | ||
var application = await appMetadata.GetApplicationMetadata(); | ||
|
||
var uri = urlHelper.CreateInstanceDelegationUrl(delegation.ResourceId, delegation.InstanceId); | ||
var body = JsonSerializer.Serialize(delegation); | ||
|
||
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri) | ||
{ | ||
Content = new StringContent(body, new MediaTypeHeaderValue("application/json")), | ||
}; | ||
httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
httpRequestMessage.Headers.Add( | ||
"PlatformAccessToken", | ||
accessTokenGenerator.GenerateAccessToken(application.Org, application.AppIdentifier.App) | ||
); | ||
|
||
httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, ct); | ||
httpContent = await httpResponseMessage.Content.ReadAsStringAsync(ct); | ||
DelegationResponse? response; | ||
if (httpResponseMessage.IsSuccessStatusCode) | ||
{ | ||
response = JsonSerializer.Deserialize<DelegationResponse>(httpContent); | ||
if (response is null) | ||
throw new JsonException("Couldn't deserialize access management response."); | ||
} | ||
else | ||
{ | ||
throw new HttpRequestException("Got error status code for access management request."); | ||
} | ||
return response; | ||
} | ||
catch (Exception e) | ||
{ | ||
var ex = new DelegationException( | ||
$"Something went wrong when processing the access management request.", | ||
httpResponseMessage, | ||
httpContent, | ||
e | ||
); | ||
logger.LogError(ex, "Error when processing access management request."); | ||
|
||
// TODO: metrics | ||
|
||
throw ex; | ||
} | ||
finally | ||
{ | ||
httpResponseMessage?.Dispose(); | ||
} | ||
} | ||
} |
Oops, something went wrong.