audit4j / audit4j-core

An open source auditing framework.
http://audit4j.org
Apache License 2.0
125 stars 77 forks source link

Need something better than toString for converting args #22

Closed massfords closed 8 years ago

massfords commented 8 years ago

Very nice library!

The conversion of the method args to a List is based on the arg's toString() implementation. It would be nice to support a pluggable conversion from object to a String or even support producing multiple Field's from a single argument.

Consider the following case:

public MyDTO create(MyDTO arg) { ... }

In this case, I'd like to record a couple of different fields from the MyDTO arg as opposed to relying solely on its toString() implementation.

I'm thinking I can add the behavior I want by writing my own version of AnnotationTransformer and then using it in an AuditOutputStream but it would be nice if this had a declarative / annotation driven solution. For spring users in particular, it would be great to have the option of an annotation that produced a List using different names and SpEL (spring expression language). For example, I could annotate the above method with an array of annotations each one having a name and SpEL that would extract the field I want to include in the AuditEvent.

janithb commented 8 years ago

Hi @massfords ,

We already Identified this issue and currently in progress of developing the solution. We thought of using pluggable serializer to extract object to relevant audit record based on annotations in the object fields (ex: MyDTO). I have developed below couple of serializes similar to old toString implementation. Please refer below implementations.

https://github.com/audit4j/audit4j-core/blob/master/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java

https://github.com/audit4j/audit4j-core/blob/master/src/main/java/org/audit4j/core/ObjectToStringSerializer.java

Using this method, users are able to plug their own serializer implementation based on the requirement (Ex: JSONable, XML). then you don't need to implement a custom a annotation transformer

What do you think.

massfords commented 8 years ago

A pluggable serializer seems like the right approach. I took a quick look at the source. I don't see a way to configure the serializer yet but I'm guessing this is still a work in progress.

janithb commented 8 years ago

This issue is resolved.

Fixes are available in Audit4j 2.4.1-RC1 release

@massfords Please test and verify.

janithb commented 8 years ago

This issue is fixed in 2.4.1