Authored by mali

版本升级

... ... @@ -6,6 +6,7 @@ package com.yoho.ufo.interceptor;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
... ... @@ -13,6 +14,7 @@ import com.yoho.ufo.constants.CodeEnum;
import com.yoho.ufo.constants.PlatformConstant;
import com.yoho.ufo.login.model.OperatorBean;
import com.yoho.ufo.login.model.UserInfoResponseBO;
import com.yoho.ufo.login.service.LoginSessionService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -29,6 +31,9 @@ import org.springframework.web.servlet.ModelAndView;
public class UrlInterceptor implements HandlerInterceptor {
private static final Logger log = LoggerFactory.getLogger(UrlInterceptor.class);
@Resource
private LoginSessionService loginSessionService;
//免过滤列表(不管有没有session都可以访问)
private List<String> firstNoFilterList = new ArrayList<String>();
... ... @@ -64,7 +69,7 @@ public class UrlInterceptor implements HandlerInterceptor {
return true;
}
//过滤session失效的
//UserInfoResponseBO user = loginSessionUtil.getLoginSession(request);
//UserInfoResponseBO user = loginSessionService.getLoginSession()
UserInfoResponseBO user = (UserInfoResponseBO) request.getSession().getAttribute(PlatformConstant.USER_SESSION);
if (user == null) {
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.ufo.login.model.MenuInfoResponseBO;
import com.yoho.ufo.login.model.Response;
import com.yoho.ufo.login.model.UserInfoResponseBO;
import com.yoho.ufo.login.service.LoginService;
import com.yoho.ufo.login.service.LoginSessionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
... ... @@ -30,6 +31,9 @@ public class LoginController {
@Resource
private LoginService loginService;
@Resource
private LoginSessionService loginSessionService;
/**
* 登录
* @param loginName
... ... @@ -54,6 +58,8 @@ public class LoginController {
//登录成功,把用户信息存入session
session.setAttribute(PlatformConstant.USER_SESSION, responseBO.getData());
// loginSessionService.setLoginSession(responseBO.getData(), request, responseBO.getData().getPid());
//获取用户所能见的菜单
Response<Map<String, List<MenuInfoResponseBO>>> menuResp = loginService.getUserMenu(responseBO.getData().getPid(), responseBO.getData().getRole_id(), "7");
... ...
... ... @@ -40,7 +40,7 @@ public class LoginSessionService {
if (StringUtils.isBlank(pid)) {
return null;
}
String userRedisValue = yhValueOperations.get(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, Integer.parseInt(pid))));
String userRedisValue = yhValueOperations.get(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)));
logger.info( "getLoginSession userRedisValue is {}.", userRedisValue);
if (StringUtils.isBlank(userRedisValue)) {
return null;
... ... @@ -53,16 +53,16 @@ public class LoginSessionService {
/**
* 设置登录用户的缓存
*/
public void setLoginSession(UserInfoResponseBO userInfoResponseBO, HttpServletRequest request, int pid) {
public void setLoginSession(UserInfoResponseBO userInfoResponseBO, HttpServletRequest request, String pid) {
logger.info( "setLoginSession userInfoResponseBO is {} and pid is {}.", userInfoResponseBO,pid);
yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getPidKey(request)), String.valueOf(pid), 2, TimeUnit.HOURS);
yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)), JSON.toJSONString(userInfoResponseBO), 2, TimeUnit.HOURS);
//yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getPidKey(request)), String.valueOf(pid), 2, TimeUnit.HOURS);
yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)), JSON.toJSONString(userInfoResponseBO), 20, TimeUnit.MINUTES);
}
/**
* 清除登录用户的缓存
*/
public void clearLoginSession(HttpServletRequest request, int pid){
public void clearLoginSession(HttpServletRequest request, String pid){
logger.info( "clearLoginSession pid is {}.", pid);
String pidKey = getPidKey(request);
String userKey = getUserKey(request, pid);
... ... @@ -75,8 +75,8 @@ public class LoginSessionService {
return RedisKeyConstants.LOGIN_PID_PRE + getRemoteIp(request);
}
public String getUserKey(HttpServletRequest request, int pid) {
return RedisKeyConstants.LOGIN_USER_PRE + pid + "_" + getRemoteIp(request);
public String getUserKey(HttpServletRequest request, String pid) {
return RedisKeyConstants.LOGIN_USER_PRE + pid;// + "_" + getRemoteIp(request);
}
private String getRemoteIp(HttpServletRequest request) {
... ...