This commit is contained in:
caozehui
2025-02-27 11:10:12 +08:00
parent 4a4393f890
commit 951c364727

View File

@@ -2,7 +2,6 @@ package com.njcn.web.utils;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.njcn.common.bean.CustomCacheUtil;
@@ -27,10 +26,10 @@ public class RequestUtil {
HttpServletRequest request = HttpServletUtil.getRequest();
String accessTokenStr = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
String accessToken = null;
if (StrUtil.isNotBlank(accessTokenStr)) {
if (StrUtil.isNotBlank(accessTokenStr) && accessTokenStr.startsWith(SecurityConstants.AUTHORIZATION_PREFIX)) {
accessToken = accessTokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
}
return accessToken;
return "".equals(accessToken)? null : accessToken;
}
/**
@@ -60,9 +59,10 @@ public class RequestUtil {
/**
* 获取当前登录用户的用户名
*
* @return 若成功返回当前登录用户的用户名若失败返回null
*/
public static String getUserName(){
public static String getUserName() {
String userJson = getUserJson();
String username = null;
if (StrUtil.isNotBlank(userJson)) {
@@ -74,14 +74,15 @@ public class RequestUtil {
/**
* 从缓冲中获取当前登录用户的JSON格式的用户信息
*
* @return 若成功返回当前登录用户的JSON格式的用户信息若失败返回null
*/
public static String getUserJson(){
public static String getUserJson() {
String accessToken = getAccessToken();
String userJson = null;
if (StrUtil.isNotBlank(accessToken)) {
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
userJson = customCacheUtil.get(accessToken,false);
userJson = customCacheUtil.get(accessToken, false);
}
return userJson;
}