diff --git a/src/KArtSell.Host/Features/Audit/AuthAuditSql.cs b/src/KArtSell.Host/Features/Audit/AuthAuditSql.cs index 4f4c0ffc..d77fbdbe 100644 --- a/src/KArtSell.Host/Features/Audit/AuthAuditSql.cs +++ b/src/KArtSell.Host/Features/Audit/AuthAuditSql.cs @@ -1,6 +1,7 @@ using Dapper; using System.Data; using NpgsqlTypes; +using KArtSell.BuildingBlocks.Data; namespace KArtSell.Host.Features.Audit; @@ -46,7 +47,7 @@ public sealed class AuthAuditSql : IAuthAuditSql entry.IdentityId, entry.Username, entry.Role, - IpAddress = entry.IpAddress != null ? NpgsqlInet.Parse(entry.IpAddress) : (NpgsqlInet?)null, + IpAddress = entry.IpAddress != null ? new NpgsqlInet(entry.IpAddress) : (NpgsqlInet?)null, entry.UserAgent, entry.Endpoint, entry.HttpMethod, diff --git a/src/KArtSell.Host/Features/Audit/GetAuditLogsEndpoint.cs b/src/KArtSell.Host/Features/Audit/GetAuditLogsEndpoint.cs index a00c9df2..45245020 100644 --- a/src/KArtSell.Host/Features/Audit/GetAuditLogsEndpoint.cs +++ b/src/KArtSell.Host/Features/Audit/GetAuditLogsEndpoint.cs @@ -47,13 +47,29 @@ public sealed class GetAuditLogsEndpoint : Endpoint new AuditLogItem + { + AuditId = entry.AuditId, + EventType = entry.EventType, + IdentityId = entry.IdentityId, + Username = entry.Username, + Role = entry.Role, + IpAddress = entry.IpAddress, + Endpoint = entry.Endpoint, + HttpMethod = entry.HttpMethod, + Status = entry.Status, + ErrorCode = entry.ErrorCode, + ErrorMessage = entry.ErrorMessage, + OccurredAt = entry.OccurredAt + }).ToList(); + await Send.OkAsync(new GetAuditLogsResponse { - Items = logs.ToList(), + Items = items, Total = total, Page = req.Page, PageSize = req.PageSize - }, 200, ct); + }, ct); } } diff --git a/src/KArtSell.Host/Program.cs b/src/KArtSell.Host/Program.cs index d5a296ad..cef64480 100644 --- a/src/KArtSell.Host/Program.cs +++ b/src/KArtSell.Host/Program.cs @@ -9,6 +9,8 @@ using KArtSell.Host.Infrastructure; using KArtSell.Host.OpenApi; using KArtSell.Host.Observability; using KArtSell.Host.Features.Observability; +using KArtSell.Host.Features.Audit; +using KArtSell.Host.Middleware; using KArtSell.BuildingBlocks.Data; using KArtSell.BuildingBlocks.Reliability; using KArtSell.BuildingBlocks.Time; @@ -233,6 +235,9 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); +// Authentication Audit Logging (AEG-AUTH-001) +builder.Services.AddScoped(); + builder.Services.AddProblemDetails(); const string authenticationScheme = "KArtSell"; @@ -342,6 +347,7 @@ if (app.Environment.IsDevelopment()) } app.UseAuthentication(); +app.UseMiddleware(); app.UseAuthorization(); app.UseFastEndpoints(config => config.Endpoints.RoutePrefix = "api"); app.MapHub("/api/hubs/shadow-run");