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 SubEntities,SensitiveSubEntity中又包含了SensitiveGrandSonEntity,基本可以满足我们大多数场景。

     @Desensitization
     public Page page() {
         Page page = new Page();
         page.setCurrent(1);
         page.setSize(10);
         List list = new ArrayList();
         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 subEntities = new ArrayList();
         for (int j=0;j<3;j++){
             SensitiveSubEntity sensitiveSubEntity = new SensitiveSubEntity();
             sensitiveSubEntity.setAddress("addr--->"+j);
 
             SensitiveGrandSonEntity grandSonEntity = new SensitiveGrandSonEntity();
             grandSonEntity.setEmail("[email protected]");
             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 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;
 }

示例代码下载地址

/

版权声明:
作者:cc
链接:https://www.techfm.club/p/47174.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>