如何使用spring检测tomcat会话过期 [英] how to detect tomcat session expiration using spring

查看:30
本文介绍了如何使用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.

这篇关于如何使用spring检测tomcat会话过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆