Grails Spring Security在AuthenticationSuccessEvent上手动触发

Grails Spring Security在AuthenticationSuccessEvent上手动触发,spring,grails,Spring,Grails,我有一些手动验证用户的代码,但我希望这也能触发onAuthenticationSuccessEvent中包含的逻辑。我现在拥有的代码如下所示: springSecurityService.reauthenticate(user.username) authenticationSuccessHandler.onAuthenticationSuccess(request, response, springSecurityService.getAuthentication()) 它可以很好地登录用户

我有一些手动验证用户的代码,但我希望这也能触发onAuthenticationSuccessEvent中包含的逻辑。我现在拥有的代码如下所示:

springSecurityService.reauthenticate(user.username)
authenticationSuccessHandler.onAuthenticationSuccess(request, response, springSecurityService.getAuthentication())
它可以很好地登录用户,但不会像我想象的那样触发onAuthenticationSuccessEvent。我认为对authenticationSuccessHandler.onAuthenticationSuccess的调用会触发此事件,但它不会。如何在手动登录时触发此事件


谢谢

您始终可以通过请求发布身份验证成功事件。例如,在服务中,您可以:

class MyService {
  def authenticationEventPublisher
  def springSecurityService
  ...
  void someMethod() {
    ...
    authenticationEventPublisher.publishAuthenticationSuccess(
      springSecurityService.getAuthentication()
    )
    ...
  }
  ...
}

所有这些都记录在Spring安全API和Spring框架中。

完美!非常感谢。我已经连续12个小时通过spring安全源进行谷歌搜索和调试,但都找不到它。我一定是看错了东西:)别担心。很乐意帮忙。我有点喜欢春季保安。:)我肯定也会成为一名球迷。我用得越多,就越喜欢它。