springboot脱敏控件升级支持深度脱敏
作者:小尘哥
这篇文章主要为大家介绍了springboot脱敏控件升级支持深度脱敏,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
正文
secure-ext-spring-boot-starter自发布以来受到广大童鞋的关注,也收到各位同行朋友好的建议与需求,主要是常规情况下我们可能根据各自项目需求,列表页会返回Page对象,Page中包含records(List类型),records又包含实际的Entity,因此大多数情况下返回的会是复杂对象。
因此经过几天的优化调整,重新发布升级版,本次主要升级内容:
1. 支持自动化配置;
2. 支持深度脱敏,支持复杂对象,嵌套对象,对象内多层级嵌套,自动寻找返回值中嵌套对象包含的需脱敏的属性;
最新版本
最新发布版已更新到mave中央仓库:[Maven Central][1.0.3-release]
主要配置
sensitive: enable: true depth: false packages: com.mos.secure
说明:
属性 | 默认值 | 取值范围 | 说明 |
---|---|---|---|
enable | true | true/false | 是否启用脱敏,全局生效,默认开启 |
depth | false | true/false | 是否启用深度脱敏,为了性能考虑,默认关闭 |
packages | 空 | 字符串 | 包路径,多个以英文逗号分隔 |
深度脱敏规则:
depth为true,且packages不为空,当方法返回值嵌套的属性包含在packages下,则自动进行脱敏。
示例
代码略长,大致如下:方法返回Page,Page中的Records为List,List中存放实体类SensitiveEntity,SensitiveEntity又包含List<SensitiveSubEntity> SubEntities,SensitiveSubEntity中又包含了SensitiveGrandSonEntity,基本可以满足我们大多数场景。
@Desensitization public Page page() { Page page = new Page(); page.setCurrent(1); page.setSize(10); List<SensitiveEntity> list = new ArrayList<SensitiveEntity>(); for (int i = 0; i < 5; i++) { SensitiveEntity sensitiveEntity = createEntity("1" + i, "樱木花道" + i, "15699996666" + i, "10101020000101000" + i); list.add(sensitiveEntity); } page.setRecords(list); return page; } private static SensitiveEntity createEntity(String i, String i1, String i2, String i3) { SensitiveEntity sensitiveEntity = new SensitiveEntity(); sensitiveEntity.setId(i); sensitiveEntity.setName(i1); sensitiveEntity.setMobile(i2); sensitiveEntity.setIdCard(i3); List<SensitiveSubEntity> subEntities = new ArrayList<SensitiveSubEntity>(); for (int j=0;j<3;j++){ SensitiveSubEntity sensitiveSubEntity = new SensitiveSubEntity(); sensitiveSubEntity.setAddress("addr--->"+j); SensitiveGrandSonEntity grandSonEntity = new SensitiveGrandSonEntity(); grandSonEntity.setEmail("grq100296@163.com"); sensitiveSubEntity.setSensitiveGrandSonEntity(grandSonEntity); subEntities.add(sensitiveSubEntity); } sensitiveEntity.setSubEntities(subEntities); return sensitiveEntity; }
SensitiveEntity
@Data public class SensitiveEntity { private String id; @DesensitizationProp(value = SensitiveTypeEnum.CUSTOM,preLength = 1,sufLength = 5) private String name; @DesensitizationProp(SensitiveTypeEnum.MOBILE_PHONE) private String mobile; @DesensitizationProp(SensitiveTypeEnum.ID_CARD) private String idCard; private List<SensitiveSubEntity> subEntities; }
SensitiveSubEntity
@Data public class SensitiveSubEntity { @DesensitizationProp(SensitiveTypeEnum.ADDRESS) private String address; private SensitiveGrandSonEntity sensitiveGrandSonEntity; }
SensitiveGrandSonEntity
@Data public class SensitiveGrandSonEntity { @DesensitizationProp(value = SensitiveTypeEnum.EMAIL) private String email; }
以上就是springboot脱敏控件升级支持深度脱敏的详细内容,更多关于springboot脱敏控件的资料请关注脚本之家其它相关文章!