提交修改

This commit is contained in:
quyixiao 2025-04-12 23:21:24 +08:00
parent 8ec19cfca7
commit 7e213deefe
3 changed files with 47 additions and 12 deletions

View File

@ -296,4 +296,14 @@ public class ApiConstants {
public static final String TENCENT_AUTH = "20C7941B2CCAD689A90C796A4A9DF04A";
/**
* 不需要 注解名称
*/
public static final String EB_AUTHENTICATION = "EbAuthentication";
public static final String t_auth = "t_auth";
}

View File

@ -23,7 +23,7 @@ public class AnnotationUtils {
if (annotations != null && annotations.length > 0) {
for (Annotation annotation : annotations) {
if (name.equals(getAnnotationName(annotation))) {
return getAnnotationValue(annotation);
return getAnnotationValue(annotation,"value");
}
}
}
@ -43,6 +43,20 @@ public class AnnotationUtils {
return false;
}
public static String getAnnotation(Method method, String name) {
Annotation[] annotations = method.getAnnotations();
if (annotations != null && annotations.length > 0) {
for (Annotation annotation : annotations) {
if (name.equals(getAnnotationName(annotation))) {
return getAnnotationValue(annotation,"tencent");
}
}
}
return null;
}
public static String getAnnotationName(Annotation annotation) {
String annotionStr = annotation.toString();
int a = annotionStr.indexOf("(", 0);
@ -58,9 +72,9 @@ public class AnnotationUtils {
public static <T> T getAnnotationValue(Annotation annotation) {
public static <T> T getAnnotationValue(Annotation annotation,String key) {
try {
Method method = annotation.getClass().getMethod("value");
Method method = annotation.getClass().getMethod(key);
if (method != null) {
T paramName = (T) method.invoke(annotation);
return paramName;

View File

@ -1,6 +1,7 @@
package com.heyu.api.aop;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heyu.api.common.LogAspect;
import com.heyu.api.data.constants.ApiConstants;
import com.heyu.api.data.service.bussiness.RedisSettingService;
@ -48,6 +49,8 @@ public class LogAop {
public static Map<String, Boolean> faceAuthMap = new HashMap<>();
public static Map<String, String> faceAuthTentMap = new HashMap<>();
@Value("${eb.config.rabbitQueue.accountAmountQueue}")
private String accountAmountQueue;
@ -64,7 +67,6 @@ public class LogAop {
Object result = null;
StringBuilder sb = new StringBuilder();
String methodName = "";
String token = "";
String ip = "";
String args = "";
String className = "";
@ -91,6 +93,7 @@ public class LogAop {
className = clazz.getName();
// 类名加方法名
String classNameAndMethodName = className + "#" + methodName;
String classNameAndMethodNametencent = className + "#" + methodName + "#tencent";
sb.append("LoggerAop args:").append(args).append(BLANK_SPACE)
.append("class:").append(className).append("#").append(methodName).append(BLANK_SPACE)
@ -100,26 +103,31 @@ public class LogAop {
Boolean intercept = faceAuthMap.get(className);
Boolean classMethodConfigNotIntercept = faceAuthMap.get(classNameAndMethodName);
String authConfig = request.getHeader("X-TCloudMarket-Custom-AuthConfig");
log.info("authConfig:{}",authConfig);
if (intercept == null) {
boolean exitClassAnnotation = AnnotationUtils.hasAnnotation(clazz, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
boolean exitMethodAnnotation = AnnotationUtils.hasAnnotation(method, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
String tencent = AnnotationUtils.getAnnotation(method, ApiConstants.EB_AUTHENTICATION);
// 如果存在NotIntercept则不进行拦截否则进行拦截
intercept = exitClassAnnotation ? false : true;
classMethodConfigNotIntercept = exitMethodAnnotation ? false : true;
faceAuthMap.put(className, intercept);
faceAuthMap.put(classNameAndMethodName, intercept);
faceAuthMap.put(classNameAndMethodName, classMethodConfigNotIntercept);
faceAuthTentMap.put(classNameAndMethodNametencent , tencent);
log.info("LogAop one cache className:{},classNameAndMethodName:{},classNameAndMethodNametencent:{}", intercept, classMethodConfigNotIntercept, tencent);
}
// 如果需要进行拦截
if (!intercept && !classMethodConfigNotIntercept ) {
return R.error("auth error");
if (!intercept && !classMethodConfigNotIntercept) {
String authConfig = request.getHeader("X-TCloudMarket-Custom-AuthConfig");
Map<String, Object> authConfigMap = JSONObject.parseObject(authConfig, Map.class);
String auth = faceAuthTentMap.get(classNameAndMethodNametencent);
if(StringUtils.isBlank(auth) || !auth.equals(authConfigMap.get(ApiConstants.t_auth))){
return R.error("auth error");
}
}
result = point.proceed();
} catch (Exception e) {
log.error("LogAop set error " + sb.toString(), e);
@ -144,6 +152,9 @@ public class LogAop {
}
private String recordRequestLog(Object[] argArrs, String uri) {
String mediaType = "";
String args = null;