I have some code that is manually authenticating a user, but I want this to also trigger the logic contained in the onAuthenticationSuccessEvent. The code that I have right now looks like this:

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

It logs the user in fine, but does not trigger the onAuthenticationSuccessEvent like I thought it would. I figured the call to authenticationSuccessHandler.onAuthenticationSuccess would trigger this, but it doesn't. How can I get this event to trigger while logging in manually?

Thanks!

有帮助吗?

解决方案

You can always ask that an authentication successful event through the DefaultAuthenticationEventPublisher be published. For example in a service you could:

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

It's all documented in the Spring Security API and Spring framework.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top