Listening to successful login with Spring Security

2020-08-25 05:45发布


I want to perform several actions when a User successfully logs in to my app, this actions need some User data as parameters, so is there a way to listen to successful logins with Spring Security 3.0.x? Or any other way to accomplish this?



Use an AuthenticationSuccessHandler

<form-login authentication-success-handler-ref="authenticationSuccessHandler"/>

You can get the username from the Authentication (UsernamePasswordAuthenticationToken) that is passed to onAuthenticationSuccess() and then look up the other user info from there.