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

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

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

我這里 shiro 并沒(méi)有集成 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,強(qiáng)制退出時(shí),通過(guò)將session移除實(shí)現(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 中,用戶登錄進(jìn)行認(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){
//清除該用戶以前登錄時(shí)保存的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才能進(jìn)行認(rèn)證判斷。在與服務(wù)器交互時(shí),subject信息截圖如下:

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

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

相關(guān)文章

最新評(píng)論