honwhy / common-data-masking

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

common-data-masking

WIP do not use in production

Data masking util based on Fastjson ValueFilter and Jackson SimpleBeanPropertyFilter, and use RewritePolicy for masking sensitive message of log4j2

usage

for POJOs within project

  • when use Fastjson, annotated with @Mask annotations on fields
@AllArgsConstructor
@Data
public class AnyDTO {
    @MaskCarNo
    private String val1;
    @MaskMobile
    private String val2;

}
  • use util
String json = MaskUtil.toJSONString(dto);
  • when use Jackson, annotated with @Mask annotations on fields, and @JsonFilter("MaskAny") on class level
@AllArgsConstructor
@Data
@JsonFilter("MaskAny")
public class AnyDTO {
    @MaskCarNo
    private String val1;
    @MaskMobile
    private String val2;

}
  • use util
String json = MaskJackUtil.writeValueAsString(dto);

for POJOs outside project

  • example
package com.thh3;

@AllArgsConstructor
@Data
public class SimpleDTO {
    private String val1;
    private String val2;
}
  • properties configuration
com.thh3.SimpleDTO#val1=MaskCarNo
com.thh3.SimpleDTO#val2=MaskMobile
  • use util
String json = MaskSettingUtil.toJSONString(dto);

for Map type

  • composite your own util
public class MaskMapUtil {

    public static String toJSONString(Object object) {
        return JSON.toJSONString(object, new ValueFilter[]{
                new KeyMapValueFilter("carNo", new CarNoValueFilter()),
                new KeyMapValueFilter("mobile", new MobileValueFilter())
        });
    }
}
  • use util
Map<String, Object> dto = new HashMap<>();
dto.put("carNo", "粤B-D23456");
dto.put("mobile", "13700137000");
String json = MaskMapUtil.toJSONString(dto);

idea

img

documents

About


Languages

Language:Java 100.0%