Grails Spring Security manually starts onAuthenticationSuccessEvent

I have a code that manually authenticates the user, but I want this to also call the logic contained in onAuthenticationSuccessEvent. The code that I have now looks like this:

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

It writes the user in order, but does not call onAuthenticationSuccessEvent, as I thought. I understood that the authentication call SuHuHandler.onAuthenticationSuccess would cause this, but it is not. How can I fire this event when logging in manually?

Thank!

+4
source share
1 answer

DefaultAuthenticationEventPublisher. , :

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

Spring API Spring.

+5

Source: https://habr.com/ru/post/1540548/


All Articles