Просмотр исходного кода

网关服务-修改外部鉴权过滤器

sunxbiao 1 год назад
Родитель
Сommit
1d8ca4d027

+ 14 - 14
gateWay_server/src/main/java/com/bjtdba/gateWay/filter/ApiAuthFilter.java

@@ -40,22 +40,22 @@ public class ApiAuthFilter extends AbstractGatewayFilterFactory<ApiAuthFilter.Co
40 40
             }
41 41
 
42 42
             // 3. 验证时间戳有效性
43
-//            try {
44
-//                long requestTime = Long.parseLong(timestamp);
45
-//                long currentTime = System.currentTimeMillis();
46
-//
47
-//                if (Math.abs(currentTime - requestTime) > TIMESTAMP_THRESHOLD) {
48
-//                    return unauthorized(exchange, "Timestamp expired");
49
-//                }
50
-//            } catch (NumberFormatException e) {
51
-//                return unauthorized(exchange, "Invalid timestamp format");
52
-//            }
43
+            try {
44
+                long requestTime = Long.parseLong(timestamp);
45
+                long currentTime = System.currentTimeMillis();
46
+
47
+                if (Math.abs(currentTime - requestTime) > TIMESTAMP_THRESHOLD) {
48
+                    return unauthorized(exchange, "Timestamp expired");
49
+                }
50
+            } catch (NumberFormatException e) {
51
+                return unauthorized(exchange, "Invalid timestamp format");
52
+            }
53 53
 
54 54
             // 4. 生成并验证签名
55
-//            String expectedSignature = generateSignature(apiKey, timestamp);
56
-//            if (!expectedSignature.equalsIgnoreCase(signature)) {
57
-//                return unauthorized(exchange, "Invalid signature");
58
-//            }
55
+            String expectedSignature = generateSignature(apiKey, timestamp);
56
+            if (!expectedSignature.equalsIgnoreCase(signature)) {
57
+                return unauthorized(exchange, "Invalid signature");
58
+            }
59 59
             System.out.println("Forwarding to: " + exchange.getRequest().getURI());
60 60
             return chain.filter(exchange);
61 61
         };

+ 1 - 1
gateWay_server/src/main/resources/application.yml

@@ -1,5 +1,5 @@
1 1
 server:
2
-  port: 9002
2
+  port: 9000
3 3
 spring:
4 4
   application:
5 5
     name: gateWay-server