如何使用spring检测tomcat会话过期

问题描述:

我正在使用spring运行wicket并使用spring security,当tomcat会话时,在web.xml中声明的会话过期

i am running wicket with spring and use spring security , when tomcat session , the one which declared in the web.xml expired

<session-config>
    <session-timeout>1</session-timeout>
</session-config>

我想使用过滤器捕获此事件(不覆盖现有的 httpSession 或 Session )我怎样才能使用 spring 实现这一目标?

I want to catch this event using a filter(not overiding existing httpSession or Session ) how can I achive that using spring ?

10 倍

您可以使用侦听器类来实现此目的.定义一个监听器组件如下:

You can use a listener class to achieve this. Define a listener component as below:

@Component
public class AppLogoutListener implements
        ApplicationListener<SessionDestroyedEvent> {


    @Override
    public void onApplicationEvent(SessionDestroyedEvent event) {
        // from event you can obtain SecurityContexts to work with


    }

}

您需要在 web.xml 中定义会话事件发布者:

You need to define a session event publisher in your web.xml:

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

这里 HttpSessionEventPublisher 会在会话创建和过期时发布会话生命周期事件.

Here the HttpSessionEventPublisher publishes the session life cycle events whenever sessions are created and expired.