Simplify GetDocument authorization logic

Refactor `DocumentController.GetDocument` to exclusively support the "Sender" role by removing logic for the "Receiver" role. Update the `[Authorize]` attribute to enforce the `AuthPolicy.Sender` policy instead of `AuthPolicy.SenderOrReceiver`.

Remove the `AuthPolicy.SenderOrReceiver` policy from `Program.cs` authorization configuration, reflecting the decision to separate role-based access more explicitly. The application now defines distinct policies for "Sender" and "Receiver" roles without combining them.
This commit is contained in:
2026-06-25 15:18:20 +02:00
parent b5bb2bbaae
commit 67798b35da
2 changed files with 7 additions and 27 deletions

View File

@@ -30,11 +30,8 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
/// <param name="query">Encoded envelope key.</param> /// <param name="query">Encoded envelope key.</param>
/// <param name="cancel">Cancellation token.</param> /// <param name="cancel">Cancellation token.</param>
[HttpGet] [HttpGet]
[Authorize(Policy = AuthPolicy.SenderOrReceiver)] [Authorize(Policy = AuthPolicy.Sender)]
public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery? query = null) public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery? query = null)
{
// Sender: expects query with envelope key
if (await this.IsUserInPolicyAsync(AuthPolicy.Sender))
{ {
if (query is null) if (query is null)
return BadRequest("Missing document query."); return BadRequest("Missing document query.");
@@ -45,22 +42,6 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
: NotFound("Document is empty."); : NotFound("Document is empty.");
} }
// Receiver: resolve envelope id from claims
if (await this.IsUserInPolicyAsync(AuthPolicy.Receiver))
{
if (query is not null)
return BadRequest("Query parameters are not allowed for receiver role.");
var envelopeId = User.EnvelopeId();
var receiverDoc = await mediator.Send(new ReadDocumentQuery { EnvelopeId = envelopeId }, cancel);
return receiverDoc.ByteData is byte[] receiverDocByte
? File(receiverDocByte, "application/octet-stream")
: NotFound("Document is empty.");
}
return Unauthorized();
}
/// <summary> /// <summary>
/// Gets the document for the specified envelope key. /// Gets the document for the specified envelope key.
/// </summary> /// </summary>

View File

@@ -255,7 +255,6 @@ try
// Authorization Policies // Authorization Policies
builder.Services.AddAuthorizationBuilder() builder.Services.AddAuthorizationBuilder()
.AddPolicy(AuthPolicy.SenderOrReceiver, policy => policy.RequireRole(Role.Sender, Role.Receiver.Full))
.AddPolicy(AuthPolicy.Sender, policy => policy .AddPolicy(AuthPolicy.Sender, policy => policy
.RequireRole(Role.Sender) .RequireRole(Role.Sender)
.AddAuthenticationSchemes(AuthScheme.Sender)) .AddAuthenticationSchemes(AuthScheme.Sender))