脱敏保留源数据格式;
代码规范
Showing
| ... | @@ -17,6 +17,17 @@ public class MaskUtil implements Serializable { | ... | @@ -17,6 +17,17 @@ public class MaskUtil implements Serializable { |
| public static final int DEFAULT_MAP_CAPACITY = 16; | public static final int DEFAULT_MAP_CAPACITY = 16; | ||
| /** | |||
| * 数据格式信息 | |||
| */ | |||
| //todo 抽取到配置文件 | |||
|
|
|||
| private List<String> dataFormats = new ArrayList<String>(){{ | |||
|
|
|||
| add(","); | |||
| add("."); | |||
| add("@"); | |||
| add("-"); | |||
| }}; | |||
| /** | /** | ||
| * 姓名正则 | * 姓名正则 | ||
| */ | */ | ||
| ... | @@ -88,7 +99,6 @@ public class MaskUtil implements Serializable { | ... | @@ -88,7 +99,6 @@ public class MaskUtil implements Serializable { |
| patterns.add(Pattern.compile(this.macRegExp)); | patterns.add(Pattern.compile(this.macRegExp)); | ||
| patterns.add(Pattern.compile(this.emailRegExp)); | patterns.add(Pattern.compile(this.emailRegExp)); | ||
| patterns.add(Pattern.compile(this.ipRegExp)); | patterns.add(Pattern.compile(this.ipRegExp)); | ||
| patterns.add(Pattern.compile(this.nameRegExp)); | |||
| patterns.add(Pattern.compile(this.idRegExp18)); | patterns.add(Pattern.compile(this.idRegExp18)); | ||
| patterns.add(Pattern.compile(this.idRegExp15)); | patterns.add(Pattern.compile(this.idRegExp15)); | ||
| patterns.add(Pattern.compile(this.bankCardRegExp)); | patterns.add(Pattern.compile(this.bankCardRegExp)); | ||
| ... | @@ -104,9 +114,15 @@ public class MaskUtil implements Serializable { | ... | @@ -104,9 +114,15 @@ public class MaskUtil implements Serializable { |
| if (matcher.find()) { | if (matcher.find()) { | ||
| String replaceStr = ""; | String replaceStr = ""; | ||
| for (int i = 0; i < matcher.group().length(); i++) { | for (int i = 0; i < matcher.group().length(); i++) { | ||
| replaceStr = replaceStr.concat("*"); | String s = String.valueOf(matcher.group().charAt(i)); | ||
| if(dataFormats.contains(s)){ | |||
| replaceStr = replaceStr.concat(s); | |||
| }else{ | |||
| replaceStr = replaceStr.concat("*"); | |||
| } | |||
| } | } | ||
| value = value.replace(matcher.group(), replaceStr); | value = value.replace(matcher.group(), replaceStr); | ||
| System.out.println("\n"); | |||
|
|||
| } | } | ||
| } | } | ||
| map.put(k, value); | map.put(k, value); | ||
| ... | @@ -118,15 +134,20 @@ public class MaskUtil implements Serializable { | ... | @@ -118,15 +134,20 @@ public class MaskUtil implements Serializable { |
| } | } | ||
| public static void main(String[] args) { | public static void main(String[] args) { | ||
| MaskUtil maskUtil = new MaskUtil("[\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\\\.\\\\s]{1,20}", "((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}", | MaskUtil maskUtil = new MaskUtil("[\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\\\.\\\\s]{1,20}", | ||
| "(\\d{3,4}-)?\\d{6,8}", "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", "[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}", | "((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}", | ||
| "[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])", "([1-9]{1})(\\d{11}|\\d{15}|\\d{16}|\\d{17}|\\d{18})", | "0\\d{2,3}-\\d{7,8}", | ||
| "([\u4E00-\u9FA5A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}", "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)", | "[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+", | ||
| "[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}", | |||
| "[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])", | |||
| "([1-9]{1})(\\d{11}|\\d{15}|\\d{16}|\\d{17}|\\d{18})", | |||
| "([\u4E00-\u9FA5A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}", | |||
| "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)", | |||
| "([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"); | "([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"); | ||
| Map map = new HashMap(DEFAULT_MAP_CAPACITY); | Map map = new HashMap(DEFAULT_MAP_CAPACITY); | ||
| map.put("姓名", "王海鹰"); | map.put("姓名", "王海鹰"); | ||
| map.put("身份证号", "372925199008075158"); | map.put("身份证号", "372925199101195158"); | ||
| map.put("手机号", "15000101879"); | map.put("手机号", "15000101879"); | ||
| map.put("电话", "021-61341606"); | map.put("电话", "021-61341606"); | ||
| map.put("邮箱", "wanghaiying@zork.com"); | map.put("邮箱", "wanghaiying@zork.com"); | ||
| ... | @@ -137,6 +158,7 @@ public class MaskUtil implements Serializable { | ... | @@ -137,6 +158,7 @@ public class MaskUtil implements Serializable { |
| map.put("message", "王海鹰,372925199008075158#15000101879"); | map.put("message", "王海鹰,372925199008075158#15000101879"); | ||
| map.put("messid", "0000011404342B32233DDCDA"); | map.put("messid", "0000011404342B32233DDCDA"); | ||
| map.put("bsflag", "0000011404342B32233DDCDA"); | map.put("bsflag", "0000011404342B32233DDCDA"); | ||
| map.put("test", "wanghaiying123"); | |||
| map.put("normalFields", "13811110000-110101199003075517-上海市浦东新区张江微电子港-zorkdata@163.com-123456789-wanghaiying123-王海鹰-192.168.1.1-00-50-56-C0-00-08-6227002470170278192"); | map.put("normalFields", "13811110000-110101199003075517-上海市浦东新区张江微电子港-zorkdata@163.com-123456789-wanghaiying123-王海鹰-192.168.1.1-00-50-56-C0-00-08-6227002470170278192"); | ||
| String[] fieldsWhiteListArray = "messid,fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc".split(","); | String[] fieldsWhiteListArray = "messid,fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc".split(","); | ||
| ... | ... | ||
-
SonarQube analysis reported 153 issues
-
🚫 20 critical -
⚠ 82 major -
🔽 49 minor -
ℹ 2 info
Watch the comments in this conversation to review them.
Top 30 extra issues
Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:
-
🚫 Move constants to a class or enum.📘 -
🚫 Move constants to a class or enum.📘 -
🚫 Move constants to a class or enum.📘 -
🚫 Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.📘 -
🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.)📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
🚫 Make "patterns" private or transient.📘 -
🚫 Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.📘 -
🚫 Define a constant instead of duplicating this literal "序列化失败" 15 times.📘 -
🚫 Define a constant instead of duplicating this literal " {\n" 7 times.📘 -
🚫 [Define a constant instead of duplicating this literal " "type": \n" 7 times.📘 -
🚫 Define a constant instead of duplicating this literal " "string",\n" 4 times.📘 -
🚫 Define a constant instead of duplicating this literal " "null"\n" 4 times.📘 -
🚫 [Define a constant instead of duplicating this literal " ]\n" 7 times.](https://git.zorkdata.com/wanghaiying/transactionlogmask/blob/243313f1dcd57649e5d99095a290c497c8063b07/src/main/java/com/zorkdata/datamask/util/avro/LogAvroMacroDef.java#L20)📘 -
🚫 Define a constant instead of duplicating this literal " },\n" 6 times.📘 -
🚫 Define a constant instead of duplicating this literal " "null",\n" 3 times.📘 -
🚫 Define a constant instead of duplicating this literal " {\n" 3 times.📘 -
🚫 Define a constant instead of duplicating this literal " "type": "map",\n" 3 times.📘 -
🚫 Define a constant instead of duplicating this literal " }\n" 3 times.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Remove this unused "source" private field.📘 -
⚠ Remove this unused "hdfsSrc" private field.📘 -
⚠ Remove this unused "hdfsDest" private field.📘 -
⚠ Remove this unused "core" private field.📘 -
⚠ Remove this unused "date" private field.📘 -
⚠ Remove this unused "startTime" private field.📘 -
⚠ Remove this unused "endTime" private field.📘 -
⚠ Remove this unused "servers" private field.📘 -
⚠ Remove this unused "zookeeper" private field.📘
- ... 118 more
-