李天标 5 роки тому
батько
коміт
36682b949a
2 змінених файлів з 24 додано та 0 видалено
  1. 5 0
      pom.xml
  2. 19 0
      src/main/java/com/shawn/monitor/PerformanceMonitor.java

+ 5 - 0
pom.xml

@@ -34,6 +34,11 @@
 	</properties>
 
 	<dependencies>
+		<dependency>
+			<groupId>io.jsonwebtoken</groupId>
+			<artifactId>jjwt</artifactId>
+			<version>0.7.0</version>
+		</dependency>
 		<!-- Spring Component End -->
 		<dependency>
 			<groupId>org.json</groupId>

+ 19 - 0
src/main/java/com/shawn/monitor/PerformanceMonitor.java

@@ -1,5 +1,9 @@
 package com.shawn.monitor;
 
+import com.shawn.model.dto.ResultMessage;
+import com.shawn.model.entity.TAdmin;
+import com.shawn.service.interfac.TAdminServiceInterface;
+import com.shawn.util.JavaWebToken;
 import com.shawn.web.exception.MyException;
 import lombok.extern.apachecommons.CommonsLog;
 import org.apache.commons.lang3.StringUtils;
@@ -11,12 +15,14 @@ import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.beans.factory.annotation.Autowired;
 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.util.Map;
 
 /**
  * @author 吴洪双
@@ -26,6 +32,8 @@ import javax.servlet.http.HttpServletRequest;
 @Component
 public class PerformanceMonitor {
 
+    @Autowired
+    private TAdminServiceInterface tAdminService;
     /**
      * 所有请求,
      * 排除了登录
@@ -44,10 +52,21 @@ public class PerformanceMonitor {
         if(StringUtils.isEmpty(token)){
             // TODO 做token的逻辑判断
             isLogin = false;
+        }else{
+            Map<String, Object> map = JavaWebToken.parserJavaWebToken(token);
+            Object userId = map.get("userId");
+            Long id = Long.valueOf(String.valueOf(userId));
+            TAdmin admin = tAdminService.selectEntityById(id);
+            if(admin!=null){
+                isLogin = true;
+            }else {
+                isLogin = false;
+            }
         }
         if(!isLogin){
             throw new MyException("请登录");
         }
+//        throw new MyException("请登录");
     }
 
 }