转:零下一度的寒
spring-security 一个用户只能登陆一次
首先假设你的security能正常的运行了,一般的配置都没问题的情况下,实现一个用户只能登陆一次,大概只需要两步。
第一步 在你的web.xml中加入监听器
- <listener>
- <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher </listener-class>
- </listener>
复制代码 第二步 在security的配置文件中加入以下配置信息
- <http auto-config='true' >
- <intercept-url pattern="/**" access="ROLE_USER" />
- <remember-me key="myAppKey"/>
- <logout invalidate-session="true"/>
- <openid-login />
- <session-management>
- <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
- </session-management>
- </http>
复制代码 如果你想在那个用户第二次登陆时跳转到一个错误页面时,使用 session-authentication-error-url属性。
嘿 so easy吧 |