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