Commit d043ed08 by fanjiaxin

联调问题处理

parent 9e652ef7
Pipeline #71570 passed with stages
in 1 minute 4 seconds
......@@ -36,4 +36,16 @@ public class LoginUserHelper {
redisClient.setStr(CoreConstant.REDIS_TOKEN_USER_KEY + token,
JSON.toJSONString(loginUserInfo), CoreConstant.REDIS_TOKEN_EXPIRE_SECONDS);
}
/**
* 保存用户认证信息
*/
public void setLoginUserInfo(String token) {
LoginUserInfo loginUserInfo = getLoginUserInfo(token);
if(null != loginUserInfo) {
LoginUserContextHolder.set(loginUserInfo);
redisClient.setStr(CoreConstant.REDIS_TOKEN_USER_KEY + token,
JSON.toJSONString(loginUserInfo), CoreConstant.REDIS_TOKEN_EXPIRE_SECONDS);
}
}
}
package com.netease.yanxuan.wx.store.sharer.biz.interceptor;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserHelper;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo;
import com.netease.yanxuan.wx.store.sharer.common.annotation.LoginRequired;
import com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException;
import com.netease.yanxuan.wx.store.sharer.common.handler.RedisClient;
......@@ -10,10 +11,12 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
/**
* @Description 鉴权拦截器
......@@ -31,7 +34,11 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.info("AuthInterceptor preHandle execute, url:{}", request.getRequestURI());
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
LoginRequired clientMethodAnnotation = method.getAnnotation(LoginRequired.class);
String token = request.getHeader(CoreConstant.AUTH_HEADER_TOKEN_KEY);
if (clientMethodAnnotation != null) {
if (StringUtils.isEmpty(token)) {
throw new NoAuthException("用户认证失败,TOKEN为空");
}
......@@ -40,8 +47,11 @@ public class AuthInterceptor implements HandlerInterceptor {
log.info("用户登录状态过期,token缓存失效,path:{}", request.getServletPath());
throw new NoAuthException("用户登录状态过期");
}
}
if(StringUtils.isNotBlank(token)){
// 刷新缓存
jwtHelper.setLoginUserInfo(token, loginUserInfo);
jwtHelper.setLoginUserInfo(token);
}
return true;
}
......
package com.netease.yanxuan.wx.store.sharer.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* des: 登录注解
* 限制只有登录才能访问的接口加此注解
* @author :XDD
* @ date : 2020/9/11 14:09
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface LoginRequired {
}
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