springboot脱敏控件升级,支持深度脱敏

藏宝库编辑 2024-9-20 12:59:33 87 0 来自 中国
\
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阐明:
属性默认值取值范围阐明enabletruetrue/false是否启用脱敏,全局见效,默认开启depthfalsetrue/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; }示例代码下载地点
\
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-11-21 20:48, Processed in 0.113914 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表