Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

58 рядки
2.2KB

  1. namespace Campaign_Tracker.Server.Audit;
  2. /// <summary>
  3. /// Shared audit event type constants used across all application features.
  4. /// </summary>
  5. public static class AuditEventType
  6. {
  7. public const string SessionLogin = "SESSION_LOGIN";
  8. public const string SessionLoginFailure = "SESSION_LOGIN_FAILURE";
  9. public const string SessionRefresh = "SESSION_REFRESH";
  10. public const string SessionRefreshFailure = "SESSION_REFRESH_FAILURE";
  11. public const string SessionLogout = "SESSION_LOGOUT";
  12. public const string AuthorizationAllowed = "AUTHORIZATION_ALLOWED";
  13. public const string AuthorizationDenied = "AUTHORIZATION_DENIED";
  14. }
  15. /// <summary>
  16. /// A general-purpose audit event record written by any application feature.
  17. /// All fields are required; no nullable properties to prevent incomplete records.
  18. /// </summary>
  19. public sealed record AuditEvent(
  20. string EventType,
  21. string ActorIdentity,
  22. string Resource,
  23. string Outcome,
  24. string TraceIdentifier,
  25. DateTimeOffset RecordedAt);
  26. /// <summary>
  27. /// Shared audit logging service contract. All application features record
  28. /// security-relevant events through this interface — features must not
  29. /// implement their own audit persistence (AC #3).
  30. ///
  31. /// Record() is synchronous and throws if the underlying store is unavailable.
  32. /// Callers must not silently swallow these exceptions; failed audit writes
  33. /// must block or surface the originating action (AC #5).
  34. /// </summary>
  35. public interface IAuditService
  36. {
  37. /// <summary>
  38. /// Appends an audit event to the durable store.
  39. /// Throws <see cref="AuditServiceUnavailableException"/> if the store cannot be written to.
  40. /// </summary>
  41. void Record(AuditEvent auditEvent);
  42. /// <summary>
  43. /// Returns the most recent events from the in-process cache for review and testing.
  44. /// For full historical queries spanning 365+ days, read the underlying store directly.
  45. /// </summary>
  46. IReadOnlyCollection<AuditEvent> GetRecent(int maxCount = 200);
  47. }
  48. public sealed class AuditServiceUnavailableException : Exception
  49. {
  50. public AuditServiceUnavailableException(string message, Exception innerException)
  51. : base(message, innerException) { }
  52. }

Powered by TurnKey Linux.