Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Envers custom revision listener

I am using Hibernate Envers in a Tomcat environment. It works fine. I do however need to be able to add the username of the user that changed the data that is to be audited. This can be done by implementing your own version of RevisionEntity. Then you also have to implement a custom RevisionListener that will populate the extra information you want to audit. I need to audit the username that has changed the data that are to be audited. In the documentation it is a example on how to do this with Seam. In the RevisionListener they call:

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

To obtain the username. In my project we have split the project into seperate modules for database and web. I need to implement my custum revision listener in my database module to be able to get the currently logged in username. I can not move the RevisionListener to the web package and introduce a dependency on the web module from the database module. How can I obtain the current username in a way that handles multiple users logged in at the same time in my custom RevisionListener`?

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

like image 813
Brumlebass Avatar asked Nov 14 '22 17:11

Brumlebass


1 Answers

I can understand you wanting to limit coupling between modules. I have done this in the past using Spring and JSF. I had Data Access code in their own projects and my web projects were dependant on the data access jars.

I wrote the listener in another project that knew about the Hibernate classes and JSF API. I was able to use the JSF API to find the logged in user.

That way the web app is dependent on the data and the listener project. The data access project doesn't need to know where it is used and even if there is auditing happening. And the listener is configured in the web project.

like image 105
James DW Avatar answered Dec 23 '22 15:12

James DW