码迷,mamicode.com
首页 > 编程语言 > 详细

spring security登录人数限制并且同一个账号可以踢掉前一个用户配置文件

时间:2018-07-12 18:05:50      阅读:947      评论:0      收藏:0      [点我收藏+]

标签:设置   current   注入   maximums   exce   position   class   sas   property   

一、限制用户登录数和session自动托管

  1.maximumSessions:限制登录人数

  2.exceptionIfMaximumExceeded:

    • 为true同一账户只能登录一次,
    • 为false同一账户可以登录多次如果配置了org.springframework.security.web.session.ConcurrentSessionFilter则会踢出前一个登录的session

  3.sessionRegistry配置session管理

  4.concurrentSessionFilter如果不配置这个则踢不出上一个登录的session,会一个账户可以登录多次

<bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
  <property name="maximumSessions" value="1"/>
<property name="exceptionIfMaximumExceeded" value="false"></property> 
<constructor-arg>
  <ref bean="sessionRegistry"/>
</constructor-arg>
</bean>
<bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl"></bean> 
<bean id="concurrentSessionFilter"
  class="org.springframework.security.web.session.ConcurrentSessionFilter">
  <property name="sessionRegistry" ref="sessionRegistry"/>
</bean>

  

二、将配置好的bean进行注入

  将上述的bean设置好通过下述方式配置好即可

<s:http access-denied-page="/403.jsp" auto-config=‘true‘>

  <s:session-management invalid-session-url="/login.jsp" session-authentication-strategy-ref="sas"/>
  <s:custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrentSessionFilter" /> 
</s:http>

  

三、另附思路启发参考网页

http://www.mossle.com/docs/auth/html/ch214-smart-concurrent.html

 

spring security登录人数限制并且同一个账号可以踢掉前一个用户配置文件

标签:设置   current   注入   maximums   exce   position   class   sas   property   

原文地址:https://www.cnblogs.com/y-bobo/p/9300408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!