aratno commented on code in PR #3728:
URL: https://github.com/apache/cassandra/pull/3728#discussion_r1890674517
##########
src/java/org/apache/cassandra/audit/AuditLogManager.java:
##########
@@ -400,4 +418,103 @@ else if (e instanceof
PasswordGuardrail.PasswordGuardrailException)
return PasswordObfuscator.obfuscate(e.getMessage());
}
+
+ private static class JmxFormatter
+ {
+ private static String user(Subject subject)
+ {
+ return String.format("%s", subject == null ? null :
subject.getPrincipals().stream().map(Objects::toString).collect(Collectors.joining(",
")));
+ }
+
+ private static String method(Method method, Object[] args)
+ {
+ Function<Object, String> fmt = obj -> {
+ if (obj == null)
+ return "null";
+ return obj.toString();
+ };
+ String argsFmt = "";
+ if (args != null)
+ argsFmt =
Arrays.stream(args).map(fmt).collect(Collectors.joining(", "));
+ return String.format("%s#%s(%s)",
method.getDeclaringClass().getCanonicalName(), method.getName(), argsFmt);
+ }
+ }
+
+ @Override
+ public void onInvocation(Subject subject, Method method, Object[] args)
+ {
+ if (filter.isFiltered(AuditLogEntryCategory.JMX))
+ return;
+
+ AuditLogEntry entry = new AuditLogEntry.Builder(JMX)
+ .setOperation(String.format("JMX INVOCATION:
%s", JmxFormatter.method(method, args)))
+ .setUser(JmxFormatter.user(subject))
+ .build();
+ log(entry);
+ }
+
+ @Override
+ public void onRejection(Subject subject, Method method, Object[] args,
String reason)
+ {
+ if (filter.isFiltered(AuditLogEntryCategory.JMX))
+ return;
+
+ AuditLogEntry entry = new AuditLogEntry.Builder(JMX)
+ .setOperation(String.format("JMX REJECTION: %s
due to %s", JmxFormatter.method(method, args), reason))
Review Comment:
Good point - REJECTION was from a prior version of this patch that only
applied for AuthorizationProxy. Now it's much closer to a generic failure audit
log. I've updated the event naming to clarify that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]