-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance audit logging: add event name and description, refine mutatio… #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e5c85bb
484bc31
b51596b
41d8a44
4fe28a7
4cc870d
6e824ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,8 +109,20 @@ public void afterCompletion(int status) { | |
| auditService.record(AuditEventEntity.builder() | ||
| .caseId(caseEntity.getId()) | ||
| .statusChange(statusChange) | ||
| .eventName("STATUS_CHANGED") | ||
| .description("Status changed to COMMUNICATION after document upload") | ||
| .actorId(actor.userId()) | ||
| .actorRole(actor.role() != null ? actor.role().name() : null) | ||
| .occurredAt(Instant.now()) | ||
| .build()); | ||
| } else { | ||
| auditService.record(AuditEventEntity.builder() | ||
| .caseId(caseEntity.getId()) | ||
| .eventName("DOCUMENT_UPLOADED") | ||
| .description("Document uploaded: " + entity.getFileName()) | ||
| .actorId(actor.userId()) | ||
| .actorRole(actor.role() != null ? actor.role().name() : null) | ||
| .occurredAt(Instant.now()) | ||
| .build()); | ||
| } | ||
|
Comment on lines
+118
to
127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this can leak sensitive data into the audit table and onto the audit UI. Consider either truncating/escaping the filename, or documenting that audit Additionally, no upper bound on 🤖 Prompt for AI Agents |
||
| return documentMapper.toDTO(saved); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,17 @@ public AuditInterceptor(AuditService auditService, SecurityActorAdapter security | |
|
|
||
| @Override | ||
| public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { | ||
| String method = request.getMethod(); | ||
| boolean isMutation = "POST".equalsIgnoreCase(method) || | ||
| "PUT".equalsIgnoreCase(method) || | ||
| "DELETE".equalsIgnoreCase(method) || | ||
| "PATCH".equalsIgnoreCase(method); | ||
|
|
||
| // Only record mutations or errors to reduce noise | ||
| if (!isMutation && ex == null) { | ||
| return; | ||
| } | ||
|
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-mutating requests that fail without throwing will silently skip audit.
Consider also auditing non-mutating requests when the response status indicates an error: Proposed fix- // Only record mutations or errors to reduce noise
- if (!isMutation && ex == null) {
- return;
- }
+ // Only record mutations or errors to reduce noise
+ int status = response != null ? response.getStatus() : 0;
+ boolean isError = ex != null || status >= 400;
+ if (!isMutation && !isError) {
+ return;
+ }🤖 Prompt for AI Agents |
||
|
|
||
| Actor actor = null; | ||
| try { | ||
| actor = securityActorAdapter.currentUser(); | ||
|
|
@@ -43,10 +54,11 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp | |
| } | ||
| event.setPrincipalName(request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : null); | ||
|
|
||
| event.setHttpMethod(request.getMethod()); | ||
| event.setRequestPath(request.getRequestURI()); | ||
| event.setQueryString(request.getQueryString()); | ||
| event.setHandler(handlerName(handler)); | ||
| event.setEventName("WEB_ACTION"); | ||
| event.setDescription(method + " " + request.getRequestURI()); | ||
|
|
||
| event.setResponseStatus(response != null ? response.getStatus() : null); | ||
| event.setErrorType(ex != null ? ex.getClass().getSimpleName() : null); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.