我使用 Spring Security 开发了一个 Web 应用程序。对于登录,它从 LDAP 获取访问权限。现在我想使用 spring security 本身来管理会话,我可以使用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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)