Skip to content

Commit e5420fe

Browse files
author
zhifu.xin
committed
配置、以及敏感字段脱敏
1 parent 4f6480b commit e5420fe

File tree

6 files changed

+43
-40
lines changed

6 files changed

+43
-40
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.xiaofu.annotation;
22

33
import java.lang.annotation.*;
4-
54
@Documented
65
@Target({ElementType.FIELD,ElementType.PARAMETER})
76
@Retention(RetentionPolicy.RUNTIME)
@@ -10,3 +9,4 @@
109
String[] value() default "";
1110
}
1211

12+

springboot-jasypt/src/main/java/com/xiaofu/aspect/EncryptHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ public void pointCut() {
3131

3232
@Around("pointCut()")
3333
public Object around(ProceedingJoinPoint joinPoint) {
34-
3534
/**
3635
* 加密
3736
*/
3837
encrypt(joinPoint);
39-
4038
/**
4139
* 解密
4240
*/
4341
Object decrypt = decrypt(joinPoint);
44-
4542
return decrypt;
4643
}
4744

springboot-jasypt/src/main/java/com/xiaofu/controller/Encryptor.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import com.alibaba.fastjson.JSON;
44
import com.xiaofu.annotation.EncryptField;
55
import com.xiaofu.annotation.EncryptMethod;
6-
import com.xiaofu.model.UserDto;
7-
import com.xiaofu.model.UserVo;
6+
import lombok.Data;
87
import lombok.extern.slf4j.Slf4j;
98
import org.jasypt.encryption.StringEncryptor;
109
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.web.bind.annotation.*;
1211

12+
import java.io.Serializable;
13+
1314
@Slf4j
1415
@RestController
1516
@RequestMapping("/encryptor/")
@@ -18,6 +19,11 @@ public class Encryptor {
1819
@Autowired
1920
private StringEncryptor stringEncryptor;
2021

22+
public void encrypt(String content) {
23+
String encryptStr = stringEncryptor.encrypt("xiaofu");
24+
System.out.println("加密后的内容:" + encryptStr);
25+
}
26+
2127
@EncryptMethod
2228
@PostMapping(value = "test")
2329
@ResponseBody
@@ -28,7 +34,20 @@ public Object testEncrypt(@RequestBody UserVo user, @EncryptField String name) {
2834

2935
private UserVo insertUser(UserVo user, String name) {
3036
System.out.println("加密后的数据:user" + JSON.toJSONString(user));
31-
System.out.println("加密后的数据:name" + name);
3237
return user;
3338
}
39+
40+
@Data
41+
public class UserVo implements Serializable {
42+
43+
private Long userId;
44+
45+
@EncryptField
46+
private String mobile;
47+
48+
@EncryptField
49+
private String address;
50+
51+
private String age;
52+
}
3453
}

springboot-jasypt/src/main/java/com/xiaofu/model/UserDto.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

springboot-jasypt/src/main/java/com/xiaofu/model/UserVo.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
* @Date: 2021/7/26 15:10
1111
* @Description:
1212
*/
13-
@Data
14-
public class UserVo implements Serializable {
15-
16-
private Long userId;
17-
18-
@EncryptField
19-
private String mobile;
20-
21-
@EncryptField
22-
private String address;
23-
24-
private String age;
25-
}
13+
//@Data
14+
//public class UserVo implements Serializable {
15+
//
16+
// private Long userId;
17+
//
18+
// @EncryptField
19+
// private String mobile;
20+
//
21+
// @EncryptField
22+
// private String address;
23+
//
24+
// private String age;
25+
//}

springboot-jasypt/src/main/resources/application.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# \u7AEF\u53E3\u53F7
22
server:
33
port: 9000
4+
5+
spring:
6+
datasource:
7+
url: jdbc:mysql://1.2.3.4:3306/xiaofu?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
8+
username: xiaofu
9+
password: ENC(mVTvp4IddqdaYGqPl9lCQbzM3H/b0B6l)
10+
411
# \u79D8\u94A5
512
jasypt:
613
encryptor:

0 commit comments

Comments
 (0)