i'm using spring security plugin , i want to save the user's login date in the DB so i wrote the below in the config file :
grails.plugin.springsecurity.useSecurityEventListener = true
grails.plugin.springsecurity.onAuthenticationSuccessEvent= { e, appCtx ->
com.app.utils.UserActivity.withTransaction {
def user = com.app.utils.UserActivity.findByUser(com.app.security.Users.get(appCtx.springSecurityService.principal.id))
if (!user)
{
new com.app.utils.UserActivity(user:user,userLoggedIn:new Date(),userLoggedOut: null).save(failOnError:true)
}
else
{
user.userLoggedIn= new Date()
user.userLoggedOut=null
user.save(failOnError:true)
}
}
}
the issue is that appCtx.springSecurityService.principal.id
is always returning null
, and are there any events for the logout
action.
正确的获取主密码的方法是通过如下所示的身份验证事件:
e.getAuthentication().getPrincipal()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.