標籤:設定 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登入人數限制並且同一個帳號可以踢掉前一個使用者設定檔