【问题标题】:Spring mvc 4 Concurrent Session ControlSpring mvc 4 并发会话控制
【发布时间】:2016-02-11 03:21:03
【问题描述】:

我已阅读此站点和有关设置并发会话控制的文档,我不知道 Spring 处理得这么好。

示例: Question 1 Question 2 等等……

但是我找不到如何在 Spring 4 控制器(spring 4 - 注释)中以编程方式(不是应用程序上下文)执行此操作。

<http>
  ...
   <session-management>
     <concurrency-control max-sessions="1" />
   </session-management>
</http>

我已经阅读了有关 ConcurrentSessionControlAuthenticationStrategy、ConcurrentSessionControlStrategy、CompositeSessionAuthenticationStrategy 的信息,但无法实现。我要做的是确保用户只能登录一次,如果其他人使用相同的用户名登录,则会给他们一个错误页面。

感谢任何帮助或建议...

【问题讨论】:

    标签: java spring session authentication


    【解决方案1】:

    这就是我的应用程序中的内容。如果存在有效会话,这会给任何登录尝试带来错误

    ...security:concurrency-control max-sessions="1" error-if-maximum- exceeded="true"..

    【讨论】:

    • 我在 XML 中没有提到 -> 仅以编程方式。
    【解决方案2】:

    希望您可以通过实现javax.servlet.http.HttpSessionBindingListener 接口并通过java 配置将其注册为ServletContext listener 来做到这一点。

    参考:How to invalidate another session when an user is logged in twice?

    【讨论】:

    • 感谢您的回答,但我试图阻止新用户而不是踢出原始登录用户。
    • 当然这取决于您,如果您发现同一用户再次尝试登录,您可以使新创建的会话或现有会话无效。
    猜你喜欢
    • 1970-01-01
    • 2014-04-15
    • 2021-04-18
    • 1970-01-01
    • 2011-04-25
    • 2019-06-24
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多