Commit ab8918f48b80e7d02ce092df472c4af5e3866927
Merge branch 'desensitization' into develop
Showing
18 changed files
with
749 additions
and
4 deletions
huaheng-wms-core/pom.xml
... | ... | @@ -188,6 +188,11 @@ |
188 | 188 | <classifier>sources</classifier> |
189 | 189 | <type>java-source</type> |
190 | 190 | </dependency> |
191 | + <dependency> | |
192 | + <groupId>org.reflections</groupId> | |
193 | + <artifactId>reflections</artifactId> | |
194 | + <version>0.9.10</version> | |
195 | + </dependency> | |
191 | 196 | </dependencies> |
192 | 197 | |
193 | 198 | <build> |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/annotation/SensitiveField.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.annotation; | |
2 | + | |
3 | + | |
4 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
5 | + | |
6 | +import java.lang.annotation.*; | |
7 | + | |
8 | +/** | |
9 | + * 对需要脱敏的字段加上该注解 | |
10 | + * | |
11 | + * @author xub | |
12 | + * @date 2022/6/1 下午2:08 | |
13 | + */ | |
14 | +@Documented | |
15 | +@Inherited | |
16 | +@Retention(RetentionPolicy.RUNTIME) | |
17 | +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) | |
18 | +public @interface SensitiveField { | |
19 | + | |
20 | + /** | |
21 | + * 脱敏类型 | |
22 | + */ | |
23 | + SensitiveTypeEnums value(); | |
24 | + | |
25 | + /** | |
26 | + * 填充值 | |
27 | + */ | |
28 | + String fillValue() default "*"; | |
29 | + | |
30 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/enums/SensitiveTypeEnums.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.enums; | |
2 | + | |
3 | +/** | |
4 | + * 脱敏类型 | |
5 | + * | |
6 | + * @author xub | |
7 | + * @date 2022/6/1 上午1:09 | |
8 | + */ | |
9 | +public enum SensitiveTypeEnums { | |
10 | + | |
11 | + /** | |
12 | + * 默认方式脱敏 | |
13 | + */ | |
14 | + DEFAULT(0,6), | |
15 | + | |
16 | + /** | |
17 | + * 中文名称 | |
18 | + */ | |
19 | + CHINESE_NAME(1,1), | |
20 | + | |
21 | + /** | |
22 | + * 手机号 | |
23 | + */ | |
24 | + MOBILE(3,4), | |
25 | + | |
26 | + /** | |
27 | + * 座机号码 | |
28 | + */ | |
29 | + FIXED_PHONE(0,4), | |
30 | + | |
31 | + /** | |
32 | + * 银行卡 | |
33 | + */ | |
34 | + BANK_CARD(6,4), | |
35 | + | |
36 | + /** | |
37 | + * 身份证号 | |
38 | + */ | |
39 | + ID_CARD(0,4), | |
40 | + | |
41 | + /** | |
42 | + * 邮箱 | |
43 | + */ | |
44 | + EMAIL(2,0), | |
45 | + | |
46 | + /** | |
47 | + * 地址 | |
48 | + */ | |
49 | + ADDRESS(6,4), | |
50 | + | |
51 | + ; | |
52 | + | |
53 | + SensitiveTypeEnums(int begin, int end){ | |
54 | + this.begin = begin; | |
55 | + this.end = end; | |
56 | + }; | |
57 | + | |
58 | + /** | |
59 | + * 开始长度 | |
60 | + */ | |
61 | + private int begin; | |
62 | + | |
63 | + /** | |
64 | + * 结束长度 | |
65 | + */ | |
66 | + private int end; | |
67 | + | |
68 | + public int getBegin() { | |
69 | + return begin; | |
70 | + } | |
71 | + | |
72 | + public int getEnd() { | |
73 | + return end; | |
74 | + } | |
75 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.plugin; | |
2 | + | |
3 | + | |
4 | +import cn.hutool.core.util.ObjectUtil; | |
5 | +import org.apache.ibatis.executor.resultset.ResultSetHandler; | |
6 | +import org.apache.ibatis.plugin.*; | |
7 | +import org.apache.shiro.SecurityUtils; | |
8 | +import org.jeecg.common.exception.JeecgBootException; | |
9 | +import org.jeecg.modules.desensitization.annotation.SensitiveField; | |
10 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
11 | +import org.jeecg.modules.desensitization.strategy.SensitiveContext; | |
12 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
13 | +import org.jeecg.modules.system.entity.SysUserRole; | |
14 | +import org.jeecg.modules.system.service.ISysRoleService; | |
15 | +import org.jeecg.utils.HuahengJwtUtil; | |
16 | +import org.reflections.ReflectionUtils; | |
17 | +import org.slf4j.Logger; | |
18 | +import org.slf4j.LoggerFactory; | |
19 | +import org.springframework.core.annotation.Order; | |
20 | +import org.springframework.stereotype.Service; | |
21 | +import org.springframework.util.CollectionUtils; | |
22 | + | |
23 | +import javax.annotation.Resource; | |
24 | +import javax.servlet.http.HttpServletRequest; | |
25 | +import java.lang.reflect.Field; | |
26 | +import java.util.*; | |
27 | +import java.util.concurrent.ConcurrentHashMap; | |
28 | + | |
29 | +import static org.jeecg.utils.HuahengJwtUtil.getRolesByToken; | |
30 | + | |
31 | + | |
32 | +/** | |
33 | + * 基于拦截器对数据脱敏 | |
34 | + * | |
35 | + * @author xub | |
36 | + * @date 2022/6/2 下午2:23 | |
37 | + */ | |
38 | +@Intercepts({ | |
39 | + @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {java.sql.Statement.class}) | |
40 | +}) | |
41 | +@Service | |
42 | +@Order(-1) | |
43 | +public class DesensitizationInterceptor implements Interceptor { | |
44 | + | |
45 | + | |
46 | + private static final Logger log = LoggerFactory.getLogger(DesensitizationInterceptor.class); | |
47 | + | |
48 | + /** | |
49 | + * key值为class对象 value可以理解成是该类带有SensitiveField注解的属性,只不过对属性封装了一层。 | |
50 | + * 它是非常能够提高性能的处理器 它的作用就是不用每一次一个对象经来都要看下它的哪些属性带有SensitiveField注解 | |
51 | + * 毕竟类的反射在性能上并不友好。只要key包含该对象那就不需要检查它哪些属性带SensitiveField注解。 | |
52 | + */ | |
53 | + private Map<Class, List<Handler>> handlerMap = new ConcurrentHashMap<>(); | |
54 | + | |
55 | + @Override | |
56 | + public Object intercept(Invocation invocation) throws Throwable { | |
57 | + // 获取结果 | |
58 | + List<Object> results = (List<Object>) invocation.proceed(); | |
59 | + if (CollectionUtils.isEmpty(results)) { | |
60 | + return results; | |
61 | + } | |
62 | + // 批量设置加密 | |
63 | + for (Object object : results) { | |
64 | + process(object); | |
65 | + } | |
66 | + return results; | |
67 | + } | |
68 | + | |
69 | + | |
70 | + private void process(Object object) throws Throwable { | |
71 | + if(ObjectUtil.isNotEmpty(object)){ | |
72 | + Class handlerKey = object.getClass(); | |
73 | + List<Handler> handlerList = handlerMap.get(handlerKey); | |
74 | + //性能优化点,如果有两个都是user对象同时,那么只需有个进行反射处理属性就好了,另一个只需执行下面的for循环 | |
75 | + SYNC: | |
76 | + if (handlerList == null) { | |
77 | + synchronized (this) { | |
78 | + handlerList = handlerMap.get(handlerKey); | |
79 | + //如果到这里map集合已经存在,则跳出到指定SYNC标签 | |
80 | + if (handlerList != null) { | |
81 | + break SYNC; | |
82 | + } | |
83 | + handlerMap.put(handlerKey, handlerList = new ArrayList<>()); | |
84 | + // 反射工具类 获取带有SensitiveField注解的所有属性字段 | |
85 | + Set<Field> allFields = ReflectionUtils.getAllFields( | |
86 | + object.getClass(), | |
87 | + input -> input != null && input.getAnnotation(SensitiveField.class) != null | |
88 | + ); | |
89 | + | |
90 | + for (Field field : allFields) { | |
91 | + handlerList.add(new Handler(field)); | |
92 | + } | |
93 | + } | |
94 | + } | |
95 | + for (Handler handler : handlerList) { | |
96 | + handler.accept(object); | |
97 | + } | |
98 | + } | |
99 | + | |
100 | + } | |
101 | + | |
102 | + | |
103 | + @Override | |
104 | + public Object plugin(Object target) { | |
105 | + return Plugin.wrap(target, this); | |
106 | + } | |
107 | + | |
108 | + @Override | |
109 | + public void setProperties(Properties properties) { | |
110 | + } | |
111 | + | |
112 | + | |
113 | + private static class Handler { | |
114 | + Field field; | |
115 | + | |
116 | + Handler(Field field) { | |
117 | + this.field = field; | |
118 | + } | |
119 | + | |
120 | + private boolean checkField(Object object, Field field) throws IllegalAccessException { | |
121 | + if (!field.isAccessible()) { | |
122 | + field.setAccessible(true); | |
123 | + } | |
124 | + //如果为空 那么就不用进行脱敏操作了 | |
125 | + return field.get(object) != null; | |
126 | + } | |
127 | + | |
128 | + public void accept(Object o) throws Throwable { | |
129 | + if (checkField(o, field)) { | |
130 | + SensitiveField annotation = field.getAnnotation(SensitiveField.class); | |
131 | + SensitiveTypeEnums typeEnums = annotation.value(); | |
132 | + String fillValue = annotation.fillValue(); | |
133 | + Object o1 = field.get(o); | |
134 | + if(!SecurityUtils.getSubject().hasRole("desensitization")){ | |
135 | + SensitiveStrategy sensitiveStrategy = SensitiveContext.get(typeEnums); | |
136 | + String s = sensitiveStrategy.handle(o1, fillValue); | |
137 | + field.set(o, s); | |
138 | + } | |
139 | + } | |
140 | + } | |
141 | + } | |
142 | + | |
143 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/SensitiveContext.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy; | |
2 | + | |
3 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
4 | +import org.jeecg.modules.desensitization.strategy.impl.*; | |
5 | +import org.springframework.stereotype.Component; | |
6 | +import org.springframework.util.Assert; | |
7 | + | |
8 | +import java.util.Map; | |
9 | +import java.util.concurrent.ConcurrentHashMap; | |
10 | + | |
11 | +/** | |
12 | + * 获取所有策略 | |
13 | + * | |
14 | + * @author xub | |
15 | + * @date 2022/6/2 下午2:13 | |
16 | + */ | |
17 | +@Component | |
18 | +public class SensitiveContext { | |
19 | + | |
20 | + private static final Map<SensitiveTypeEnums,SensitiveStrategy> map = new ConcurrentHashMap<>(); | |
21 | + | |
22 | + static { | |
23 | + map.put(SensitiveTypeEnums.DEFAULT,new DefaultStrategyHandle()); | |
24 | + map.put(SensitiveTypeEnums.CHINESE_NAME,new NameStrategyHandle()); | |
25 | + map.put(SensitiveTypeEnums.MOBILE,new MobileStrategyHandle()); | |
26 | + map.put(SensitiveTypeEnums.FIXED_PHONE,new FixedPhoneStrategyHandle()); | |
27 | + map.put(SensitiveTypeEnums.BANK_CARD,new BankCardStrategyHandle()); | |
28 | + map.put(SensitiveTypeEnums.ID_CARD,new IdCardStrategyHandle()); | |
29 | + map.put(SensitiveTypeEnums.EMAIL,new EmailStrategyHandle()); | |
30 | + map.put(SensitiveTypeEnums.ADDRESS,new AddressStrategyHandle()); | |
31 | + } | |
32 | + | |
33 | + | |
34 | + public static SensitiveStrategy get(SensitiveTypeEnums sensitiveType){ | |
35 | + | |
36 | + SensitiveStrategy sensitiveStrategy = map.get(sensitiveType); | |
37 | + Assert.notNull(sensitiveStrategy,"sensitiveStrategy no found!"); | |
38 | + return sensitiveStrategy; | |
39 | + } | |
40 | + | |
41 | + | |
42 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/SensitiveStrategy.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy; | |
2 | + | |
3 | + | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | + | |
7 | +/** | |
8 | + * 脱敏策略 | |
9 | + * | |
10 | + * @author xub | |
11 | + * @date 2021/12/2 上午10:22 | |
12 | + */ | |
13 | +public interface SensitiveStrategy { | |
14 | + | |
15 | + | |
16 | + /** | |
17 | + * 具体脱敏类型 | |
18 | + */ | |
19 | + SensitiveTypeEnums getType(); | |
20 | + | |
21 | + /** | |
22 | + * 默认处理具体脱敏方法,如果特色子类 由子类实现 | |
23 | + * | |
24 | + * @param object 具体需要脱敏字段 | |
25 | + * @param fillValue 填充值 默认* | |
26 | + * @return 已经脱敏后的数据 | |
27 | + */ | |
28 | + String handle(Object object, String fillValue); | |
29 | + | |
30 | + | |
31 | +//===========================接口默认方法,把实现类公共部分抽离出来========================================================== | |
32 | + | |
33 | + /** | |
34 | + * 中间填充的脱敏数据 比如手机号、银行卡、座机等等 | |
35 | + * | |
36 | + * @param value 具体需要脱敏字段 | |
37 | + * @param fillValue 填充值 默认* | |
38 | + * @return 已经脱敏后的数据 | |
39 | + */ | |
40 | + default String centerFill(String value, String fillValue) { | |
41 | + | |
42 | + SensitiveTypeEnums typeEnums = this.getType(); | |
43 | + int begin = typeEnums.getBegin(); | |
44 | + int end = typeEnums.getEnd(); | |
45 | + int length = StringUtils.length(value); | |
46 | + | |
47 | + //这里以手机为列子 说明下是如何做到中间填充的。其它的比如银行卡,身份证号等等都是一个道理 | |
48 | + //这里一共做了4步: | |
49 | + //1、获取左边值:StringUtils.left(mobile, begin) 13312345678获取133 | |
50 | + //2、获取右边值:StringUtils.right(mobile, end) 13312345678获取5678 | |
51 | + //3、填充将5678左填充变为 ***5678 | |
52 | + //4、在合并1,3就变成 133133***5678 | |
53 | + return StringUtils.left(value, begin) | |
54 | + .concat(StringUtils.leftPad(StringUtils.right(value, end), length - begin, fillValue)); | |
55 | + | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * 右边填充的脱敏数据 比如身份证号、座机号、地址等等 | |
60 | + * | |
61 | + * @param value 具体需要脱敏字段 | |
62 | + * @param fillValue 填充值 默认* | |
63 | + * @return 已经脱敏后的数据 | |
64 | + */ | |
65 | + default String rightFill(String value, String fillValue) { | |
66 | + | |
67 | + SensitiveTypeEnums typeEnums = this.getType(); | |
68 | + int end = typeEnums.getEnd(); | |
69 | + int length = StringUtils.length(value); | |
70 | + | |
71 | + //这里以身份证为示例 说明下是如何做到中间填充的 | |
72 | + //这里一共做了2步: | |
73 | + //1、获取左边值:StringUtils.left(value, end) 330127199911114444获取33012719991111 | |
74 | + //2、填充将33012719991111左填充变为 33012719991111**** | |
75 | + return StringUtils.rightPad(StringUtils.left(value, length - end), length, fillValue); | |
76 | + } | |
77 | + | |
78 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/AddressStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | + | |
9 | +/** | |
10 | + * 地址填充: 宁波市慈溪市观海卫镇禹皇路999号鸣鹤古镇 转为 宁波市慈溪市***********鸣鹤古镇 | |
11 | + * | |
12 | + * @author xub | |
13 | + * @date 2022/6/2 上午9:16 | |
14 | + */ | |
15 | +public class AddressStrategyHandle implements SensitiveStrategy { | |
16 | + | |
17 | + @Override | |
18 | + public SensitiveTypeEnums getType() { | |
19 | + return SensitiveTypeEnums.ADDRESS; | |
20 | + } | |
21 | + | |
22 | + @Override | |
23 | + public String handle(Object object, String fillValue) { | |
24 | + if (object == null) { | |
25 | + return null; | |
26 | + } | |
27 | + //字段原始值 | |
28 | + String value = object.toString(); | |
29 | + SensitiveTypeEnums type = getType(); | |
30 | + int begin = type.getBegin(); | |
31 | + int end = type.getEnd(); | |
32 | + int length = StringUtils.length(value); | |
33 | + //如果开始+结束 < 地址总长度 那就可以中间填充 | |
34 | + if (end + begin < length) { | |
35 | + return this.centerFill(value, fillValue); | |
36 | + } | |
37 | + | |
38 | + //如果开始+结束 > 地址总长度 同时 结束 < 地址总长度 那么右边填充 | |
39 | + if (end + begin < length && end < length) { | |
40 | + return this.rightFill(value, fillValue); | |
41 | + } | |
42 | + return value; | |
43 | + } | |
44 | + | |
45 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/BankCardStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | +import java.util.regex.Pattern; | |
9 | + | |
10 | +/** | |
11 | + * 银行卡脱敏: 6228477477865321转为622847******5321 | |
12 | + * | |
13 | + * @author xub | |
14 | + * @date 2022/6/2 上午9:16 | |
15 | + */ | |
16 | +public class BankCardStrategyHandle implements SensitiveStrategy { | |
17 | + | |
18 | + /** | |
19 | + * 银行卡卡号位数匹配 | |
20 | + */ | |
21 | + public final static String BANK_CARD_NUMBER = "^\\d{16}|\\d{19}$"; | |
22 | + | |
23 | + @Override | |
24 | + public SensitiveTypeEnums getType() { | |
25 | + return SensitiveTypeEnums.BANK_CARD; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public String handle(Object object, String fillValue) { | |
30 | + if (object == null) { | |
31 | + return null; | |
32 | + } | |
33 | + //字段原始值 | |
34 | + String value = object.toString(); | |
35 | + //如果银行卡不符合格式 直接返回 不进行脱敏 | |
36 | + if (!Pattern.matches(BANK_CARD_NUMBER, value)) { | |
37 | + return value; | |
38 | + } | |
39 | + //填充银行卡卡号 | |
40 | + return this.centerFill(value, fillValue); | |
41 | + } | |
42 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/DefaultStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | +import org.apache.commons.lang3.StringUtils; | |
4 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
5 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
6 | + | |
7 | +/** | |
8 | + * 默认脱敏方式 | |
9 | + * | |
10 | + * @author xub | |
11 | + * @date 2022/6/2 上午9:16 | |
12 | + */ | |
13 | +public class DefaultStrategyHandle implements SensitiveStrategy { | |
14 | + | |
15 | + | |
16 | + @Override | |
17 | + public SensitiveTypeEnums getType() { | |
18 | + return SensitiveTypeEnums.DEFAULT; | |
19 | + } | |
20 | + | |
21 | + @Override | |
22 | + public String handle(Object object, String fillValue) { | |
23 | + if (object == null) { | |
24 | + return null; | |
25 | + } | |
26 | + //字段原始值 | |
27 | + String value = object.toString(); | |
28 | + SensitiveTypeEnums type = getType(); | |
29 | + int end = type.getEnd(); | |
30 | + int length = StringUtils.length(value); | |
31 | + if (end < length) { | |
32 | + return this.rightFill(value, fillValue); | |
33 | + } | |
34 | + return value; | |
35 | + } | |
36 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/EmailStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | +import java.util.regex.Pattern; | |
9 | + | |
10 | + | |
11 | +/** | |
12 | + * 邮箱脱敏 邮箱脱敏比较特殊。一般我们说455555@qq.com 那我们会在@之前几位进行脱敏 45****@qq.com | |
13 | + * | |
14 | + * @author xub | |
15 | + * @date 2022/6/2 上午10:31 | |
16 | + */ | |
17 | +public class EmailStrategyHandle implements SensitiveStrategy { | |
18 | + | |
19 | + | |
20 | + /** | |
21 | + * 邮箱email | |
22 | + */ | |
23 | + public static final String EMAIL_REG = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; | |
24 | + | |
25 | + @Override | |
26 | + public SensitiveTypeEnums getType() { | |
27 | + return SensitiveTypeEnums.EMAIL; | |
28 | + } | |
29 | + | |
30 | + @Override | |
31 | + public String handle(Object object, String fillValue) { | |
32 | + if (object == null) { | |
33 | + return null; | |
34 | + } | |
35 | + //字段原始值 | |
36 | + String value = object.toString(); | |
37 | + //如果不符合格式 直接返回 不进行脱敏 | |
38 | + if (!Pattern.matches(EMAIL_REG, value)) { | |
39 | + return value; | |
40 | + } | |
41 | + //以 455555@qq.com 示例 | |
42 | + int length = StringUtils.length(value); | |
43 | + //获取@位置 | |
44 | + int indexOf = StringUtils.indexOf(value, "@"); | |
45 | + //获取455555 部分 | |
46 | + String left = StringUtils.left(value, indexOf); | |
47 | + //获取@qq.com部分 这部分数据是不用处理的 后面在拼接回来就好了 | |
48 | + String right = StringUtils.right(value, length - indexOf); | |
49 | + | |
50 | + int leftLength = StringUtils.length(left); | |
51 | + //45@qq.com 直接返回 **@qq.com | |
52 | + if (leftLength <= 2) { | |
53 | + return StringUtils.leftPad(right, length, fillValue); | |
54 | + } | |
55 | + //如果leftLength大于2 | |
56 | + String leftFill = this.centerFill(left, fillValue); | |
57 | + //做好拼接 | |
58 | + return leftFill.concat(right); | |
59 | + } | |
60 | + | |
61 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/FixedPhoneStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | +import java.util.regex.Pattern; | |
9 | + | |
10 | +/** | |
11 | + * 座机电话号脱敏 0211-8711882转为0211-871**** | |
12 | + * | |
13 | + * @author xub | |
14 | + * @date 2022/6/2 上午9:16 | |
15 | + */ | |
16 | +public class FixedPhoneStrategyHandle implements SensitiveStrategy { | |
17 | + | |
18 | + /** | |
19 | + * 身份证号码位数限制 匹配形式如 0511-4405222 或 021-87888822 | |
20 | + */ | |
21 | + public final static String FIXED_PHONE = "^\\d{3}-\\d{7,8}|\\d{4}-\\d{7,8}$"; | |
22 | + | |
23 | + @Override | |
24 | + public SensitiveTypeEnums getType() { | |
25 | + return SensitiveTypeEnums.FIXED_PHONE; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public String handle(Object object, String fillValue) { | |
30 | + if (object == null) { | |
31 | + return null; | |
32 | + } | |
33 | + //字段原始值 | |
34 | + String value = object.toString(); | |
35 | + //如果座机不符合格式 直接返回 不进行脱敏 | |
36 | + if (!Pattern.matches(FIXED_PHONE, value)) { | |
37 | + return value; | |
38 | + } | |
39 | + //座机脱敏 | |
40 | + return this.rightFill(value, fillValue); | |
41 | + } | |
42 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/IdCardStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | +import java.util.regex.Pattern; | |
9 | + | |
10 | +/** | |
11 | + * 身份证号脱敏 330127199911114444转为330127199911114444**** | |
12 | + * | |
13 | + * @author xub | |
14 | + * @date 2022/6/2 上午9:16 | |
15 | + */ | |
16 | +public class IdCardStrategyHandle implements SensitiveStrategy { | |
17 | + | |
18 | + /** | |
19 | + * 身份证号码位数限制 | |
20 | + */ | |
21 | + public final static String ID_CARD = "^\\d{15}|(\\d{17}[0-9,x,X])$"; | |
22 | + | |
23 | + @Override | |
24 | + public SensitiveTypeEnums getType() { | |
25 | + return SensitiveTypeEnums.ID_CARD; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public String handle(Object object, String fillValue) { | |
30 | + if (object == null) { | |
31 | + return null; | |
32 | + } | |
33 | + //字段原始值 | |
34 | + String value = object.toString(); | |
35 | + //如果身份证号不符合格式 直接返回 不进行脱敏 | |
36 | + if (!Pattern.matches(ID_CARD, value)) { | |
37 | + return value; | |
38 | + } | |
39 | + //身份证号脱敏 | |
40 | + return this.rightFill(value, fillValue); | |
41 | + } | |
42 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/MobileStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | +import java.util.regex.Pattern; | |
9 | + | |
10 | +/** | |
11 | + * 手机号码脱敏 13312345678转为133****5678 | |
12 | + * | |
13 | + * @author xub | |
14 | + * @date 2022/6/2 上午9:16 | |
15 | + */ | |
16 | +public class MobileStrategyHandle implements SensitiveStrategy { | |
17 | + | |
18 | + | |
19 | + /** | |
20 | + * 手机号码匹配 | |
21 | + */ | |
22 | + public static final String PHONE_REG = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"; | |
23 | + | |
24 | + @Override | |
25 | + public SensitiveTypeEnums getType() { | |
26 | + return SensitiveTypeEnums.MOBILE; | |
27 | + } | |
28 | + | |
29 | + @Override | |
30 | + public String handle(Object object, String fillValue) { | |
31 | + if (object == null) { | |
32 | + return null; | |
33 | + } | |
34 | + //字段原始值 | |
35 | + String mobile = object.toString(); | |
36 | + //如果手机号不符合手机格式 直接返回 不进行脱敏 | |
37 | + if (!Pattern.matches(PHONE_REG, mobile)) { | |
38 | + return mobile; | |
39 | + } | |
40 | + | |
41 | + //填充手机号 | |
42 | + return this.centerFill(mobile, fillValue); | |
43 | + } | |
44 | + | |
45 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/strategy/impl/NameStrategyHandle.java
0 → 100644
1 | +package org.jeecg.modules.desensitization.strategy.impl; | |
2 | + | |
3 | + | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
6 | +import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; | |
7 | + | |
8 | + | |
9 | +/** | |
10 | + * 中文名称脱敏 这个比较特殊。张三 转 张*,李世民->李*民,司徒伯雷->司**雷 | |
11 | + * | |
12 | + * @author xub | |
13 | + * @date 2022/6/2 上午10:31 | |
14 | + */ | |
15 | +public class NameStrategyHandle implements SensitiveStrategy { | |
16 | + | |
17 | + @Override | |
18 | + public SensitiveTypeEnums getType() { | |
19 | + return SensitiveTypeEnums.CHINESE_NAME; | |
20 | + } | |
21 | + | |
22 | + @Override | |
23 | + public String handle(Object object, String fillValue) { | |
24 | + if (object == null) { | |
25 | + return null; | |
26 | + } | |
27 | + //字段原始值 | |
28 | + String value = object.toString(); | |
29 | + int length = StringUtils.length(value); | |
30 | + //如果为2 则说明为右边填充 | |
31 | + if (length == 2) { | |
32 | + return this.rightFill(value, fillValue); | |
33 | + } | |
34 | + //如果大于2 则说明为中间填充 | |
35 | + if (length > 2) { | |
36 | + return this.centerFill(value, fillValue); | |
37 | + } | |
38 | + //如果只有一个子那就直接返回 | |
39 | + return value; | |
40 | + } | |
41 | + | |
42 | +} | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
... | ... | @@ -154,7 +154,7 @@ public class SysUserController { |
154 | 154 | userIds.add(u.getId().toString()); |
155 | 155 | } |
156 | 156 | |
157 | - if (userIds != null && userIds.size() > 0) { | |
157 | + if (!userIds.isEmpty()) { | |
158 | 158 | Map<String, String> useDepNames = sysUserService.getDepNamesByUserIds(userIds); |
159 | 159 | pageList.getRecords().forEach(item -> { |
160 | 160 | item.setOrgCodeTxt(useDepNames.get(item.getId().toString())); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/entity/SysUser.java
... | ... | @@ -6,6 +6,8 @@ import java.util.Date; |
6 | 6 | import java.util.List; |
7 | 7 | |
8 | 8 | import org.jeecg.common.aspect.annotation.Dict; |
9 | +import org.jeecg.modules.desensitization.annotation.SensitiveField; | |
10 | +import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; | |
9 | 11 | import org.jeecgframework.poi.excel.annotation.Excel; |
10 | 12 | import org.springframework.format.annotation.DateTimeFormat; |
11 | 13 | import org.springframework.util.StringUtils; |
... | ... | @@ -45,12 +47,14 @@ public class SysUser implements Serializable { |
45 | 47 | * 登录账号 |
46 | 48 | */ |
47 | 49 | @Excel(name = "登录账号", width = 15) |
50 | +// @SensitiveField(SensitiveTypeEnums.CHINESE_NAME) | |
48 | 51 | private String username; |
49 | 52 | |
50 | 53 | /** |
51 | 54 | * 真实姓名 |
52 | 55 | */ |
53 | 56 | @Excel(name = "真实姓名", width = 15) |
57 | + @SensitiveField(SensitiveTypeEnums.CHINESE_NAME) | |
54 | 58 | private String realname; |
55 | 59 | |
56 | 60 | /** |
... | ... | @@ -96,6 +100,7 @@ public class SysUser implements Serializable { |
96 | 100 | * 电话 |
97 | 101 | */ |
98 | 102 | @Excel(name = "电话", width = 15) |
103 | + @SensitiveField(SensitiveTypeEnums.MOBILE) | |
99 | 104 | private String phone; |
100 | 105 | |
101 | 106 | /** |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java
huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java
... | ... | @@ -3,14 +3,20 @@ package org.jeecg.modules.system.service.impl; |
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Arrays; |
5 | 5 | import java.util.List; |
6 | +import java.util.concurrent.atomic.AtomicReference; | |
6 | 7 | |
8 | +import cn.hutool.core.util.ObjectUtil; | |
7 | 9 | import org.jeecg.common.api.vo.Result; |
8 | 10 | import org.jeecg.common.constant.CommonConstant; |
9 | 11 | import org.jeecg.common.util.ImportExcelUtil; |
10 | 12 | import org.jeecg.modules.system.entity.SysRole; |
13 | +import org.jeecg.modules.system.entity.SysUser; | |
14 | +import org.jeecg.modules.system.entity.SysUserRole; | |
11 | 15 | import org.jeecg.modules.system.mapper.SysRoleMapper; |
12 | 16 | import org.jeecg.modules.system.mapper.SysUserMapper; |
13 | 17 | import org.jeecg.modules.system.service.ISysRoleService; |
18 | +import org.jeecg.modules.system.service.ISysUserRoleService; | |
19 | +import org.jeecg.modules.system.service.ISysUserService; | |
14 | 20 | import org.jeecgframework.poi.excel.ExcelImportUtil; |
15 | 21 | import org.jeecgframework.poi.excel.entity.ImportParams; |
16 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -22,6 +28,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
22 | 28 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
23 | 29 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
24 | 30 | |
31 | +import javax.annotation.Resource; | |
32 | + | |
25 | 33 | /** |
26 | 34 | * <p> |
27 | 35 | * 角色表 服务实现类 |
... | ... | @@ -36,6 +44,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl |
36 | 44 | @Autowired |
37 | 45 | SysUserMapper sysUserMapper; |
38 | 46 | |
47 | + @Resource | |
48 | + private ISysUserRoleService iSysUserRoleService; | |
49 | + | |
50 | + @Resource | |
51 | + private ISysUserService iSysUserService; | |
52 | + | |
39 | 53 | @Override |
40 | 54 | public Result importExcelCheckRoleCode(MultipartFile file, ImportParams params) throws Exception { |
41 | 55 | List<Object> listSysRoles = ExcelImportUtil.importExcel(file.getInputStream(), SysRole.class, params); |
... | ... | @@ -92,7 +106,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl |
92 | 106 | public SysRole getRoleByName(String roleName) { |
93 | 107 | LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = Wrappers.lambdaQuery(); |
94 | 108 | roleLambdaQueryWrapper.eq(SysRole::getRoleName, roleName); |
95 | - SysRole role = getOne(roleLambdaQueryWrapper); | |
96 | - return role; | |
109 | + return getOne(roleLambdaQueryWrapper); | |
97 | 110 | } |
98 | 111 | } |
... | ... |