feat(security): enforcement — filtrage caméra dans les endpoints sensibles (#175)
This commit is contained in:
1 parent
0f47236c08
commit
b97d3bec11
24 files changed
+313
-25
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Security.Claims;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Events.Commands.CreateEvent;
|
||||
using Heimdall.Application.Events.Commands.AttachSnapshot;
|
||||
@@ -48,7 +49,8 @@ public class EventsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new GetEventQuery(id), ct);
|
||||
var userId = GetUserId();
|
||||
var result = await _mediator.Send(new GetEventQuery(id, userId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
@@ -74,7 +76,8 @@ public class EventsController : ControllerBase
|
||||
if (type is not null && Enum.TryParse<EventType>(type, true, out var t))
|
||||
parsedType = t;
|
||||
|
||||
var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q), ct);
|
||||
var userId = GetUserId();
|
||||
var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q, userId), ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
@@ -84,7 +87,8 @@ public class EventsController : ControllerBase
|
||||
[ProducesResponseType(typeof(List<CameraEventResponse>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetRecentByCamera(Guid cameraId, [FromQuery] int count = 20, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _mediator.Send(new GetRecentByCameraQuery(cameraId, count), ct);
|
||||
var userId = GetUserId();
|
||||
var result = await _mediator.Send(new GetRecentByCameraQuery(cameraId, count, userId), ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
@@ -113,6 +117,11 @@ public class EventsController : ControllerBase
|
||||
? Ok()
|
||||
: StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
private Guid? GetUserId()
|
||||
{
|
||||
var sub = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value
|
||||
?? User?.FindFirst("sub")?.Value;
|
||||
return Guid.TryParse(sub, out var userId) ? userId : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user