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

View File

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

View File

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

View File

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