|
|
@@ -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
|
};
|