update
This commit is contained in:
@@ -16,7 +16,7 @@ public class CommonConstants {
|
||||
|
||||
public static final String DEFAULT_AVATAR = "DefaultAvatar";
|
||||
|
||||
public static final int ACTION_TOKEN_EXPIRE = 14400;
|
||||
public static final int ACCESS_TOKEN_EXPIRE = 14400;
|
||||
|
||||
public static final int REFRESH_TOKEN_EXPIRE = 60*60*24*30;
|
||||
|
||||
|
||||
@@ -24,5 +24,10 @@ public class CurrentUser {
|
||||
*/
|
||||
private Boolean isAdmin;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
private SysRoleDO sysRoleDO;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class UserContext {
|
||||
public class CurrentUserContext {
|
||||
|
||||
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
private RedisUtilPool redisUtilPool;
|
||||
@Resource
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
@Value("${corpId:null}")
|
||||
@Value("${corp.id:null}")
|
||||
private String corpId;
|
||||
|
||||
@Override
|
||||
@@ -78,13 +78,14 @@ public class LoginServiceImpl implements LoginService {
|
||||
currentUser.setIsAdmin(enterpriseUser.getIsAdmin());
|
||||
currentUser.setSysRoleDO(sysRole);
|
||||
currentUser.setCorpId(corpId);
|
||||
currentUser.setAvatar(enterpriseUser.getAvatar());
|
||||
//生成令牌
|
||||
RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
|
||||
String token = randomNumberGenerator.nextBytes().toHex();
|
||||
String refreshToken = randomNumberGenerator.nextBytes().toHex();
|
||||
currentUser.setName(enterpriseUser.getName());
|
||||
currentUser.setAccessToken(token);
|
||||
redisUtilPool.setString(CommonConstants.ACCESS_TOKEN_KEY + ":" + token, JSON.toJSONString(currentUser), CommonConstants.ACTION_TOKEN_EXPIRE);
|
||||
redisUtilPool.setString(CommonConstants.ACCESS_TOKEN_KEY + ":" + token, JSON.toJSONString(currentUser), CommonConstants.ACCESS_TOKEN_EXPIRE);
|
||||
redisUtilPool.setString(currentUser.getUserId(), token);
|
||||
redisUtilPool.setString(CommonConstants.REFRESH_TOKEN_KEY+":"+refreshToken,JSON.toJSONString(refreshUser), CommonConstants.REFRESH_TOKEN_EXPIRE);
|
||||
log.info("[" + enterpriseUser.getName() + "; action_token:"+ token + "; userId:" + currentUser.getUserId() +"]登入系统成功");
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.UserContext;
|
||||
import com.cool.store.context.CurrentUserContext;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -74,7 +74,7 @@ public class TokenValidateFilter implements Filter {
|
||||
String userStr = "";
|
||||
CurrentUser currentUser = null;
|
||||
boolean isInWhiteList = excludePath(uri);
|
||||
String accessToken = reqs.getParameter("access_token");
|
||||
String accessToken = reqs.getHeader("accessToken");
|
||||
String key = "access_token:" + accessToken;
|
||||
if(StringUtils.isNotBlank(accessToken)){
|
||||
userStr = redisUtilPool.getString(key);
|
||||
@@ -105,10 +105,10 @@ public class TokenValidateFilter implements Filter {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
UserContext.setUser(userStr);
|
||||
CurrentUserContext.setUser(userStr);
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} finally {
|
||||
UserContext.removeUser();
|
||||
CurrentUserContext.removeUser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.context.CurrentUserContext;
|
||||
import com.cool.store.dto.login.FeiShuLoginDTO;
|
||||
import com.cool.store.dto.login.UserIdInfoDTO;
|
||||
import com.cool.store.enums.AppTypeEnum;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.http.ISVHttpRequest;
|
||||
@@ -56,4 +56,9 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/getUserInfoByToken")
|
||||
public ResponseResult getUserInfoByToken(){
|
||||
return ResponseResult.success(CurrentUserContext.getUser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class OssClientController {
|
||||
private String endpoint;
|
||||
@Value("${oss.bucket:null}")
|
||||
private String bucket;
|
||||
@Value("${corpId:null}")
|
||||
@Value("${corp.id:null}")
|
||||
private String corpId;
|
||||
|
||||
@GetMapping("/getUploadFileConfig")
|
||||
|
||||
Reference in New Issue
Block a user