【问题标题】:Grails Spring Security manually trigger onAuthenticationSuccessEventGrails Spring Security 手动触发 onAuthenticationSuccessEvent
【发布时间】:2014-05-14 16:33:51
【问题描述】:

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

springSecurityService.reauthenticate(user.username)
authenticationSuccessHandler.onAuthenticationSuccess(request, response, springSecurityService.getAuthentication())

它可以很好地记录用户,但不会像我想象的那样触发 onAuthenticationSuccessEvent。我认为对 authenticationSuccessHandler.onAuthenticationSuccess 的调用会触发此操作,但事实并非如此。如何在手动登录时触发此事件?

谢谢!

【问题讨论】:

    标签: spring grails


    【解决方案1】:

    您可以随时通过DefaultAuthenticationEventPublisher 要求发布身份验证成功事件。例如,在服务中,您可以:

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

    这些都记录在 Spring Security API 和 Spring 框架中。

    【讨论】:

    • 完美!谢谢你。我已经通过 spring 安全源搜索和调试了整整 12 个小时,但找不到它。我一定是在看完全错误的东西:)
    • 不用担心。乐意效劳。我有点喜欢 Spring Security。 :)
    • 我肯定也会成为粉丝。越用越喜欢。
    猜你喜欢
    • 2015-01-08
    • 2014-10-28
    • 2022-07-19
    • 2011-07-08
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多