日志脱敏是数据实现常见的安全需求。普通的何优基于工具类方法的方式,对代码的脱敏入侵性太强,编写起来又特别麻烦。金融
sensitive[1] 提供了基于注解的用户雅地方式,并且内置了常见的敏感脱敏方式,便于开发。数据实现
为了金融交易的何优安全性,国家强制规定对于以下信息是脱敏要日志脱敏的:
<dependency> <groupId>com.github.houbb</groupId> <artifactId>sensitive-core</artifactId> <version>1.0.0</version></dependency>
SensitiveUtil 工具类的核心方法列表如下:
序号 | 方法 | 参数 | 结果 | 说明 |
1 | desCopy() | 目标对象 | 深度拷贝脱敏对象 | 适应性更强 |
2 | desJson() | 目标对象 | 脱敏对象 json | 性能较好 |
3 | desCopyCollection() | 目标对象集合 | 深度拷贝脱敏对象集合 | |
4 | desJsonCollection() | 目标对象集合 | 脱敏对象 json 集合 |
通过注解,指定每一个字段的脱敏策略。
public class UserAnnotationBean { @SensitiveStrategyChineseName private String username; @SensitiveStrategyPassword private String password; @SensitiveStrategyPassport private String passport; @SensitiveStrategyIdNo private String idNo; @SensitiveStrategyCardId private String bandCardId; @SensitiveStrategyPhone private String phone; @SensitiveStrategyEmail private String email; @SensitiveStrategyAddress private String address; @SensitiveStrategyBirthday private String birthday; @SensitiveStrategyGps private String gps; @SensitiveStrategyIp private String ip; @SensitiveStrategyMaskAll private String maskAll; @SensitiveStrategyMaskHalf private String maskHalf; @SensitiveStrategyMaskRange private String maskRange; //Getter & Setter //toString()}
构建一个最简单的测试对象:
UserAnnotationBean bean = new UserAnnotationBean();bean.setUsername("张三");bean.setPassword("123456");bean.setPassport("CN1234567");bean.setPhone("13066668888");bean.setAddress("中国上海市浦东新区外滩18号");bean.setEmail("whatanice@code.com");bean.setBirthday("20220831");bean.setGps("66.888888");bean.setIp("127.0.0.1");bean.setMaskAll("可恶啊我会被全部掩盖");bean.setMaskHalf("还好我只会被掩盖一半");bean.setMaskRange("我比较灵活指定掩盖范围");bean.setBandCardId("666123456789066");bean.setIdNo("360123202306018888");
final String originalStr = "UserAnnotationBean{ username='张三', password='123456', passport='CN1234567', idNo='360123202306018888', bandCardId='666123456789066', phone='13066668888', email='whatanice@code.com', address='中国上海市浦东新区外滩18号', birthday='20220831', gps='66.888888', ip='127.0.0.1', maskAll='可恶啊我会被全部掩盖', maskHalf='还好我只会被掩盖一半', maskRange='我比较灵活指定掩盖范围'}";final String sensitiveStr = "UserAnnotationBean{ username='张*', password='null', passport='CN*****67', idNo='3(责任编辑:知识)
东方国信(300166.SZ)公布消息:拟使用节余募集资金永久补充流动资金
EDC“城市快闪计划”空降苏州中心商场,与你一起享受纯粹快乐
微软澄清:暂时不会推出《我的世界》Xbox Series X
港铁公司(0066.HK)去年大幅亏损48.09亿港元 全年普通股息合共每股1.23港元