Rub*_*uby 5 spring-security session-management
我使用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>
Run Code Online (Sandbox Code Playgroud)
当我使用它并尝试使用其他浏览器登录时,它会给我以下错误:
HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
enter code here
Run Code Online (Sandbox Code Playgroud)
我可能会遗漏一些东西,但我已经尝试了下一个配置,它按预期工作:
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用其他浏览器中的同一用户登录时,它会将我带到/login.jsp并显示错误消息: Maximum sessions of 1 for this principal exceeded
编辑:你还需要把它放在你的 web.xml
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6493 次 |
| 最近记录: |