想要實現(xiàn)一個功能:同一個用戶在兩個不同的瀏覽器中登錄,后面的踢掉之前的登錄。
本來的思路是在httpSession監(jiān)聽器中進行判斷。但是在使用httpSession.invalidate();銷毀Session的時候,這一句話會拋出奇怪的異常,怎么都解決不了。
這個時候可以使用一個比較笨的但是有效的一個方法來替代:
httpSession.setMaxInactiveInterval(1);
在代碼中設(shè)置過期時間為1秒鐘
當然這個方法只是耍小聰明,后來發(fā)現(xiàn),我遇到的問題,實際上是JeeSite 框架集成了Shiro 登陸框架,而這個框架,已經(jīng)默認實現(xiàn)了之前描述的功能,在它自定義的登錄登出攔截器中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<!-- 定義Shiro安全管理配置 --> < bean id = "securityManager" class = "org.apache.shiro.web.mgt.DefaultWebSecurityManager" > < property name = "realm" ref = "systemAuthorizingRealm" /> < property name = "sessionManager" ref = "sessionManager" /> < property name = "cacheManager" ref = "shiroCacheManager" /> </ bean > <!-- 自定義會話管理配置 --> < bean id = "sessionManager" class = "com.thinkgem.jeesite.common.security.shiro.session.SessionManager" > < property name = "sessionDAO" ref = "sessionDAO" /> <!-- 會話超時時間,單位:毫秒 --> < property name = "globalSessionTimeout" value = "${session.sessionTimeout}" /> <!-- 定時清理失效會話, 清理用戶直接關(guān)閉瀏覽器造成的孤立會話 --> < property name = "sessionValidationInterval" value = "${session.sessionTimeoutClean}" /> < property name = "sessionValidationSchedulerEnabled" value = "true" /> < property name = "sessionIdCookie" ref = "sessionIdCookie" /> < property name = "sessionIdCookieEnabled" value = "true" /> </ bean > |
只需要修改屬性文件jeesite.properties 中的屬性即可
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://www.cnblogs.com/acm-bingzi/p/sessionInvalidate.html