Commit 021927a1 by zhanghj

V1.1.0--抽出公共的剔除下线接口

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@21128 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 7099912b
......@@ -98,6 +98,9 @@ public class UserController extends BaseController {
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private ShiroUtil shiroUtil;
/**
* @param userQueryVo
......@@ -865,7 +868,7 @@ public class UserController extends BaseController {
/*
* 同一用户单端登录
*/
singleTerminalTypeLogin(username);
shiroUtil.singleTerminalTypeLogin(username);
/*
* shiro登录校验
......@@ -904,22 +907,6 @@ public class UserController extends BaseController {
return result;
}
/**
* @param username void
* @author zhanghj
* @Title: singleTerminalTypeLogin
* @Description: TODO 同一用户单端登录
*/
private void singleTerminalTypeLogin(String username) {
Collection<Session> sessions = redisSessionDAO.getActiveSessions();
for (Session sess : sessions) {
//shiro session可以拿到已经登陆的username
if (username.equals(sess.getAttribute("username"))) {
redisSessionDAO.delete(sess); //session清除
sess.setTimeout(0);
}
}
}
/**
* @return ResultObject
......@@ -1077,7 +1064,7 @@ public class UserController extends BaseController {
/*
* 同一用户单端登录
*/
singleTerminalTypeLogin(username);
shiroUtil.singleTerminalTypeLogin(username);
/*
* shiro登录校验
......
package com.glsx.usercenter.utils;
import java.util.Collection;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.mgt.RealmSecurityManager;
......@@ -7,6 +9,9 @@ import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.SimplePrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.glsx.common.utils.StringUtils;
import com.glsx.common.utils.bean.BeanUtils;
......@@ -22,7 +27,13 @@ import com.glsx.usercenter.shiro.UserRealm;
* @date 2019年2月13日 下午4:44:10
* @version 1.0.0
*/
@Component
public class ShiroUtil {
@Autowired
private RedisSessionDAO redisSessionDAO;
public static Subject getSubjct() {
return SecurityUtils.getSubject();
}
......@@ -85,4 +96,21 @@ public class ShiroUtil {
String hex = secureRandom.nextBytes(3).toHex();
return hex;
}
/**
* @param username void
* @author zhanghj
* @Title: singleTerminalTypeLogin
* @Description: TODO 同一用户单端登录
*/
public void singleTerminalTypeLogin(String username) {
Collection<Session> sessions = redisSessionDAO.getActiveSessions();
for (Session sess : sessions) {
//shiro session可以拿到已经登陆的username
if (username.equals(sess.getAttribute("username"))) {
redisSessionDAO.delete(sess); //session清除
sess.setTimeout(0);
}
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!