Skip to content

Commit b28477a

Browse files
committed
加密配置文件中的敏感信息
1 parent e440510 commit b28477a

File tree

8 files changed

+15
-50
lines changed

8 files changed

+15
-50
lines changed

2.x/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
### 配置文件
2626

2727
- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/)
28+
- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/)
2829
- [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/)
2930
- [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/)
30-
- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/)
31+
- [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/)
3132

3233
### API开发
3334

2.x/README_zh.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
### 配置文件
2727

2828
- [Spring Boot 2.x基础教程:配置文件详解](http://blog.didispace.com/spring-boot-learning-21-1-3/)
29+
- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/)
2930
- [Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化](http://blog.didispace.com/spring-boot-learning-24-1-4/)
3031
- [Spring Boot 2.x基础教程:2.4版本前后的分组配置变化](http://blog.didispace.com/spring-boot-learning-24-1-5/)
31-
- [Spring Boot 2.x基础教程:配置元数据的应用 ](http://blog.didispace.com/spring-boot-learning-24-1-6/)
32+
- [Spring Boot 2.x基础教程:加密配置中的敏感信息](http://blog.didispace.com/spring-boot-learning-2-1-5/)
3233

3334
### API开发
3435

2.x/chapter1-5/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>com.didispace</groupId>
1212
<artifactId>chapter1-5</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<description>敏感配置信息的加密</description>
14+
<description>加密配置中的敏感信息</description>
1515

1616
<properties>
1717
<java.version>1.8</java.version>
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
11
package com.didispace.chapter15;
22

3-
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
4-
import org.springframework.beans.factory.annotation.Autowired;
53
import org.springframework.boot.SpringApplication;
64
import org.springframework.boot.autoconfigure.SpringBootApplication;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.RestController;
95

106
@SpringBootApplication
11-
@EnableEncryptableProperties
127
public class Chapter15Application {
138

149
public static void main(String[] args) {
1510
SpringApplication.run(Chapter15Application.class, args);
1611
}
1712

18-
@RestController
19-
static class HelloController {
20-
21-
@Autowired
22-
private JasyptExample jasyptExample;
23-
24-
@GetMapping("/hello")
25-
public String hello() {
26-
return "Hello World, " + jasyptExample.getFrom2();
27-
}
28-
29-
}
30-
3113
}

2.x/chapter1-5/src/main/java/com/didispace/chapter15/JasyptExample.java

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

2-
com.didispace.from1=didi
3-
com.didispace.from2=ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds)
2+
datasource.password=ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q)
43

54
jasypt.encryptor.password=didispace
65

7-
#[INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator
8-
#[INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator
9-
106
# mvn jasypt:encrypt -Djasypt.encryptor.password=didispace
11-
# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
7+
# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
8+
9+
#jasypt.encryptor.property.prefix=ENC(
10+
#jasypt.encryptor.property.suffix=)

2.x/chapter1-5/src/test/java/com/didispace/chapter15/PropertiesTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.junit.jupiter.api.Test;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.boot.test.context.SpringBootTest;
78

89
@Slf4j
910
@SpringBootTest
1011
public class PropertiesTest {
1112

12-
@Autowired
13-
private JasyptExample jasyptExample;
13+
@Value("${datasource.password:}")
14+
private String password;
1415

1516
@Test
1617
public void test() {
17-
log.info("from1 : {}", jasyptExample.getFrom1());
18-
log.info("from2 : {}", jasyptExample.getFrom2());
18+
log.info("datasource.password : {}", password);
1919
}
2020

2121
}

2.x/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<module>chapter1-2</module> <!-- 2.4版本前后的多环境配置与配置激活 -->
1717
<module>chapter1-3</module> <!-- 2.4版本前后的配置分组配置 -->
1818
<module>chapter1-4</module> <!-- 配置元数据的应用 -->
19-
<module>chapter1-5</module> <!-- 敏感配置信息的加密 -->
19+
<module>chapter1-5</module> <!-- 加密配置文件中的敏感信息 -->
2020

2121
<!--API开发-->
2222
<module>chapter2-1</module> <!-- 构建RESTful API与单元测试 -->

0 commit comments

Comments
 (0)