提交修改
This commit is contained in:
parent
8ec19cfca7
commit
7e213deefe
@ -296,4 +296,14 @@ public class ApiConstants {
|
|||||||
public static final String TENCENT_AUTH = "20C7941B2CCAD689A90C796A4A9DF04A";
|
public static final String TENCENT_AUTH = "20C7941B2CCAD689A90C796A4A9DF04A";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不需要 注解名称
|
||||||
|
*/
|
||||||
|
public static final String EB_AUTHENTICATION = "EbAuthentication";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String t_auth = "t_auth";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class AnnotationUtils {
|
|||||||
if (annotations != null && annotations.length > 0) {
|
if (annotations != null && annotations.length > 0) {
|
||||||
for (Annotation annotation : annotations) {
|
for (Annotation annotation : annotations) {
|
||||||
if (name.equals(getAnnotationName(annotation))) {
|
if (name.equals(getAnnotationName(annotation))) {
|
||||||
return getAnnotationValue(annotation);
|
return getAnnotationValue(annotation,"value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,6 +43,20 @@ public class AnnotationUtils {
|
|||||||
return false;
|
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) {
|
public static String getAnnotationName(Annotation annotation) {
|
||||||
String annotionStr = annotation.toString();
|
String annotionStr = annotation.toString();
|
||||||
int a = annotionStr.indexOf("(", 0);
|
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 {
|
try {
|
||||||
Method method = annotation.getClass().getMethod("value");
|
Method method = annotation.getClass().getMethod(key);
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
T paramName = (T) method.invoke(annotation);
|
T paramName = (T) method.invoke(annotation);
|
||||||
return paramName;
|
return paramName;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.heyu.api.aop;
|
package com.heyu.api.aop;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.heyu.api.common.LogAspect;
|
import com.heyu.api.common.LogAspect;
|
||||||
import com.heyu.api.data.constants.ApiConstants;
|
import com.heyu.api.data.constants.ApiConstants;
|
||||||
import com.heyu.api.data.service.bussiness.RedisSettingService;
|
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, Boolean> faceAuthMap = new HashMap<>();
|
||||||
|
|
||||||
|
public static Map<String, String> faceAuthTentMap = new HashMap<>();
|
||||||
|
|
||||||
@Value("${eb.config.rabbitQueue.accountAmountQueue}")
|
@Value("${eb.config.rabbitQueue.accountAmountQueue}")
|
||||||
private String accountAmountQueue;
|
private String accountAmountQueue;
|
||||||
|
|
||||||
@ -64,7 +67,6 @@ public class LogAop {
|
|||||||
Object result = null;
|
Object result = null;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String methodName = "";
|
String methodName = "";
|
||||||
String token = "";
|
|
||||||
String ip = "";
|
String ip = "";
|
||||||
String args = "";
|
String args = "";
|
||||||
String className = "";
|
String className = "";
|
||||||
@ -91,6 +93,7 @@ public class LogAop {
|
|||||||
className = clazz.getName();
|
className = clazz.getName();
|
||||||
// 类名加方法名
|
// 类名加方法名
|
||||||
String classNameAndMethodName = className + "#" + methodName;
|
String classNameAndMethodName = className + "#" + methodName;
|
||||||
|
String classNameAndMethodNametencent = className + "#" + methodName + "#tencent";
|
||||||
|
|
||||||
sb.append("LoggerAop args:").append(args).append(BLANK_SPACE)
|
sb.append("LoggerAop args:").append(args).append(BLANK_SPACE)
|
||||||
.append("class:").append(className).append("#").append(methodName).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 intercept = faceAuthMap.get(className);
|
||||||
Boolean classMethodConfigNotIntercept = faceAuthMap.get(classNameAndMethodName);
|
Boolean classMethodConfigNotIntercept = faceAuthMap.get(classNameAndMethodName);
|
||||||
|
|
||||||
String authConfig = request.getHeader("X-TCloudMarket-Custom-AuthConfig");
|
|
||||||
log.info("authConfig:{}",authConfig);
|
|
||||||
|
|
||||||
if (intercept == null) {
|
if (intercept == null) {
|
||||||
boolean exitClassAnnotation = AnnotationUtils.hasAnnotation(clazz, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
|
boolean exitClassAnnotation = AnnotationUtils.hasAnnotation(clazz, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
|
||||||
boolean exitMethodAnnotation = AnnotationUtils.hasAnnotation(method, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
|
boolean exitMethodAnnotation = AnnotationUtils.hasAnnotation(method, ApiConstants.NOT_INTERCEPT_ANNOTATION_NAME);
|
||||||
|
String tencent = AnnotationUtils.getAnnotation(method, ApiConstants.EB_AUTHENTICATION);
|
||||||
// 如果存在NotIntercept则不进行拦截,否则进行拦截
|
// 如果存在NotIntercept则不进行拦截,否则进行拦截
|
||||||
intercept = exitClassAnnotation ? false : true;
|
intercept = exitClassAnnotation ? false : true;
|
||||||
classMethodConfigNotIntercept = exitMethodAnnotation ? false : true;
|
classMethodConfigNotIntercept = exitMethodAnnotation ? false : true;
|
||||||
|
|
||||||
faceAuthMap.put(className, intercept);
|
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 ) {
|
if (!intercept && !classMethodConfigNotIntercept) {
|
||||||
|
String authConfig = request.getHeader("X-TCloudMarket-Custom-AuthConfig");
|
||||||
|
Map<String, Object> authConfigMap = JSONObject.parseObject(authConfig, Map.class);
|
||||||
return R.error("auth error");
|
String auth = faceAuthTentMap.get(classNameAndMethodNametencent);
|
||||||
|
if(StringUtils.isBlank(auth) || !auth.equals(authConfigMap.get(ApiConstants.t_auth))){
|
||||||
|
return R.error("auth error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result = point.proceed();
|
result = point.proceed();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("LogAop set error " + sb.toString(), e);
|
log.error("LogAop set error " + sb.toString(), e);
|
||||||
@ -144,6 +152,9 @@ public class LogAop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String recordRequestLog(Object[] argArrs, String uri) {
|
private String recordRequestLog(Object[] argArrs, String uri) {
|
||||||
String mediaType = "";
|
String mediaType = "";
|
||||||
String args = null;
|
String args = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user