Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
7.5 KiB
Design
Full design with approaches and the user's approved calls: docs/superpowers/specs/2026-11-30-admin-audit-log-design.md.
Context
AppAccessAspect(solvway-mobile-api/.../useraccess/AppAccessAspect.java) wraps every controller method. It already:- knows the admin from the JWT;
- resolves
@AdminModulefrom the method, falling back to the class; - refuses with 403 on a missing module, super admin required or pending reset;
- publishes a
ResponseTimerecord per call to services-log over Pub/Sub (response-time-log-topic).
- services-log stores in MySQL schema
service-logwith JPA. It creates its topics and subscriptions at startup (configuration/PubSubConfig.java), listens inpubsub/PubSubListener.java, and archives response times on a schedule (scheduler/ResponseTimeLogArchiveScheduler.java). - Local Pub/Sub: the emulator creates the topics listed in
local/pubsub/topics.txt. - Client IP: the portal already forwards
X-Client-Ipon every call (app/lib/server/mobileApi.ts). - babyboo reference:
- core-libs
model/AuditEvent.java; - mobile-api
useraccess/Audited.java,useraccess/AuditChanges.javaand the audit part ofuseraccess/AppAccessAspect.java; service/AuditLogService.javaandcontroller/AdminAuditLogController.java;- services-log
controller/AuditEventController.java,model/AuditEventLog.java,repo/AuditEventLogRepository.javaandservice/AuditEventLogPurge.java; - portal
app/audit-log/page.tsxandapp/api/audit-log/**.
- core-libs
Goals / Non-Goals
Goals:
- record admin writes, refusals and three sensitive reads;
- record allow-listed changes;
- delete events after 730 days;
- an Audit log screen.
Non-Goals:
- member and public calls;
- page views;
- sign-ins (covered by
login_audit); - legacy
/log/savecleanup.
Decisions
-
AuditEventin core-libs: fieldscompanyId,occurredAt,actor,module,action,httpMethod,pathTemplate,targetId,outcome,httpStatus,clientIpandchanges(a JSON string). It is the shared contract, so it lands first. -
Table
service-log.audit_event:- Columns follow the event fields.
changesis TEXT.- Indexes:
occurred_at,(actor, occurred_at)and(module, action, occurred_at).
-
What the aspect records:
- Writes: every handler under a class mapped to
/api/adminwhose HTTP method is not GET. - Sensitive GETs: handlers annotated
@Audited(lead export, event-lead export, email detail). - Skipped: handlers annotated
@Audited(skip = true)(event-leadmatch) and everyAdminAuthControllerhandler exceptfirstLogin. - Actor required: only calls whose admin token resolved to a user are recorded. A refusal at the access check (403 from the module or super-admin check, or
PASSWORD_RESET_REQUIRED) for such a user is recorded asFAILURE.
- Writes: every handler under a class mapped to
-
Event fields, as the aspect builds them:
- Action:
@Audited(action); otherwise derived from the handler: drop anAdminprefix and aControllersuffix, then UPPER_SNAKE both parts and join them, soAdminUserController.updatebecomesUSER_UPDATE. - Path template: the class
@RequestMappingplus the method mapping, for example/api/admin/users/{id}. - Target id: the last path variable (the record acted on, e.g. the event lead in
/event-leads/{eventUuid}/leads/{eventLeadUuid}).@Audited(target = false)records none: the unlock path carries a username as typed at a failed sign-in, which can be a mistyped password. - Outcome:
SUCCESSfor a 2xxResponseEntity, or when there is noResponseEntity;- otherwise
FAILUREwith the status, taken from a non-2xxResponseEntityor from a thrownResponseStatusException; - any other exception is
FAILUREwith 500.
- Client IP: the
X-Client-Ipheader.
- Action:
-
AuditChanges: a request-scoped holder. Services callAuditChanges.put(field, before, after)orAuditChanges.fields(names...), and the aspect serialises the result intochanges. The allow-list is enforced where the values are supplied:AdminUserServicecreate and update:roles(role names) andenabled;AdminRoleServiceset modules:moduleswith the codes added and removed;AdminLeadServiceandAdminEventLeadServiceedits: changed field names only;AdminLoginSecurityServiceconfig and password rules: the changed settings with before and after.
-
Publishing: to
audit-event-topic, after the handler finishes, through the existingPubSubUtilandPubSubTemplatepattern used forResponseTime. Any exception is logged at WARN and swallowed. -
services-log:
- Creates
audit-event-topicandaudit-event-subscriptionat startup, like the other topics. - The listener saves each
AuditEventas anAuditEventLog. - A scheduled purge (daily) deletes rows with
occurred_atolder thanaudit.retention-days(envAUDIT_RETENTION_DAYS, default 730), in batches. POST /log/audit/search: body{actor, module, action, outcome, from, to, page, size}.actorandactionmatch exactly;fromandtoareyyyy-MM-ddand inclusive. It returns newest first, caps the size at 100, and answers{content, totalElements, number, size}.GET /log/audit/{id}.- Both need the admin's token at the gateway, like the other
/log/**routes.
- Creates
-
mobile-api read API:
AdminAuditLogController(@AdminModule("BO_AUDIT_LOG")):GET /api/admin/audit-log?actor&module&action&outcome&from&to&page&size;GET /api/admin/audit-log/{id}(404 when missing).- The reads themselves are not audited (GET without
@Audited).
-
Portal
/audit-log:- List: time, who, module (label from the module's i18n key), action, target, outcome with status, and IP.
- Filters: who, module select, action, outcome, and From/To
DatePicker. - Detail
/audit-log/[id]: the event fields, then a changes table (field, before, after), or a list of changed fields when only names were recorded. - Gating:
RequireModuleandROUTE_MODULES. - Proxy:
app/api/audit-log/[[...path]]/route.ts, GET only.
-
Module row:
(41100000, 'BO_AUDIT_LOG', 'Audit log', 'BO', 'M', 40000000, '/audit-log', 'ScrollText'), with no role grants.
Risks / Trade-offs
- Lost events: Pub/Sub publishing is best-effort, so a broker outage loses events. This is accepted, as in babyboo; the application log still carries the existing
... by ...lines. - Role names and settings stored as values: these are not personal data. Lead personal data is never stored; lead edits keep field names only.
- Path variables as targets: the last path variable is a UUID or id, except the unlock username, which is not recorded. The concrete path is never stored, so no query string, and therefore no search text, ends up in the log.
- Requests refused before the handler: malformed JSON or a binding error is answered before
AppAccessAspectruns, so such calls are not recorded. - Extra reads for before-values: a lead edit and a login-security settings save read the current values once before saving, only for the audit. The read is best-effort and cannot fail the save; it adds one internal call.
- One company: reads do not filter by
company_id. Add the filter when Co-Lite becomes multi-company. - Retention:
AUDIT_RETENTION_DAYSbelow 1 stops service-log at startup rather than deleting the whole trail. - Volume: one row per admin write. With one company and a handful of admins, 730 days is small.