\
secure-ext-spring-boot-starter自發(fā)布以來受到廣大童鞋的關(guān)注,也收到各位同行朋友好的建議與需求芳撒,主要是常規(guī)情況下我們可能根據(jù)各自項目需求,列表頁會返回Page對象未桥,Page中包含records(List類型)笔刹,records又包含實際的Entity,因此大多數(shù)情況下返回的會是復(fù)雜對象冬耿。因此經(jīng)過幾天的優(yōu)化調(diào)整舌菜,重新發(fā)布升級版,本次主要升級內(nèi)容:
1. 支持自動化配置亦镶;
2. 支持深度脫敏日月,支持復(fù)雜對象,嵌套對象缤骨,對象內(nèi)多層級嵌套爱咬,自動尋找返回值中嵌套對象包含的需脫敏的屬性;
最新版本
最新發(fā)布版已更新到mave中央倉庫:[Maven Central][1.0.3-release]
主要配置
sensitive:
enable: true
depth: false
packages: com.mos.secure
說明:
屬性 | 默認(rèn)值 | 取值范圍 | 說明 |
---|---|---|---|
enable | true | true/false | 是否啟用脫敏绊起,全局生效精拟,默認(rèn)開啟 |
depth | false | true/false | 是否啟用深度脫敏,為了性能考慮虱歪,默認(rèn)關(guān)閉 |
packages | 空 | 字符串 | 包路徑蜂绎,多個以英文逗號分隔 |
深度脫敏規(guī)則:
depth為true,且packages不為空笋鄙,當(dāng)方法返回值嵌套的屬性包含在packages下师枣,則自動進行脫敏。
示例
代碼略長萧落,大致如下:方法返回Page践美,Page中的Records為List,List中存放實體類SensitiveEntity找岖,SensitiveEntity又包含List<SensitiveSubEntity> SubEntities陨倡,SensitiveSubEntity中又包含了SensitiveGrandSonEntity,基本可以滿足我們大多數(shù)場景宣增。
@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;
}
\