审计日志相关代码提交
This commit is contained in:
@@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -70,7 +71,6 @@ public class RequestUtil {
|
||||
String refreshToken = request.getParameter(SecurityConstants.REFRESH_TOKEN_KEY);
|
||||
String payload = StrUtil.toString(JWSObject.parse(refreshToken).getPayload());
|
||||
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(payload);
|
||||
|
||||
String authenticationMethod = jsonObject.getStr(SecurityConstants.AUTHENTICATION_METHOD);
|
||||
if (StrUtil.isBlank(authenticationMethod)) {
|
||||
authenticationMethod = AuthenticationMethodEnum.USERNAME.getValue();
|
||||
@@ -86,8 +86,8 @@ public class RequestUtil {
|
||||
*/
|
||||
public static HttpServletRequest getRequest() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if(Objects.nonNull(requestAttributes)){
|
||||
return ((ServletRequestAttributes)requestAttributes).getRequest();
|
||||
if (Objects.nonNull(requestAttributes)) {
|
||||
return ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -132,8 +132,8 @@ public class RequestUtil {
|
||||
*/
|
||||
public static JSONObject getJwtPayload() {
|
||||
JSONObject jsonObject = null;
|
||||
String jwtPayload = getRequest().getHeader(SecurityConstants.JWT_PAYLOAD_KEY);
|
||||
try {
|
||||
String jwtPayload = getRequest().getHeader(SecurityConstants.JWT_PAYLOAD_KEY);
|
||||
if (StrUtil.isNotBlank(jwtPayload)) {
|
||||
jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString());
|
||||
jsonObject = JSONObject.fromObject(jwtPayload);
|
||||
@@ -150,8 +150,8 @@ public class RequestUtil {
|
||||
*/
|
||||
public static JSONObject getJwtPayload(HttpServletRequest request) {
|
||||
JSONObject jsonObject = null;
|
||||
String jwtPayload = request.getHeader(SecurityConstants.JWT_PAYLOAD_KEY);
|
||||
try {
|
||||
String jwtPayload = request.getHeader(SecurityConstants.JWT_PAYLOAD_KEY);
|
||||
if (StrUtil.isNotBlank(jwtPayload)) {
|
||||
jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString());
|
||||
jsonObject = JSONObject.fromObject(jwtPayload);
|
||||
@@ -170,8 +170,8 @@ public class RequestUtil {
|
||||
JSONObject jsonObject = null;
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
try {
|
||||
String jwtPayload = headers.get(SecurityConstants.JWT_PAYLOAD_KEY).get(0);
|
||||
if (StrUtil.isNotBlank(jwtPayload)) {
|
||||
if (CollectionUtils.isNotEmpty(headers.get(SecurityConstants.JWT_PAYLOAD_KEY))) {
|
||||
String jwtPayload = headers.get(SecurityConstants.JWT_PAYLOAD_KEY).get(0);
|
||||
jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString());
|
||||
jsonObject = JSONObject.fromObject(jwtPayload);
|
||||
}
|
||||
@@ -182,6 +182,29 @@ public class RequestUtil {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpServletRequest获取在网关中存储的用户索引
|
||||
*/
|
||||
public static String getUserIndex(ServerHttpRequest request) {
|
||||
String userIndex = LogInfo.UNKNOWN_USER;
|
||||
JSONObject jwtPayload = getJwtPayload(request);
|
||||
if (Objects.nonNull(jwtPayload)) {
|
||||
userIndex = jwtPayload.getString(SecurityConstants.USER_INDEX_KEY);
|
||||
}
|
||||
return userIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpServletRequest获取在网关中存储的用户索引
|
||||
*/
|
||||
public static String getUserIndex(HttpServletRequest request) {
|
||||
String userIndex = LogInfo.UNKNOWN_USER;
|
||||
JSONObject jwtPayload = getJwtPayload(request);
|
||||
if (Objects.nonNull(jwtPayload)) {
|
||||
userIndex = jwtPayload.getString(SecurityConstants.USER_INDEX_KEY);
|
||||
}
|
||||
return userIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpServletRequest获取在网关中存储的用户索引
|
||||
|
||||
Reference in New Issue
Block a user