Commit 8fad1544 by 陶光胜

Merge branch 'developer' into 'master'

Developer

See merge request !5
parents 1f28f9e6 a2a7aed3
......@@ -14,7 +14,10 @@ import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.TimeUnit;
public class UserContext {
public static final Long expireLength = 1l;
/**
* 有效期4小时
*/
public static final Long expireLength = 4L;
private static UserContext userContext = null;
private static final Logger log = LogManager.getLogger(UserContext.class);
......@@ -34,16 +37,12 @@ public class UserContext {
}
public UserDetail get(){
String token = getToken();
if(StringUtils.isBlank(token)){
return new UserDetail();
}
String key = Constants.TOKEN_KEY + token;
Object cache = RedisUtil.getCache(key);
if(cache != null){
return (UserDetail) cache;
return (UserDetail) RequestContext.getContext().getRequest().getAttribute("user");
}
return new UserDetail();
public UserDetail getByRedis(){
String token = getToken();
return getByToken(token);
}
public UserDetail getByToken(String token) {
......
package com.gic.enterprise.interceptor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.gic.enterprise.ano.IgnoreLogin;
import com.gic.enterprise.base.MenuInfo;
......@@ -23,7 +8,19 @@ import com.gic.enterprise.context.UserContext;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.CommonException;
import com.gic.enterprise.utils.UserDetail;
import com.gic.enterprise.utils.UserDetailUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AuthInterceptor extends HandlerInterceptorAdapter {
......@@ -63,12 +60,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String uri = request.getRequestURI();
log.info("权限拦截token url:{}", uri);
HandlerMethod handler = (HandlerMethod) object;
//免登录接口路由
IgnoreLogin ignoreLogin = handler.getMethodAnnotation(IgnoreLogin.class);
if (null != ignoreLogin) {
return true;
}
//操作项标志位
String isControl = request.getHeader("isControl");
......@@ -81,10 +72,19 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return true;
}
//判断是否有权限的路径
UserDetail userDetail = UserDetailUtils.getUserDetail();
UserDetail userDetail = UserContext.getContext().getByRedis();
if (userDetail == null || userDetail.getUserInfo() == null) {
throw new CommonException(ErrorCode.LOGIN_INVALID.getErrorCode(), "登录信息不存在,请登录");
}
request.setAttribute("user", userDetail);
HandlerMethod handler = (HandlerMethod) object;
//免登录接口路由
IgnoreLogin ignoreLogin = handler.getMethodAnnotation(IgnoreLogin.class);
if (null != ignoreLogin) {
return true;
}
//不需要拦截的路径
if (ignoreUriAfterLoginMap.containsKey(uri)) {
......
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