【问题标题】:Spring session destroy event differentiate between session timeout and logoutSpring会话销毁事件区分会话超时和注销
【发布时间】:2013-10-31 15:18:06
【问题描述】:

我有一个 Spring 应用程序,其中我有一个扩展 HttpSessionEventPublisher 的类。

我一直在跟踪会话销毁事件。

但是现在我想区分会话是由于会话超时还是由于用户显式注销而被破坏的。

谢谢。

【问题讨论】:

    标签: java spring session spring-mvc session-timeout


    【解决方案1】:

    查看HttpSessionEventPublisher API,看起来您可以使用HttpSessionDestroyedEvent,它作为sessionDestroyed()方法中的参数传递。

    您可以执行以下操作类似

    javax.servlet.http.HttpSession session = event.getSession();
    long lastAction = session.getLastAccessedTime();
    long now = System.currentTimeMillis();
    int timeout= getMaxInactiveInterval();
    if ((now-lastAction) > timeout)
       //the session has timed out
    
    SecurityContext context = getSecurityContext();
    Authentication authentication = context.getAuthentication();
    if (!authentication.isAuthenticated())
       //the user has logged out
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      相关资源
      最近更新 更多