gaodm пре 4 година
родитељ
комит
c8a991564f

+ 19 - 0
src/main/java/com/diagbot/annotation/TokenAuth.java

@@ -0,0 +1,19 @@
+package com.diagbot.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @Description: 需要二次Token验证注解
+ * @author: gaodm
+ * @time: 2020/7/29 9:23
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface TokenAuth {
+    String value() default "";
+}

+ 61 - 0
src/main/java/com/diagbot/aop/TokenAuthAspect.java

@@ -0,0 +1,61 @@
+package com.diagbot.aop;
+
+import com.diagbot.annotation.SysLoggerExport;
+import com.diagbot.annotation.TokenAuth;
+import com.diagbot.biz.log.entity.SysLog;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
+import com.diagbot.util.StringUtil;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/7/29 9:25
+ */
+@Aspect
+@Component
+@ConditionalOnProperty(prefix = "tokenAuth", value = { "enable" }, havingValue = "true")
+public class TokenAuthAspect {
+
+    //切所有Controller
+    @Pointcut("execution(* com.diagbot.web..*.*(..))")
+    public void pointcutController() {
+    }
+
+    @Before("pointcutController()")
+    public void permissionIntercept(JoinPoint joinPoint) {
+        //确定是否有TokenAuth注解
+        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+        Method method = signature.getMethod();
+
+        TokenAuth tokenAuth = method.getAnnotation(TokenAuth.class);
+        if (tokenAuth == null) {
+            return;
+        }
+        //有TokenAuth注解情况下
+        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
+        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
+        HttpServletRequest request = sra.getRequest();
+        //head里面是否有hospitalCode;
+        String token = request.getHeader("token");
+        if (StringUtil.isBlank(token)) {
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请传入token!");
+        }
+        //todo 期限和医院有效性验证
+        //todo 权限拦截
+
+    }
+}

+ 5 - 0
src/main/java/com/diagbot/config/SwaggerConfigurer.java

@@ -41,6 +41,11 @@ public class SwaggerConfigurer {
                 .modelRef(new ModelRef("string"))
                 .parameterType("header")
                 .required(false).build());
+        params.add(new ParameterBuilder().name("token")
+                .description("Authorization token")
+                .modelRef(new ModelRef("string"))
+                .parameterType("header")
+                .required(false).build());
         return params;
     }
 

+ 2 - 0
src/main/java/com/diagbot/web/MrqcController.java

@@ -1,6 +1,7 @@
 package com.diagbot.web;
 
 import com.diagbot.annotation.SysLogger;
+import com.diagbot.annotation.TokenAuth;
 import com.diagbot.dto.AnalyzeRunDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.MrqcFacade;
@@ -39,6 +40,7 @@ public class MrqcController {
                     "    String isPlacefile;")
     @PostMapping("/analyze_run")
     @SysLogger("analyze_run")
+    @TokenAuth
     public RespDTO<AnalyzeRunDTO> analyzeRun(@Valid @RequestBody AnalyzeRunVO analyzeRunVO) {
         return RespDTO.onSuc(mrqcFacade.analyzeRun(analyzeRunVO));
     }

+ 4 - 0
src/main/resources/application-dev.yml

@@ -165,6 +165,10 @@ oath.self.address: http://${myhost}:${server.port}
 swagger:
   enable: true
 
+#Token鉴权
+tokenAuth:
+  enable: true
+
 #病历质控地址
 mrqc:
   url: http://192.168.2.236:5858

+ 4 - 0
src/main/resources/application-local.yml

@@ -165,6 +165,10 @@ oath.self.address: http://${myhost}:${server.port}
 swagger:
   enable: true
 
+#Token鉴权
+tokenAuth:
+  enable: true
+
 #病历质控地址
 mrqc:
   url: http://192.168.2.236:5858

+ 4 - 0
src/main/resources/application-pre.yml

@@ -165,6 +165,10 @@ oath.self.address: http://${myhost}:${server.port}
 swagger:
   enable: true
 
+#Token鉴权
+tokenAuth:
+  enable: true
+
 #病历质控地址
 mrqc:
   url: http://192.168.2.121:5858

+ 4 - 0
src/main/resources/application-pro.yml

@@ -165,6 +165,10 @@ oath.self.address: http://${myhost}:${server.port}
 swagger:
   enable: true
 
+#Token鉴权
+tokenAuth:
+  enable: true
+
 #病历质控地址
 mrqc:
   url: http://192.168.2.122:5858

+ 4 - 0
src/main/resources/application-test.yml

@@ -165,6 +165,10 @@ oath.self.address: http://${myhost}:${server.port}
 swagger:
   enable: true
 
+#Token鉴权
+tokenAuth:
+  enable: true
+
 #病历质控地址
 mrqc:
   url: http://192.168.2.241:5858