Commit 5e9fb667 authored by xc's avatar xc

shiro限定并发登录人数

parent 040cf240
......@@ -71,10 +71,13 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
HttpServletRequest httpServletRequest=(HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
// 登录超时
Integer userId = getUserId();
Object object = SecurityUtils.getSubject().getPrincipal();
Integer userId = getUserId(object);
Long SessionTime = (Long)redisTemplate.opsForValue().get("shiroSessionTime:"+userId);
log.info("KickoutSessionControlFilter 账号id:{} 已登录时长:{} 秒",userId,(new Date().getTime()-SessionTime)/1000);
if((new Date().getTime()-SessionTime) >= (EXPIRE_TIME * 1000)){
Long loginTime = new Date().getTime()-SessionTime;
Boolean loginOutTime = (new Date().getTime()-SessionTime) >= (EXPIRE_TIME * 1000);
log.info("KickoutSessionControlFilter 账号id:{} 已登录时长:{} 秒,是否超时:{}",userId,loginTime/1000,loginOutTime);
if(loginOutTime){
log.info("KickoutSessionControlFilter 登录已超时-----返回1003,账号id:{} 已登录时长:{} 分钟",userId,(new Date().getTime()-SessionTime)/1000/60);
// 登录超时,抛出异常 Login timed out, please log in again
thrLogoutException(httpServletRequest,httpServletResponse, "1003", "登录超时,请重新登录");
......@@ -195,20 +198,20 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
}
}
private Integer getUserId(){
private Integer getUserId(Object object){
Integer userId = null;
try {
//客户端
User user = (User) SecurityUtils.getSubject().getPrincipal();
User user = (User) object;
userId = user.getId();
} catch (Exception e) {
try {
//管理端
AccountInfo accountInfo = (AccountInfo) SecurityUtils.getSubject().getPrincipal();
AccountInfo accountInfo = (AccountInfo) object;
userId = accountInfo.getId();
} catch (Exception en) {
//员工端
Staff staff = (Staff) SecurityUtils.getSubject().getPrincipal();
Staff staff = (Staff) object;
userId = staff.getId();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment