grails-audit-logging-plugin icon indicating copy to clipboard operation
grails-audit-logging-plugin copied to clipboard

Audit logging ignores multitenant mode

Open martinvlk opened this issue 7 years ago • 5 comments

Hi, we are implementing an application which uses the GORM multitenancy in DATABASE mode, e.g.

grails:
  gorm:
    multiTenancy:
      mode: DATABASE

However, the audit-logging plugin ignores the resolved tenant data source and always writes to the DEFAULT data source.

Could you add support for multitenancy?

martinvlk avatar Jun 15 '17 12:06 martinvlk

feel free to send in a PR.

robertoschwald avatar Jun 15 '17 13:06 robertoschwald

Ok, looking at it... it seems that the AuditLogListener is only reacting to events from the DEFAULT data source. Whatever happens in other data sources related to different tenants is completely ignored.

Could you point me in the right direction for fixing this?

martinvlk avatar Jun 21 '17 13:06 martinvlk

Aha, this is related to #57 - it says "not possible"......

martinvlk avatar Jun 21 '17 13:06 martinvlk

In the AuditLoggingGrailsPlugin descriptor, we register an AuditLogListener per DataSource. So you need to enable multi tenancy in the audit-test sub-project's AuditTrail domain class, as you write tests for this feature, right? ;-)

In the AuditLogListener, you need to figure out if the Domain object is tenant enabled and store the AuditTrail using this tennant id. Maybe 11.2.3 in Gorm 6.1 docs can be a hint.

Please note that the plugin must stay ORM agnostic. So you need to find an ORM independent way. Thus, don't deal with Hibernate / Mongo / etc. classes directly.

Haven't played around with tenancy yet, so the info above is just a rough guess.

robertoschwald avatar Jun 21 '17 13:06 robertoschwald

Do we have support for multitenancy now?

xaw-roz avatar Jul 23 '19 12:07 xaw-roz