Luke, thanks for the information. It was very helpful.
I'll explain how I've implemented this, in case someone else needs it:
First, I created a class which implements ApplicationListener. In this class I had to implement the onApplicationEvent(ApplicationEvent event) method.
Code:
if (event instanceof AuthenticationSuccessEvent) {
// Logon event
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) event.getSource();
WebAuthenticationDetails details = (WebAuthenticationDetails) token.getDetails();
String login = (String) token.getCredentials();
addToDataBase(login, event.getTimestamp(), details.getRemoteAddress(), details.getSessionId());
} else if (event instanceof HttpSessionDestroyedEvent) {
// Logout event
HttpSession session = (HttpSession) event.getSource();
updateLogoffTimestamp(session.getId(), event.getTimestamp());
}
This works fine. Now, I have to handle the case of session timeout. Searching in this forum, I found out that if I register a listener in web.xml, the session timeout event will be caught by my application listener and nothing else needed to be done.
Code:
<listener>
<listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
</listener>
Problem solved (I think...).