2

我已经实现了 HttpSessionListener 并且它工作正常,除了登录用户第二次同时登录的情况。Spring 正确终止了第一个会话,但从未触发 destroySession 事件,至少我的侦听器从未得到它。

我的弹簧安全如下:

<session-management 
    session-fixation-protection="migrateSession" >

<concurrency-control 
    max-sessions="1"
    expired-url="/login_sessionexpired" />
</session-management>

上面将用户从第一个会话中注销,如果他们同时登录第二次,则永远不会调用 HttpSessionListener.sessionDestroyed。

通常会调用 HttpSessionListener.sessionDestroyed 以进行手动注销和会话超时。

我在 web.xml 中有一个监听器的“委托代理”:com.test.security.DelegatingHttpSessionEventListenerProxy

此侦听器委托给 my-servlet.xml 中定义的 spring-bean:

<bean id="httpSessionEventListener"
    class="com.test.security.SimpleHttpSessionEventListenerImpl" />

委托侦听器编码为:

public class DelegatingHttpSessionEventListenerProxy implements
    HttpSessionListener {

/**
 * Delegates sessionCreated Event to the Spring-bean
 */
@Override
public void sessionCreated(HttpSessionEvent se) {
    ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(se.getSession().getServletContext());

    HttpSessionListener target = context.getBean(
            "httpSessionEventListener", HttpSessionListener.class);
    target.sessionCreated(se);
}

/**
 * Delegates sessionDestroyed Event to the Spring-bean
 */
@Override
public void sessionDestroyed(HttpSessionEvent se) {
    ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(se.getSession().getServletContext());

    HttpSessionListener target = context.getBean(
            "httpSessionEventListener", HttpSessionListener.class);
    target.sessionDestroyed(se);
}
}

我正在使用 spring-security-3.0.5,有人可以告诉我我错过了什么吗?谢谢你。

4

0 回答 0