Changing Grails Last Login Date Using Spring Security

In mine, Config.groovyI used:

grails.plugins.springsecurity.useSecurityEventListener = true

grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent = { e, appCtx ->
    User.withTransaction {
        def user = User.findById(appCtx.springSecurityService.principal.id)
        if(!user.isAttached())
            user.attach()
        user.lastLoginDate = new Date()
        user.save(flush: true, failOnError: true)
    }
}

This field is in my user domain, and I do not receive any errors when logging in, but the field is not updated.

I tried debugging everything from org.hibernate, but I could not find any updateor other relevant statements.

Is there anything else I need to add anywhere to get this to work?

For the record:

  • Grails 1.3.7
  • Spring Security Core 1.1.2
  • Hibernate 1.3.7
+5
source share
2 answers

Well, the answer was simple. I forgot the name of the package so that it could not be found User.

, , User org.test:

org.test.User.withTransaction {
      def user = org.test.User.get(appCtx.springSecurityService.principal.id)
      user.lastLoginDate = new Date()
      user.save(failOnError: true)
}
+5

spring ? , spring. , spring?

:: UPDATE::

, , , , ...

0

All Articles