I\'m trying to invoke a protected method from a class that implements the ApplicationListener
interface on successful login (S
As pointed already by @Arun P Johny the root cause of the problem is that at the moment when AuthenticationSuccessEvent
is processed SecurityContextHolder
is not populated by Authentication object. So any declarative authorization checks (that must get user rights from SecurityContextHolder
) will not work. I give you another idea how to solve this problem. There are two ways how you can run your custom code immidiately after successful authentication:
AuthenticationSuccessEvent
AuthenticationSuccessHandler
implementation.AuthenticationSuccessHandler
has one important advantage over first way: SecurityContextHolder
will be already populated. So just move your stateService.rowCount()
call into loginsuccesshandler.LoginSuccessHandler#onAuthenticationSuccess(...)
method and the problem will go away.