I have a Spring MVC app where user must be redirected to the login page when session is expired. I tried common solution suggested here. But it does not redirect automatically, it redirects when user clicks any link or takes some action.
Then I created this class
@Component
public class SessionEndedListener implements ApplicationListener<SessionDestroyedEvent> {
protected static Logger log = LogManager.getLogger(SessionEndedListener.class);
@Override
public void onApplicationEvent(SessionDestroyedEvent event)
{
log.info("Session expired or have been destroyed!");
}
}
And now, my onApplicationEvent is fired when session expires. However, I can't redirect from this method.
How to redirect automatically when session is expired? My Spring version is 4.2.5 and Spring Security version is 4.1.4.