gpt4 book ai didi

spring-security - 使用 Spring Security : Concurrent sessions 的 session 管理

转载 作者:行者123 更新时间:2023-12-04 07:03:21 25 4
gpt4 key购买 nike

我已经使用 Spring Security 开发了一个 Web 应用程序。对于登录,它从 LDAP 获得访问权限。现在我想使用 spring security 本身来管理 session ,我可以使用 authentication.getName() 来查看。我收到了 username我也可以得到 sessionID .

现在我想确定如果同一个用户尝试使用其他浏览器从同一个系统登录,他应该收到一条消息,说他已经在他的帐户中登录了。

任何人都可以给出一个想法如何实现这一目标????

<security:session-management 
invalid-session-url="/login.jsp?error=sessionExpired"
session-authentication-error-url="/login.jsp?error=alreadyLogin">
<security:concurrency-control
max-sessions="1"
expired-url="/login.jsp?error=sessionExpiredDuplicateLogin"
error-if-maximum-exceeded="false" />
</security:session-management>

当我使用它并尝试使用其他浏览器登录时,它给了我以下错误:
HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
enter code here

最佳答案

我可能遗漏了一些东西,但我已经尝试了下一个配置并且它按预期工作:

<!-- more configuration stuff -->

<sec:form-login login-page="/login.jsp"
default-target-url="/defaultTarget.jsp"
authentication-failure-url="/login.jsp?error=true"
login-processing-url="/login" always-use-default-target="true" />

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

当我尝试从另一个浏览器使用同一用户登录时,它会将我带到/login.jsp 并显示错误消息: Maximum sessions of 1 for this principal exceeded
编辑:你还需要把它放在你的 web.xml

<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

关于spring-security - 使用 Spring Security : Concurrent sessions 的 session 管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com