欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shiro實現(xiàn)單點登錄(一個用戶同一時刻只能在一個地方登錄)

 更新時間:2016年08月26日 11:16:36   投稿:mrr  
這篇文章主要介紹了shiro實現(xiàn)單點登錄(一個用戶同一時刻只能在一個地方登錄)的相關(guān)資料,非常不錯,具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧

我這里 shiro 并沒有集成 springMVC,直接使用 ini 配置文件。

shiro.ini

[main]
# Objects and their properties are defined here,
# Such as the securityManager, Realms and anything
# else needed to build the SecurityManager
authc.loginUrl = /login.jsp
authc.successUrl = /web/index.jsp
#cache manager
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager=org.apache.shiro.web.mgt.DefaultWebSecurityManager
securityManager.cacheManager = $builtInCacheManager
securityManager.sessionManager=$sessionManager
#session 必須配置session,強制退出時,通過將session移除實現(xiàn)
sessionManager=org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionDAO=$sessionDAO
sessionDAO=org.apache.shiro.session.mgt.eis.MemorySessionDAO
# Create ldap realm
ldapRealm = org.apache.shiro.realm.ldap.JndiLdapRealm
#......
# Configure JDBC realm datasource
dataSource = org.postgresql.ds.PGPoolingDataSource
#.......
# Create JDBC realm.
jdbcRealm.permissionsLookupEnabled = true
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.userRolesQuery = ......
jdbcRealm.permissionsQuery = ......
jdbcRealm.dataSource = $dataSource
#self realm
localAuthorizingRealm = com.redbudtek.shiro.LocalAuthorizingRealm
securityManager.realms = $ldapRealm, $localAuthorizingRealm

在 LocalAuthorizingRealm 中,用戶登錄進行認(rèn)證之前,先將該用戶的其他session移除:

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
String userName = (String)authenticationToken.getPrincipal();
//處理session
DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager();
DefaultWebSessionManager sessionManager = (DefaultWebSessionManager)securityManager.getSessionManager();
Collection<Session> sessions = sessionManager.getSessionDAO().getActiveSessions();//獲取當(dāng)前已登錄的用戶session列表
for(Session session:sessions){
//清除該用戶以前登錄時保存的session
if(userName.equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)))) {
sessionManager.getSessionDAO().delete(session);
}
}
String pwd = null;
return new SimpleAuthenticationInfo(userName,pwd,getName());
}

當(dāng)session刪除之后,必須有客戶端與服務(wù)器端的交互,shiro才能進行認(rèn)證判斷。在與服務(wù)器交互時,subject信息截圖如下:

此時的登錄的用戶認(rèn)證已經(jīng)失效,可以對客戶端做出響應(yīng)。

以上所述是小編給大家介紹的shiro實現(xiàn)單點登錄(一個用戶同一時刻只能在一個地方登錄),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論