全局登录态处理
This commit is contained in:
@@ -3,9 +3,9 @@ package com.cool.store.config;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.context.CurrentUserContext;
|
||||
import com.cool.store.context.CurrentUserHolder;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.context.LoginUserInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -72,14 +72,14 @@ public class TokenValidateFilter implements Filter {
|
||||
String uri = reqs.getRequestURI();
|
||||
String method = reqs.getMethod();
|
||||
String userStr = "";
|
||||
CurrentUser currentUser = null;
|
||||
LoginUserInfo currentUser = null;
|
||||
boolean isInWhiteList = excludePath(uri);
|
||||
String accessToken = reqs.getHeader("accessToken");
|
||||
String key = "access_token:" + accessToken;
|
||||
if(StringUtils.isNotBlank(accessToken)){
|
||||
userStr = redisUtilPool.getString(key);
|
||||
if(StringUtils.isNotBlank(userStr)){
|
||||
currentUser = JSON.parseObject(userStr, CurrentUser.class);
|
||||
currentUser = JSON.parseObject(userStr, LoginUserInfo.class);
|
||||
}
|
||||
}
|
||||
log.info("url:{}", uri);
|
||||
@@ -105,10 +105,10 @@ public class TokenValidateFilter implements Filter {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
CurrentUserContext.setUser(userStr);
|
||||
CurrentUserHolder.setUser(userStr);
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} finally {
|
||||
CurrentUserContext.removeUser();
|
||||
CurrentUserHolder.removeUser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.context.CurrentUserContext;
|
||||
import com.cool.store.context.CurrentUserHolder;
|
||||
import com.cool.store.dto.login.FeiShuLoginDTO;
|
||||
import com.cool.store.dto.login.UserIdInfoDTO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
@@ -59,7 +59,7 @@ public class LoginController {
|
||||
|
||||
@GetMapping("/getUserInfoByToken")
|
||||
public ResponseResult getUserInfoByToken(){
|
||||
return ResponseResult.success(CurrentUserContext.getUser());
|
||||
return ResponseResult.success(CurrentUserHolder.getUser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
import com.cool.store.context.CurrentUserHolder;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.MenuService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -21,7 +22,7 @@ public class MenuController {
|
||||
|
||||
@GetMapping("/menu/getUserMenus")
|
||||
public ResponseResult getUserMenus(){
|
||||
return ResponseResult.success(menuService.getUserMenus(null));
|
||||
return ResponseResult.success(menuService.getUserMenus(CurrentUserHolder.getUserId(), CurrentUserHolder.getRoleId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user