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

fix(webAPI): Specifying EndUserId on the ServiceOwner Search endpoint produces 500 - Internal Server error #1234

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -5161,7 +5161,7 @@
}
},
{
"description": "Filter by Display state ",
"description": "Filter by Display state",
"explode": true,
"in": "query",
"name": "systemLabel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ public interface IAltinnAuthorization
{
public Task<DialogDetailsAuthorizationResult> GetDialogDetailsAuthorization(
DialogEntity dialogEntity,
string? endUserId = null,
CancellationToken cancellationToken = default);

public Task<DialogSearchAuthorizationResult> GetAuthorizedResourcesForSearch(
List<string> constraintParties,
List<string> constraintServiceResources,
string? endUserId = null,
CancellationToken cancellationToken = default);

public Task<AuthorizedPartiesResult> GetAuthorizedParties(IPartyIdentifier authenticatedParty, bool flatten = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo

var authorizationResult = await _altinnAuthorization.GetDialogDetailsAuthorization(
dialog,
request.EndUserId,
cancellationToken);

if (!authorizationResult.HasAccessToMainResource())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public sealed class SearchDialogQuery : SortablePaginationParameter<SearchDialog
public string? Process { get; init; }

/// <summary>
/// Filter by Display state
/// Filter by Display state
knuhau marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public List<SystemLabel.Values>? SystemLabel { get; set; }

Expand Down Expand Up @@ -162,7 +162,6 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
var authorizedResources = await _altinnAuthorization.GetAuthorizedResourcesForSearch(
request.Party ?? [],
request.ServiceResource ?? [],
request.EndUserId,
cancellationToken);
dialogQuery = _db.Dialogs.PrefilterAuthorizedDialogs(authorizedResources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ public AltinnAuthorizationClient(

public async Task<DialogDetailsAuthorizationResult> GetDialogDetailsAuthorization(
DialogEntity dialogEntity,
string? endUserId,
CancellationToken cancellationToken = default)
{
var request = new DialogDetailsAuthorizationRequest
{
Claims = GetOrCreateClaimsBasedOnEndUserId(endUserId),
Claims = _user.GetPrincipal().Claims.ToList(),
knuhau marked this conversation as resolved.
Show resolved Hide resolved
ServiceResource = dialogEntity.ServiceResource,
DialogId = dialogEntity.Id,
Party = dialogEntity.Party,
Expand All @@ -64,10 +63,9 @@ public async Task<DialogDetailsAuthorizationResult> GetDialogDetailsAuthorizatio
public async Task<DialogSearchAuthorizationResult> GetAuthorizedResourcesForSearch(
List<string> constraintParties,
List<string> serviceResources,
string? endUserId,
CancellationToken cancellationToken = default)
{
var claims = GetOrCreateClaimsBasedOnEndUserId(endUserId);
var claims = _user.GetPrincipal().Claims.ToList();
knuhau marked this conversation as resolved.
Show resolved Hide resolved
var request = new DialogSearchAuthorizationRequest
{
Claims = claims,
Expand Down Expand Up @@ -187,21 +185,6 @@ private void LogIfIndeterminate(XacmlJsonResponse? response, XacmlJsonRequestRoo
}
}

private List<Claim> GetOrCreateClaimsBasedOnEndUserId(string? endUserId)
{
List<Claim> claims = [];
if (endUserId is not null && PartyIdentifier.TryParse(endUserId, out var partyIdentifier))
{
claims.Add(new Claim(partyIdentifier.Prefix(), partyIdentifier.Id));
}
else
{
claims.AddRange(_user.GetPrincipal().Claims);
}

return claims;
}

private async Task<XacmlJsonResponse?> SendPdpRequest(
XacmlJsonRequestRoot xacmlJsonRequest, CancellationToken cancellationToken) =>
await SendRequest<XacmlJsonResponse>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public LocalDevelopmentAltinnAuthorization(IDialogDbContext db)
[SuppressMessage("Performance", "CA1822:Mark members as static")]
public Task<DialogDetailsAuthorizationResult> GetDialogDetailsAuthorization(
DialogEntity dialogEntity,
string? _,
CancellationToken __)
{
// Just allow everything
return Task.FromResult(new DialogDetailsAuthorizationResult { AuthorizedAltinnActions = dialogEntity.GetAltinnActions() });
}

public async Task<DialogSearchAuthorizationResult> GetAuthorizedResourcesForSearch(List<string> constraintParties, List<string> serviceResources, string? endUserId,
public async Task<DialogSearchAuthorizationResult> GetAuthorizedResourcesForSearch(List<string> constraintParties, List<string> serviceResources,
CancellationToken cancellationToken = default)
{

Expand Down
Loading