完善 SecureUtil

This commit is contained in:
卢春梦 2024-03-10 14:28:45 +08:00
parent 6af2daad18
commit 823bdca0b4

View File

@ -119,6 +119,16 @@ public class SecureUtil {
return (BladeUser) bladeUser; return (BladeUser) bladeUser;
} }
/**
* 获取用户信息
*
* @param auth auth
* @return BladeUser
*/
public static BladeUser getUser(String auth) {
return getUser(getClaims(auth));
}
/** /**
* 获取用户信息 * 获取用户信息
* *
@ -126,7 +136,16 @@ public class SecureUtil {
* @return BladeUser * @return BladeUser
*/ */
public static BladeUser getUser(HttpServletRequest request) { public static BladeUser getUser(HttpServletRequest request) {
Claims claims = getClaims(request); return getUser(getClaims(request));
}
/**
* 获取用户信息
*
* @param claims Claims
* @return BladeUser
*/
public static BladeUser getUser(Claims claims) {
if (claims == null) { if (claims == null) {
return null; return null;
} }
@ -293,10 +312,20 @@ public class SecureUtil {
*/ */
public static Claims getClaims(HttpServletRequest request) { public static Claims getClaims(HttpServletRequest request) {
String auth = request.getHeader(SecureUtil.HEADER); String auth = request.getHeader(SecureUtil.HEADER);
String token = getToken( if (StringUtil.isBlank(auth)) {
StringUtil.isNotBlank(auth) ? auth : request.getParameter(SecureUtil.HEADER) auth = request.getParameter(SecureUtil.HEADER);
); }
return SecureUtil.parseJWT(token); return getClaims(auth);
}
/**
* 获取Claims
*
* @param auth auth
* @return Claims
*/
public static Claims getClaims(String auth) {
return SecureUtil.parseJWT(getToken(auth));
} }
/** /**