|
@@ -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 权限拦截
|
|
|
+
|
|
|
+ }
|
|
|
+}
|