diff --git a/bonus-auth/pom.xml b/bonus-auth/pom.xml
index 0f71fb5..a7ac703 100644
--- a/bonus-auth/pom.xml
+++ b/bonus-auth/pom.xml
@@ -51,7 +51,12 @@
com.bonus
bonus-common-security
-
+
+
+ com.github.ulisesbocchio
+ jasypt-spring-boot-starter
+ 3.0.2
+
diff --git a/bonus-auth/src/main/resources/bootstrap.yml b/bonus-auth/src/main/resources/bootstrap.yml
index 991a503..d13c0f5 100644
--- a/bonus-auth/src/main/resources/bootstrap.yml
+++ b/bonus-auth/src/main/resources/bootstrap.yml
@@ -13,7 +13,7 @@ spring:
cloud:
nacos:
username: nacos
- password: Jjsp@nacos2023
+ password: ENC(b8K5x5rjN7qdGdmhgzFayK/P6ZVbC/UNBHjx2SBJkoqU149aXRtJsFhDZcgpckFf)
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
@@ -27,3 +27,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+#加密组件
+jasypt:
+ encryptor:
+ password: Encrypt
diff --git a/bonus-gateway/pom.xml b/bonus-gateway/pom.xml
index 8bf94e8..1c65e63 100644
--- a/bonus-gateway/pom.xml
+++ b/bonus-gateway/pom.xml
@@ -87,7 +87,12 @@
springfox-swagger2
${swagger.fox.version}
-
+
+
+ com.github.ulisesbocchio
+ jasypt-spring-boot-starter
+ 3.0.2
+
diff --git a/bonus-gateway/src/main/java/com/bonus/gateway/BonusGatewayApplication.java b/bonus-gateway/src/main/java/com/bonus/gateway/BonusGatewayApplication.java
index f993600..895d5b3 100644
--- a/bonus-gateway/src/main/java/com/bonus/gateway/BonusGatewayApplication.java
+++ b/bonus-gateway/src/main/java/com/bonus/gateway/BonusGatewayApplication.java
@@ -1,20 +1,41 @@
package com.bonus.gateway;
+import org.jasypt.encryption.StringEncryptor;
+import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import javax.annotation.Resource;
+
/**
* 网关启动程序
*
* @author bonus
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
-public class BonusGatewayApplication
-{
- public static void main(String[] args)
- {
+public class BonusGatewayApplication implements CommandLineRunner {
+ public static void main(String[] args) {
SpringApplication.run(BonusGatewayApplication.class, args);
System.err.println("博诺思网关启动成功\n");
}
+
+
+ @Resource
+ private StringEncryptor encryptor;
+ @Override
+ public void run(String... args) throws Exception {
+ String nacos = encrypt("Jjsp@nacos2023" );
+ String mogodb = encrypt("Bonus@admin123!" );
+ System.err.println( "nacos原始明文密码加密后的结果为:" + nacos );
+ System.err.println( "mogodb原始明文密码加密后的结果为:" + mogodb );
+ }
+
+ private String encrypt( String originPassord ) {
+ return encryptor.encrypt( originPassord );
+ }
+
+ private String decrypt( String encryptedPassword ) {
+ return encryptor.decrypt( encryptedPassword );
+ }
}
diff --git a/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java b/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java
index dfd00d5..cf7cfb8 100644
--- a/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java
+++ b/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java
@@ -120,8 +120,7 @@ public class AuthFilter implements GlobalFilter, Ordered
mutate.headers(httpHeaders -> httpHeaders.remove(name)).build();
}
- private Mono unauthorizedResponse(ServerWebExchange exchange, String msg)
- {
+ private Mono unauthorizedResponse(ServerWebExchange exchange, String msg) {
log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED,jaData);
}
diff --git a/bonus-gateway/src/main/resources/bootstrap.yml b/bonus-gateway/src/main/resources/bootstrap.yml
index 3bcc302..01e2386 100644
--- a/bonus-gateway/src/main/resources/bootstrap.yml
+++ b/bonus-gateway/src/main/resources/bootstrap.yml
@@ -14,7 +14,7 @@ spring:
cloud:
nacos:
username: nacos
- password: Jjsp@nacos2023
+ password: ENC(b8K5x5rjN7qdGdmhgzFayK/P6ZVbC/UNBHjx2SBJkoqU149aXRtJsFhDZcgpckFf)
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8848
@@ -53,4 +53,4 @@ system:
#加密组件
jasypt:
encryptor:
- password: Encrypt
\ No newline at end of file
+ password: Encrypt