其他分享
首页 > 其他分享> > 如何使用Spring Security通知用户另一个会话?

如何使用Spring Security通知用户另一个会话?

作者:互联网

我有一个设计/系统要求,要通知用户User-A在User-A登录之前有另一个活动会话(由User-B).您如何使用Spring Security做到这一点?

场景是这样的:

> John Doe使用用户名johndoe登录到系统
> Jane使用johndoe登录到系统
>系统应向两个用户显示一条通知(包括另一位用户的IP地址),告知他们使用其用户名创建了另一个会话.

例:

Jane在步骤2中登录后,John Doe在发出新请求(例如单击链接)后将收到邮件.通知:

You have been automatically logged-out of the system.
Your login credential was used with IP Address (x.x.x.x).
If you believe your account was compromised, please report...

同时,在Jane登录后,还将通知她在登录之前还有另一个活动会话.

Your login credential was used with IP Address (x.x.x.x).
If you believe your account was compromised, please report...

我尝试研究自定义会话管理过滤器,自定义并发会话过滤器和自定义并发控制策略,但是我无法解决这个问题.
我似乎无法识别我应该自定义的w / c项目.

我还阅读了Spring Security文档中的Session Management章节,但仍然对如何实现上述要求有所了解.

解决方法:

如果我收到您的问题,则一次只需要一个用户即可使用xyz凭据登录;如果已经有一个用户(B)登录,而另一个用户(A)尝试登录,则您不希望其他用户登录. A,用于登录并提示有人使用相同的凭据登录.

您可以通过max-sessions =“ 1”实现

<security:http auto-config="true" use-expressions="true" access-denied-page="/accessDenied.jsp">

    <security:form-login login-page="/index.jsp"
        default-target-url="/jsp/home.jsp"
        authentication-failure-handler-ref="authenticationFailureHandler"/>


    <security:session-management>
        <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
    </security:session-management>

</security:http> 

我在理解您的实际需求时感到困惑,如果您需要同时保持两个会话都处于活动状态,则增加max-sessions =“ max_session_you_need”并仅注册会话创建侦听器,您就可以在会话请求中检查有关活动会话的信息,如果它与活动会话之一匹配,那么某些用户已经登录并可以执行您想做的任何事情…

标签:spring-security,session-management,spring
来源: https://codeday.me/bug/20191122/2063694.html