Jun 14 2008
Capturing log-in event in Acegi
Adding some custom code that is supposed to be launched while user logs in it isn’t available out of the box but it can be done easily. In order to do this you have to implement interface org.springframework.context.ApplicationListener.
public void onApplicationEvent(ApplicationEvent event) { if (event instanceof AuthenticationSuccessEvent) { AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent) event; String username = authEvent.getAuthentication().getName(); // Any custom logic } }
Such listener has to be registered. In order to do this – just create a bean in xml configuration file where other Acegi related beans are declared (usually security.xml or applicationContext-security.xml).
<bean class="my.package.SomeExampleListener"> <property name="someExampleManager" ref="someExampleManager"></property> </bean>
You can inject any required dependencies here.
That’s all!
Thank you for your post.
In my spring configuration file, I was using the option
so every time the user goes to a page, it sends a AuthenticationSuccessEvent.
To solve this issue, I capture the InteractiveAuthenticationSuccessEvent instead.