From 3a2e7dc2d6348a2a76d34589a355c715f62094fa Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Fri, 9 Dec 2022 14:15:14 +0800 Subject: [PATCH] cipher --- pom.xml | 8 +++- .../filter/ValidateNoteCipherFilter.java | 3 +- .../flagnote/gateway/utils/BizKeyUtils.java | 8 ++-- src/main/resources/application.yml | 45 ++++++++++++------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index f360b36..a187785 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.0 + 2.7.6 com.flagnote @@ -14,7 +14,7 @@ Demo project for Spring Boot 11 - 2021.0.3 + 2021.0.5 @@ -56,6 +56,10 @@ reactor-test test + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/src/main/java/com/flagnote/gateway/filter/ValidateNoteCipherFilter.java b/src/main/java/com/flagnote/gateway/filter/ValidateNoteCipherFilter.java index 6afc18a..9c126cd 100644 --- a/src/main/java/com/flagnote/gateway/filter/ValidateNoteCipherFilter.java +++ b/src/main/java/com/flagnote/gateway/filter/ValidateNoteCipherFilter.java @@ -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(); } diff --git a/src/main/java/com/flagnote/gateway/utils/BizKeyUtils.java b/src/main/java/com/flagnote/gateway/utils/BizKeyUtils.java index 30ac618..119a22b 100644 --- a/src/main/java/com/flagnote/gateway/utils/BizKeyUtils.java +++ b/src/main/java/com/flagnote/gateway/utils/BizKeyUtils.java @@ -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); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 704d28d..e9b3f87 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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 \ No newline at end of file