0

how audit-logging can work in domain class like userRole from springSecurity?

class SecUserSecRole implements Serializable {
      static auditable = true

      User user
      Role role

      ...

      def onSave = { map ->
      println "onSave userRole detected"
      }
}

thanks anyway..

rsijaya
  • 159
  • 2
  • 14

1 Answers1

1

I am not fully understanding why this is not working, but the reason seems to be auditPlugin cannot get the persisted properties when the id for class is composite. Therefore, it assumes nothing has changed and it wont call onSave.

The generated SecUserSecRole class introduces a composite key for ID based on 'role', 'user' and auditPlugin is trying to find the persisted property names from the hibernate PostInsertEvent. At this its not clear know why but the properties will be empty when domain is using composite key.

As a workaround try to change your domain mapping to

static mapping = {
   //id composite: ['role', 'user']
   role unique: 'user'
   version false
}

NOTE: This is not a solution and might have other side effects as far as springSecurity plugin.

Update: My concern was removing composite key might impact springSecurity many-to-many relationship, but according to Burt's post, seems it is safe to remove composite key and just create it unique as I mentioned here.

Community
  • 1
  • 1
Alidad
  • 5,463
  • 1
  • 24
  • 47