提交修改
This commit is contained in:
parent
b664c0c1a2
commit
92798b99a0
@ -75,7 +75,7 @@ public class LogAop {
|
||||
String uri = "";
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
String traceId = attributes.getRequest().getHeader("traceId");
|
||||
if(StringUtils.isBlank(traceId)){
|
||||
if (StringUtils.isBlank(traceId)) {
|
||||
traceId = OrderUtil.getUserPoolOrder("on");
|
||||
}
|
||||
LogAspect.threadLocalNo.set(traceId);
|
||||
@ -83,54 +83,54 @@ public class LogAop {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
uri = attributes.getRequest().getRequestURI();
|
||||
|
||||
if(uri.startsWith("/mm/") || uri.startsWith("/app/")){
|
||||
if (uri.startsWith("/mm/") || uri.startsWith("/app/")) {
|
||||
return point.proceed();
|
||||
|
||||
}
|
||||
|
||||
args = recordRequestLog(point.getArgs(), uri);
|
||||
Signature sig = point.getSignature();
|
||||
Method method = ((MethodSignature) sig).getMethod();
|
||||
if (sig instanceof MethodSignature) {
|
||||
methodName = ((MethodSignature) sig).getMethod().getName();
|
||||
}
|
||||
|
||||
Class clazz = point.getTarget().getClass();
|
||||
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)
|
||||
.append("uri:").append(uri);
|
||||
|
||||
|
||||
// 默认对有的接口进行拦截
|
||||
Boolean intercept = faceAuthMap.get(className);
|
||||
Boolean classMethodConfigNotIntercept = faceAuthMap.get(classNameAndMethodName);
|
||||
|
||||
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, classMethodConfigNotIntercept);
|
||||
faceAuthTentMap.put(classNameAndMethodNametencent, tencent);
|
||||
log.info("LogAop one cache className:{},classNameAndMethodName:{},classNameAndMethodNametencent:{}", intercept, classMethodConfigNotIntercept, tencent);
|
||||
}
|
||||
if (classMethodConfigNotIntercept) {
|
||||
return point.proceed();
|
||||
}
|
||||
try {
|
||||
|
||||
|
||||
args = recordRequestLog(point.getArgs(), uri);
|
||||
Signature sig = point.getSignature();
|
||||
Method method = ((MethodSignature) sig).getMethod();
|
||||
if (sig instanceof MethodSignature) {
|
||||
methodName = ((MethodSignature) sig).getMethod().getName();
|
||||
}
|
||||
|
||||
Class clazz = point.getTarget().getClass();
|
||||
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)
|
||||
.append("uri:").append(uri);
|
||||
|
||||
|
||||
|
||||
// 默认对有的接口进行拦截
|
||||
Boolean intercept = faceAuthMap.get(className);
|
||||
Boolean classMethodConfigNotIntercept = faceAuthMap.get(classNameAndMethodName);
|
||||
|
||||
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, classMethodConfigNotIntercept);
|
||||
faceAuthTentMap.put(classNameAndMethodNametencent , tencent);
|
||||
log.info("LogAop one cache className:{},classNameAndMethodName:{},classNameAndMethodNametencent:{}", intercept, classMethodConfigNotIntercept, tencent);
|
||||
}
|
||||
|
||||
// 如果方法和类上都没有配置NotIntercept注解 ,则需要拦截 ,是linux才进行拦截
|
||||
if (intercept && classMethodConfigNotIntercept && OsUtil.isLinux()) {
|
||||
if (intercept && OsUtil.isLinux()) {
|
||||
String authConfig = request.getHeader("X-TCloudMarket-Custom-AuthConfig");
|
||||
if (StringUtils.isBlank(authConfig) || !authConfig.startsWith("{")) {
|
||||
log.info("LogAop authConfig value:{} auth error ", authConfig);
|
||||
@ -142,7 +142,7 @@ public class LogAop {
|
||||
String auth = faceAuthTentMap.get(classNameAndMethodNametencent);
|
||||
Object tAuth = authConfigMap.get(ApiConstants.t_auth);
|
||||
|
||||
if (StringUtils.isBlank(auth) || !auth.equals(tAuth+"")) {
|
||||
if (StringUtils.isBlank(auth) || !auth.equals(tAuth + "")) {
|
||||
log.info("LogAop authConfig:{},auth:{},tAuth:{} auth error ", authConfig, auth, tAuth);
|
||||
result = R.error("auth error");
|
||||
return result;
|
||||
@ -161,7 +161,7 @@ public class LogAop {
|
||||
|
||||
|
||||
public void printLog(Object result, String args, String ip, String className, String methodName,
|
||||
String preUri) {
|
||||
String preUri) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("LoggerAop args:").append(args).append(BLANK_SPACE)
|
||||
.append("ip:").append(ip).append(BLANK_SPACE)
|
||||
@ -172,9 +172,6 @@ public class LogAop {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String recordRequestLog(Object[] argArrs, String uri) {
|
||||
String mediaType = "";
|
||||
String args = null;
|
||||
@ -184,9 +181,9 @@ public class LogAop {
|
||||
for (Object arg1 : argArrs) {
|
||||
if (arg1 instanceof MultipartFile) {
|
||||
continue;
|
||||
}else if (arg1 instanceof HttpServletRequest) {
|
||||
} else if (arg1 instanceof HttpServletRequest) {
|
||||
continue;
|
||||
}else if (arg1 instanceof HttpServletResponse) {
|
||||
} else if (arg1 instanceof HttpServletResponse) {
|
||||
continue;
|
||||
} else if (arg1 instanceof MultipartFile[]) {
|
||||
continue;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.heyu.api.controller.vv;
|
||||
|
||||
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -10,11 +11,13 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@NotIntercept
|
||||
public class AppOssAuthController {
|
||||
|
||||
|
||||
// http://localhost:8888/auth
|
||||
@RequestMapping("/auth")
|
||||
public HttpServletResponse auth(HttpServletRequest request, HttpServletResponse response) {
|
||||
public int auth(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
|
||||
@ -22,7 +25,7 @@ public class AppOssAuthController {
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
return response;
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user