Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions graylog2-server/src/main/java/org/graylog2/audit/Auditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,47 @@ public <T> T audited(final String username,
final String eventType,
final Object actionInput,
final Supplier<T> auditableAction) {
return audited(username, eventType, actionInput, auditableAction, SUCCESS_ON_NON_NULL);
return audited(username, eventType, actionInput, auditableAction, SUCCESS_ON_NON_NULL, null);
}

public <T> T audited(final String username,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this guy has no call sites. Should we drop it?

final String eventType,
final Object actionInput,
final Supplier<T> auditableAction,
final Map<String, Object> extra) {
return audited(username, eventType, actionInput, auditableAction, SUCCESS_ON_NON_NULL, extra);
}

public <T> T audited(final String username,
final String eventType,
final Object actionInput,
final Supplier<T> auditableAction,
final Predicate<? super T> isSuccess) {
return audited(username, eventType, actionInput, auditableAction, isSuccess, null);
}

public <T> T audited(final String username,
final String eventType,
final Object actionInput,
final Supplier<T> auditableAction,
final Predicate<? super T> isSuccess,
final Map<String, Object> extra) {
final T actionResult;
try {
actionResult = auditableAction.get();
} catch (RuntimeException e) {
recordFailure(username,
eventType,
actionInput,
null,
Map.of(ERROR, String.valueOf(e.getMessage())));
final Map<String, Object> extraWithError = new LinkedHashMap<>();
if (extra != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about passing Map.of() in the overloads? then

final Map<String, Object> extraWithError = new LinkedHashMap<>(extra);
extraWithError.put(ERROR, String.valueOf(e.getMessage()));

extraWithError.putAll(extra);
}
extraWithError.put(ERROR, String.valueOf(e.getMessage()));
recordFailure(username, eventType, actionInput, null, extraWithError);
throw e;
}
if (isSuccess.test(actionResult)) {
recordSuccess(username, eventType, actionInput, actionResult, null);
recordSuccess(username, eventType, actionInput, actionResult, extra);
} else {
recordFailure(username, eventType, actionInput, actionResult, null);
recordFailure(username, eventType, actionInput, actionResult, extra);
}
return actionResult;
}
Expand Down
Loading