参考http://www.family168.com/oa/springsecurity/html/ch102-concurrent-session.html
security会话管理有两种控制策略:
首先在web.xml文件配置:
在web.xml中添加一个监听器,这个监听器会在session创建和销毁的时候通知Spring Security
<listener>
<listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
</listener>
第一种:后登陆的将先登录的踢出系统
<http auto-config='true'>
<intercept-url pattern="/admin.jsp" access="ROLE_ADMIN" />
<intercept-url pattern="/**" access="ROLE_USER" />
<concurrent-session-control exception-if-maximum-exceeded="false"/>
</http>
先登陆的用户刷新页面提示:
This session has been expired (possibly due to multiple concurrent logins being attempted as the same user).
第二种:后面的用户禁止登陆
<http auto-config='true'>
<intercept-url pattern="/admin.jsp" access="ROLE_ADMIN" />
<intercept-url pattern="/**" access="ROLE_USER" />
<concurrent-session-control exception-if-maximum-exceeded="true"/>
</http>
这个参数用来控制是否在会话数目超过最大限制时抛出异常,默认值是false,也就是不抛出异常,而是把之前的session都销毁掉,所以之前登陆的用户就会被踢出系统了。
后登陆的用户提示:Maximum sessions of 1 for this principal exceeded