There are several use cases where we are require to capture the login event such as storing the login history, set user related data like name and email in session(so that no database hit to get this basic information), etc.

In my project I asked to maintain user login history so I need to capture login event for that.

Following is simple code to capture login event in grails application:

Make a bean in resources.groovy file

import org.mkb.MyLoginEventListener

beans = {
    myLoginEventListener(MyLoginEventListener)
}

and make a file MyLoginEventListener in src/groovy

package org.mkb

import org.springframework.context.ApplicationEvent
import org.springframework.context.ApplicationListener
import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent

class MyLoginEventListener implements ApplicationListener {
    @Override
    void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof InteractiveAuthenticationSuccessEvent) {
            //your code here..,.
        } 
    }
}