This commit is contained in:
Jesse-Ma
2022-12-09 14:15:14 +08:00
parent 862d47d76f
commit 3a2e7dc2d6
4 changed files with 40 additions and 24 deletions

View File

@@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<version>2.7.6</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.flagnote</groupId>
@@ -14,7 +14,7 @@
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.3</spring-cloud.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
@@ -56,6 +56,10 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>

View File

@@ -28,6 +28,7 @@ public class ValidateNoteCipherFilter implements GatewayFilter, Ordered {
String requestBody = exchange.getAttribute(ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR);
JSONObject body = JSONUtil.parseObj(requestBody);
String cipher = body.getStr("cipher");
String initTime = body.getStr("initTime");
String key = body.getStr("key");
if (!noteKey.equals(key)) {
@@ -35,7 +36,7 @@ public class ValidateNoteCipherFilter implements GatewayFilter, Ordered {
return exchange.getResponse().setComplete();
}
if (!BizKeyUtils.validateCipher(noteKey, cipher)) {
if (!BizKeyUtils.validateCipher(noteKey,initTime, cipher)) {
exchange.getResponse().setStatusCode(HttpStatus.BAD_REQUEST);
return exchange.getResponse().setComplete();
}

View File

@@ -84,12 +84,12 @@ public class BizKeyUtils {
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
}
public static String getCipher(String key) {
return md5(key + MIX_STRING + key);
public static String getCipher(String key,String initTime) {
return md5(key +"#"+ MIX_STRING + "#" + initTime);
}
public static Boolean validateCipher(String key,String cipher) {
return md5(key + MIX_STRING + key).equals(cipher);
public static Boolean validateCipher(String key,String initTime,String cipher) {
return md5(key +"#"+ MIX_STRING + "#" + initTime).equals(cipher);
}

View File

@@ -1,5 +1,6 @@
server:
port: 55555
address: 127.0.0.1
port: 10000
spring:
codec:
max-in-memory-size: 100MB
@@ -24,17 +25,16 @@ spring:
client:
simple:
instances:
keyMetaService: # 一定要带端口
- uri: http://localhost:3333
# - uri: http://flagnote.com:3333
noteService: # 一定要带端口
- uri: http://127.0.0.1:20000
# - uri: http://94.103.5.10:20001
loadbalancer:
configurations: health-check
health-check:
# path:
# noteKey: /getHealth
initial-delay: 0 #运行状况检查计划程序的初始延迟值。
interval: 5s # 重新运行运行状况检查计划程序的时间间隔。
configurations: health-check #启用预定义的负载平衡器配置。
path:
noteService: /f2w8u47ie56edc93/actuator/health
initial-delay: 0
interval: 5s
inetutils:
# 指定此客户端的ip
default-ip-address: localhost
@@ -46,7 +46,7 @@ spring:
# allowedMethods: "*"
routes:
- id: keyMeta
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/keyMeta
@@ -84,7 +84,7 @@ spring:
- id: noteMeta
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/noteMeta
@@ -92,7 +92,7 @@ spring:
filters:
- ValidateNoteKey
- id: getNote
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}
@@ -100,7 +100,7 @@ spring:
filters:
- ValidateNoteKey
- id: saveNote
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}
@@ -108,7 +108,7 @@ spring:
filters:
- ValidateNoteKey
- id: deleteNote
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/delete
@@ -116,7 +116,7 @@ spring:
filters:
- ValidateNoteKey
- id: secretKey
uri: lb://keyMetaService
uri: lb://noteService
order: -1
predicates:
- Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/secretKey
@@ -128,12 +128,23 @@ spring:
management:
# server:
# address: 127.0.0.1
# port: 19000
endpoint:
shutdown:
enabled: true
health:
enabled: true
show-details: always
endpoints:
web:
base-path: /f2w8u47ie56edc93/actuator
exposure:
include: shutdown,health
logging:
level:
org.springframework.cloud.gateway: trace
org.springframework.cloud.loadbalancer: trace
# org.springframework.cloud.loadbalancer: trace
# org.springframework.web.reactive: trace