feat(application): audit abstractions (UDT-010 B2)
Introduces the contract layer for audit logging per design #D-8:
SIGCM2.Application/Audit/:
- IAuditContext — request-scoped accessor for ActorUserId/ActorRoleId/
Ip/UserAgent/CorrelationId. Populated by CorrelationIdMiddleware +
AuditActorMiddleware (B4).
- IAuditLogger.LogAsync(action, targetType, targetId, metadata?, ct) —
domain-level audit emitter. Enlists in ambient TransactionScope
(fail-closed per #REQ-AUD-4).
- ISecurityEventLogger.LogAsync(action, result, actorUserId?, attemptedUsername?,
sessionId?, failureReason?, metadata?, ct) — security-events emitter
separate from IAuditLogger (different retention, no transaction scope,
captures login/logout/refresh/permission.denied).
- AuditOptions — bindable POCO with SanitizedKeys[] defaults (used by
JsonSanitizer in B3).
- AuditEventDto — read projection for GET /api/v1/audit/events (B10).
- AuditEventFilter — query filter record with default Limit=50.
SIGCM2.Domain/Exceptions/:
- AuditContextMissingException : DomainException — fail-closed sentinel
thrown when IAuditLogger is called without ActorUserId in a user-scoped
command (#REQ-AUD-4).
Tests (Strict TDD — shape contract, RED → GREEN):
- tests/SIGCM2.Application.Tests/Audit/AuditAbstractionsTests.cs: 11 tests
covering nullability, signatures, default options, record equality.
Suite: 336/336 Application.Tests (prev 325 + 11 new). 130/130 Api.Tests.
Refs: sdd/udt-010-auditoria-trazabilidad/{spec#REQ-AUD-3/4/5, design#D-8, tasks#B2}
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace SIGCM2.Domain.Exceptions;
|
||||
|
||||
/// Thrown when IAuditLogger.LogAsync runs without ActorUserId in the audit context while the action
|
||||
/// requires user attribution (i.e. not a system job). Fail-closed: better to break the command than
|
||||
/// to persist an audit event with a missing actor.
|
||||
public sealed class AuditContextMissingException : DomainException
|
||||
{
|
||||
public AuditContextMissingException()
|
||||
: base("Audit context is missing ActorUserId for a user-scoped action. Ensure AuditActorMiddleware ran and the request is authenticated.")
|
||||
{ }
|
||||
}
|
||||
Reference in New Issue
Block a user