Jun 14 2008

Capturing log-in event in Acegi

Published by at 4:05 pm under IT,Java

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>

You can inject any required dependencies here.

That’s all!

One response so far

One Response to “Capturing log-in event in Acegi”

  1. Blueon 18 Jun 2010 at 9:10 pm

    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.

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.