Acegi publishs a number of events. You can tap into them as you would any Spring event.
Simply create a class that implements ApplicationListener, as follows;
Code:
package app.events;
import net.sf.acegisecurity.providers.dao.event.AuthenticationSuccessEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ApplicationEvent;
public class SuccessfulLoginEvent implements ApplicationListener {
private MonitorDao monitorDao;
public MonitorDao getMonitorDao() {
return monitorDao;
}
public void setMonitorDao(MonitorDao monitorDao) {
this.monitorDao = monitorDao;
}
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
AuthenticationSuccessEvent successEvent = (AuthenticationSuccessEvent) event;
monitorDao.write(successEvent.getUser());
}
}
}
In the above example I use a DAO to record the event. You would implement your DAO as a SQL.
After that, the only other thing you need to do is register the listener in your application context.
Code:
<bean id="successflLoginEvent" class="app.events.SuccessfulLoginEvent">
<property name="monitorDao">
<ref bean="monitorDao"/>
</property>
</bean>
Spring looks for anything that implements ApplicationListener when it loads up the context. It will then fire it whenever is "hears" an event