fix(audit): exclude authenticated principal from snapshots

This commit is contained in:
2026-08-08 13:15:01 +08:00
parent dca8c05d33
commit b6b5e2dc55
2 changed files with 14 additions and 6 deletions
@@ -41,7 +41,7 @@ public class BusinessAuditAspect {
@Around("@annotation(audit)")
public Object around(ProceedingJoinPoint pjp, BusinessAudit audit) throws Throwable {
long start = System.nanoTime();
String before = audit.captureBefore() ? sanitizer.sanitize(pjp.getArgs()) : null;
String before = audit.captureBefore() ? sanitizer.sanitize(businessArguments(pjp.getArgs())) : null;
Object result = null; Throwable failure = null;
try { result = pjp.proceed(); return result; }
catch (Throwable ex) { failure = ex; throw ex; }
@@ -79,6 +79,12 @@ public class BusinessAuditAspect {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return auth != null && auth.getPrincipal() instanceof AuthenticatedUser u ? u : null;
}
private Object[] businessArguments(Object[] arguments) {
if (arguments == null || arguments.length == 0) return new Object[0];
return java.util.Arrays.stream(arguments)
.filter(argument -> !(argument instanceof AuthenticatedUser))
.toArray();
}
private String evaluateResourceId(ProceedingJoinPoint p, String expression) {
if (expression == null || expression.isBlank()) return null;
Object value = evaluate(p, expression);