feat(zgw): real per-request identity seam + citizen-scoping (WP-53)
Replaces the hardcoded DocumentStore.DemoOwner and the static ZgwOptions
UserId/UserRepresentation with one per-request CallerIdentity, resolved by a
pluggable IIdentityProvider (StubIdentityProvider reads X-Role/X-Subject
today; a real OIDC/DigiD provider swaps in without touching any consumer).
- Domain/Authorization/{CallerIdentity,IIdentityProvider,StubIdentityProvider}.cs
+ a resolution middleware in Program.cs, right after correlation-id.
- Authz.ResolvePrincipal(ctx) keeps its signature (now reads ctx.Caller().Role),
so its ~15 call sites needed no changes.
- Every endpoint that passed DocumentStore.DemoOwner to a store now passes
ctx.Caller().Bsn.
- ZgwTokenProvider gains Mint(CallerIdentity) alongside the original Mint()
(kept for calls not tied to one citizen); ZgwHttpClient threads an optional
caller through to pick the right overload.
- IZaakSource gains ListMyCases(caller, now) — the citizen-scoped read
OpenZaakZaakSource backs with ZGW's rol__...__inpBsn filter. GET /applications
now routes through it instead of ApplicationStore directly, closing the last
"reads a static store" gap for a citizen-facing endpoint.
Backend 159/159 tests (+8, incl. an HTTP-level two-identity scoping proof),
npm run ci green, no api-client drift.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using BigRegister.Api.Contracts;
|
||||
using BigRegister.Api.Data;
|
||||
using BigRegister.Domain.Authorization;
|
||||
|
||||
namespace BigRegister.Api.Zgw;
|
||||
|
||||
@@ -26,15 +27,15 @@ public sealed class OpenZaakDocumentSource(HttpClient http, ZgwTokenProvider tok
|
||||
// existing sync upload/submit endpoints, same reasoning as OpenZaakZaakSource.
|
||||
public UploadResponse Upload(
|
||||
string localId, string categoryId, string wizardId, string fileName, string contentType,
|
||||
byte[] content, string owner) =>
|
||||
UploadAsync(localId, categoryId, wizardId, fileName, contentType, content, owner)
|
||||
byte[] content, CallerIdentity caller) =>
|
||||
UploadAsync(localId, categoryId, wizardId, fileName, contentType, content, caller)
|
||||
.GetAwaiter().GetResult();
|
||||
|
||||
private async Task<UploadResponse> UploadAsync(
|
||||
string localId, string categoryId, string wizardId, string fileName, string contentType,
|
||||
byte[] content, string owner)
|
||||
byte[] content, CallerIdentity caller)
|
||||
{
|
||||
var doc = DocumentStore.Add(localId, categoryId, wizardId, fileName, contentType, content, owner);
|
||||
var doc = DocumentStore.Add(localId, categoryId, wizardId, fileName, contentType, content, caller.Bsn);
|
||||
|
||||
if (!options.InformatieobjecttypeUrls.TryGetValue(categoryId, out var informatieobjecttypeUrl))
|
||||
throw new InvalidOperationException(
|
||||
@@ -54,7 +55,7 @@ public sealed class OpenZaakDocumentSource(HttpClient http, ZgwTokenProvider tok
|
||||
// ponytail: hardcoded "openbaar" (public) — real usage would likely vary the
|
||||
// confidentiality level per category (e.g. an identity document is more sensitive
|
||||
// than a diploma); a fixed value is enough to prove the seam end-to-end.
|
||||
Vertrouwelijkheidaanduiding: "openbaar"));
|
||||
Vertrouwelijkheidaanduiding: "openbaar"), caller);
|
||||
|
||||
DocumentStore.SetDrcUrl(doc.DocumentId, eio.Url);
|
||||
return new UploadResponse(doc.DocumentId, doc.LocalId);
|
||||
@@ -64,21 +65,21 @@ public sealed class OpenZaakDocumentSource(HttpClient http, ZgwTokenProvider tok
|
||||
/// once a zaak exists, POST a zaakinformatieobject for every document that has a DRC url —
|
||||
/// documents uploaded before Zgw:Enabled was ever true (or under a config gap) simply have
|
||||
/// no DrcUrl yet and are skipped, matching "nothing extra to link" for the local case.</summary>
|
||||
public void LinkToZaak(IReadOnlyList<string> documentIds, string? zaakUrl)
|
||||
public void LinkToZaak(IReadOnlyList<string> documentIds, string? zaakUrl, CallerIdentity caller)
|
||||
{
|
||||
DocumentStore.Link(documentIds);
|
||||
if (zaakUrl is null) return;
|
||||
LinkToZaakAsync(documentIds, zaakUrl).GetAwaiter().GetResult();
|
||||
LinkToZaakAsync(documentIds, zaakUrl, caller).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private async Task LinkToZaakAsync(IReadOnlyList<string> documentIds, string zaakUrl)
|
||||
private async Task LinkToZaakAsync(IReadOnlyList<string> documentIds, string zaakUrl, CallerIdentity caller)
|
||||
{
|
||||
foreach (var documentId in documentIds)
|
||||
{
|
||||
var drcUrl = DocumentStore.Get(documentId)?.DrcUrl;
|
||||
if (drcUrl is null) continue;
|
||||
await zgw.PostAsync<JsonElement>($"{options.ZrcBaseUrl}/zaakinformatieobjecten",
|
||||
new CreateZaakInformatieobjectRequest(zaakUrl, drcUrl));
|
||||
new CreateZaakInformatieobjectRequest(zaakUrl, drcUrl), caller);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user