配置文件进行加密
This commit is contained in:
parent
a574cf292a
commit
f1c151f023
|
|
@ -51,7 +51,12 @@
|
|||
<groupId>com.bonus</groupId>
|
||||
<artifactId>bonus-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--加密依赖包-->
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -87,7 +87,12 @@
|
|||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--加密依赖包-->
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,7 @@ public class AuthFilter implements GlobalFilter, Ordered
|
|||
mutate.headers(httpHeaders -> httpHeaders.remove(name)).build();
|
||||
}
|
||||
|
||||
private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
|
||||
{
|
||||
private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
|
||||
log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED,jaData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
password: Encrypt
|
||||
|
|
|
|||
Loading…
Reference in New Issue