openmrs-core icon indicating copy to clipboard operation
openmrs-core copied to clipboard

OMRS-131: Detailed Audit Logging

Open wikumChamith opened this issue 10 months ago • 5 comments

Description of what I changed

This adds Hibernate Envers to the OpenMRS to enable audit logging.

Added hibernate.integration.envers.enabled=false property to disable audit logging by default. We should enable it from the module.

Issue I worked on

see https://openmrs.atlassian.net/browse/OMRS-131

Checklist: I completed these to help reviewers :)

  • [x] My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • [ ] I have added tests to cover my changes. (If you refactored existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • [x] I ran mvn clean package right before creating this pull request and added all formatting changes to my commit.

    No? -> execute above command

  • [x] All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • [x] My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

wikumChamith avatar Apr 20 '24 12:04 wikumChamith

@dkayiwa I was able to fix the old issue by changing the hibernate dialect from MySQLDialect to MySQL5Dialect.

wikumChamith avatar Apr 22 '24 11:04 wikumChamith

@wikumChamith i tried to locally run the changes in this pull request after adding this to my runtime properties file hibernate.integration.envers.enabled=true but not a single audit log table was created. Can you look into this too?

dkayiwa avatar May 09 '24 21:05 dkayiwa

@dkayiwa you need to add both of these properties to the runtime properties file.

hibernate.integration.envers.enabled=true
hibernate.hbm2ddl.auto=update

wikumChamith avatar May 11 '24 08:05 wikumChamith

Is there a way we can avoid this? hibernate.hbm2ddl.auto=update

dkayiwa avatar May 11 '24 19:05 dkayiwa

I don't think there are any other viable ways. This is the recommended approach in the Hibernate documentation: https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers

wikumChamith avatar May 12 '24 03:05 wikumChamith

@wikumChamith is this ready?

dkayiwa avatar Jun 03 '24 10:06 dkayiwa

@wikumChamith is this ready?

Still, the application does not generate audit tables for user_properties. I'll give it another try and let you know.

wikumChamith avatar Jun 03 '24 10:06 wikumChamith

I'll give it another try and let you know.

Anxiously looking forward to the update. 😊

dkayiwa avatar Jun 03 '24 10:06 dkayiwa

@wikumChamith can you start on a wiki page with steps of how to set up auditing that we shall use when this is merged?

dkayiwa avatar Jun 11 '24 19:06 dkayiwa

@dkayiwa I created a wiki page: https://openmrs.atlassian.net/wiki/spaces/docs/pages/113999876/Enabling+Hibernate+Envers+Audit+Logging+in+OpenMRS

I'm not entirely sure if I created it in the correct section :sweat_smile:. Could you please take a look?

wikumChamith avatar Jun 12 '24 11:06 wikumChamith

Thanks, let me take a look. Did you figure out the issue with user_properties? If not yet, can you just move on with the rest of the tables?

dkayiwa avatar Jun 12 '24 12:06 dkayiwa

Can you also add to the documentation what module developers would need to do if they want their tables to also be audited?

dkayiwa avatar Jun 12 '24 13:06 dkayiwa

Thanks, let me take a look. Did you figure out the issue with user_properties? If not yet, can you just move on with the rest of the tables?

All the core tables except the 'user_properties' are working fine. The only solution I found so far is to introduce a separate entity for UserProperties. I don't feel comfortable it with because we have to do a lot of code changes.

wikumChamith avatar Jun 13 '24 13:06 wikumChamith

Can you forget about user properties and we proceed?

dkayiwa avatar Jun 13 '24 13:06 dkayiwa

Secondly, when i looked at the log tables, i did not see which user made the change.

dkayiwa avatar Jun 13 '24 13:06 dkayiwa

I am totally happy to forget the user properties :joy:

Secondly, when i looked at the log tables, i did not see which user made the change.

Those data are in the OpenMRSRevisionEntity table.

wikumChamith avatar Jun 13 '24 13:06 wikumChamith

Seen them. Can you now proceed with the next steps?

dkayiwa avatar Jun 13 '24 13:06 dkayiwa

Seen them. Can you now proceed with the next steps?

Could you please clarify what the next steps are?

wikumChamith avatar Jun 13 '24 13:06 wikumChamith

A module for visualising those logs to the user.

dkayiwa avatar Jun 13 '24 13:06 dkayiwa

A module for visualising those logs to the user.

Shouldn't we merge this before proceeding with the module??

wikumChamith avatar Jun 13 '24 13:06 wikumChamith