fix(audit): exclude authenticated principal from snapshots
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user