Refactoring of audit events #2687
Conversation
Sorry, long PR is long... |
90bd9cc
to
f978611
- Replace `object` and `action` with just `action` - Create constants for all actions - Rename `subject` to `actor` - Add `excludedFields` field - Capture request and response entities by default This also adds some missing `@AuditLog` annotations to resources.
Also add `NoAuditEvent` annotation to be able to exclude some resources from the test.
If a POST, PUT or DELETE resource does not have an audit annotation, a warning will be written.
This makes it possible to differentiate between users and the system.
Create a more use friendly WARN message and a DEBUG that is useful for developers.
On startup and in tests.
Avoids a system notification on every server startup.
- `.system()` now takes a NodeId object - Change URN usage
Without this guice will throw an error during startup because there is no implementation binding for AuditEventFormatter.
/** | ||
* Checks all POST, PUT and DELETE resource methods for {@link AuditEvent} annotations and reports missing ones. | ||
* | ||
* It does not report methods which have a {@link NoAuditEvent} annotation. |
kroepke
Aug 18, 2016
Member
I would report @NoAuditEvent
annotations that use an empty string here, but that's nitpicking.
I would report @NoAuditEvent
annotations that use an empty string here, but that's nitpicking.
|
||
void success(String subject, String action, String object, Map<String, Object> context); | ||
void success(AuditActor actor, AuditEventType type, Map<String, Object> context); |
kroepke
Aug 18, 2016
Member
I'd add a couple of convenience methods here, to make the call sites a bit more concise:
With
default void success(String actor, String type, Map<String, Object> context) {
success(AuditActor.user(actor), AuditEventType.create(type), context);
}
it would be much easier to read on the call sites.
There are a couple of more options, too, such as allowing to append a varargs of Object pairs to implicitly create the map (or just a single String, Object pair)
I'd add a couple of convenience methods here, to make the call sites a bit more concise:
With
default void success(String actor, String type, Map<String, Object> context) {
success(AuditActor.user(actor), AuditEventType.create(type), context);
}
it would be much easier to read on the call sites.
There are a couple of more options, too, such as allowing to append a varargs of Object pairs to implicitly create the map (or just a single String, Object pair)
bernd
Aug 18, 2016
•
Author
Member
I can add a default method for success(AuditActor, String, Map<String, Object>)
. I would not create one with a String
argument for AuditActor
because there are two different methods (AuditActor.system(NodeId)
and AuditActor.user(String)
that do different things. So this can easily break.
Creating AuditEventType
from a string is fine because AuditEventType.create()
will throw an error if the string is not in the correct format.
default void success(AuditActor actor, String type, Map<String, Object> context) {
success(actor, AuditEventType.create(type), context);
}
I can add a default method for success(AuditActor, String, Map<String, Object>)
. I would not create one with a String
argument for AuditActor
because there are two different methods (AuditActor.system(NodeId)
and AuditActor.user(String)
that do different things. So this can easily break.
Creating AuditEventType
from a string is fine because AuditEventType.create()
will throw an error if the string is not in the correct format.
default void success(AuditActor actor, String type, Map<String, Object> context) {
success(actor, AuditEventType.create(type), context);
}
Use this in AuditEventModelProcessor and PrintModelProcessor instead of duplicating the code.
Switch internal use to those new methods.
Addressed review comments. |
Merging this on behalf of @kroepke who gave his "LGTM |
Description
object
andaction
intoaction
PluginAuditActions
interface to make audit actions pluggableAuditLog
annotation to the more genericAuditEvent
captureRequestEntity
andcaptureResponseEntity
by default inAuditEvent
excludedFields
inAuditEvent
to make it possible to skip fields like passwords in the audit trailPOST
,PUT
orDELETE
also have anAuditEvent
annotation or aNoAuditEvent
annotation if they should not be included in the audit trailPOST
,PUT
andDELETE
have aAuditEvent
orNoAuditEvent
annotationAuditEvent
annotations to REST resourcesActions
classAuditLogger
interface to the more genericAuditEventSender
auditlog
package toaudit
Motivation and Context
@AuditEvent
annotation