Browse Source

token拦截

吴洪双 5 năm trước cách đây
mục cha
commit
1568a1f8d6

+ 4 - 6
pom.xml

@@ -34,12 +34,6 @@
 	</properties>
 
 	<dependencies>
-		<!-- paytm支付 -->
-<!--		<dependency>-->
-<!--			<groupId>myjar</groupId>-->
-<!--			<artifactId>PaytmChecksum</artifactId>-->
-<!--			<version>1.1</version>-->
-<!--		</dependency>-->
 		<!-- Spring Component End -->
 		<dependency>
 			<groupId>org.json</groupId>
@@ -137,6 +131,10 @@
 			<artifactId>springfox-swagger-ui</artifactId>
 			<version>2.8.0</version>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-aop</artifactId>
+		</dependency>
 	</dependencies>
 	
 	<build>

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

@@ -0,0 +1,53 @@
+package com.shawn.monitor;
+
+import com.shawn.web.exception.MyException;
+import lombok.extern.apachecommons.CommonsLog;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.StopWatch;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+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.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;
+
+/**
+ * @author 吴洪双
+ */
+@CommonsLog
+@Aspect
+@Component
+public class PerformanceMonitor {
+
+    /**
+     * 所有请求,
+     * 排除了登录
+     * 排除微信TWeixinController 的所有方法
+     */
+    @Pointcut("execution(public * com.shawn.web.controller..*(..)) && !execution(public * com.shawn.web.controller.TAdminController.userLogin(..)) && !execution(public * com.shawn.web.controller.TWeixinController.*(..))")
+    private void allCell() {
+    }
+    @Before("allCell()")
+    public void setDataSourceKey(JoinPoint point) {
+        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
+        HttpServletRequest request = servletRequestAttributes.getRequest();
+        String token = null!=request.getHeader("token")?request.getHeader("token"):"";
+        boolean isLogin = true;
+        if(StringUtils.isEmpty(token)){
+            // TODO 做token的逻辑判断
+            isLogin = false;
+        }
+        if(!isLogin){
+            throw new MyException("请登录");
+        }
+    }
+
+}

+ 3 - 3
src/main/java/com/shawn/util/PushUtils.java

@@ -176,7 +176,7 @@ public class PushUtils {
         return jsonObject;
     }
 
-    public static void main(String[] args) {
-        push("71963777bd63e0f0a5b6490f04bf1ae4", "niai", "123", buildJson("editNo", "123456789").toString());
-    }
+//    public static void main(String[] args) {
+//        push("71963777bd63e0f0a5b6490f04bf1ae4", "niai", "123", buildJson("editNo", "123456789").toString());
+//    }
 }