Detects a custom audit trail

I am using Hibernate Envers in Tomcat environment. It is working fine. However, I need to be able to add the name of the user who changed the data that needs to be verified. This can be done by implementing your own version of RevisionEntity. Then you also need to run a custom RevisionListener that will fill in the additional information you want to verify. I need to check the username that changed the data to be audited. The documentation is an example of how to do this with Seam. In RevisionListener they call:

 Identity identity = (Identity) Component.getInstance("org.jboss.seam.security.identity"); 

To get the username. In my project, we divided the project into separate modules for the database and the Internet. I need to implement my custum revision listener in my database module in order to be able to get the name of the user currently registered. I cannot move the RevisionListener into a web package and imagine the dependency on the web module on the database module. How do I get the current username so that I can manage multiple users at the same time in my custom RevisionListener editor?

The best solution would be the one that worked in most containers.

+4
source share
2 answers

I understand that you want to limit communication between modules. I have done this in the past using Spring and JSF. I had a data access code in their own projects, and my web projects depended on data access bars.

I wrote a listener in another project that knew about the Hibernate classes and the JSF API. I was able to use the JSF API to search for a registered user.

Thus, the web application depends on the data and the project of the listener. A data access project does not need to know where it is used, and even if an audit occurs. And the listener is configured in a web project.

+1
source

It sounds like a context injection and dependency injection (CDI). You can define an interface, such as ClientInfo, that has the abstract methods getUsername and getIPAddress. Then, in your view layer, create a concrete implementation of this interface, say, JSFClientInfo, which uses FacesContext to capture the username and IP address. A business layer component can simply use @Inject ClientInfo.

Unfortunately, it seems to me that you will need to use a service locator, although due to the fact that CDI org.hibernate.envers.RevisionListener is not supported by CDI.

0
source

All Articles