From 1eead9676ac2631c26e63715e0cfd743bdf5057f Mon Sep 17 00:00:00 2001 From: applesline Date: Fri, 21 Jan 2022 07:16:31 +0000 Subject: [PATCH] supplement missing files --- .../handle/impl/ChineseNameHandler.java | 39 +++++++++++++++++++ .../desensitize/handle/impl/EmailHandler.java | 28 +++++++++++++ .../handle/impl/GenderHandler.java | 22 +++++++++++ .../handle/impl/IdCardNumHandler.java | 23 +++++++++++ .../desensitize/handle/impl/IpHandler.java | 27 +++++++++++++ .../handle/impl/MobileHandler.java | 23 +++++++++++ .../handle/impl/OtherCardHandler.java | 23 +++++++++++ .../handle/impl/PasswordHandler.java | 23 +++++++++++ .../handle/impl/UserIdHandler.java | 23 +++++++++++ 9 files changed, 231 insertions(+) create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/ChineseNameHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/EmailHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/GenderHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/IdCardNumHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/IpHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/MobileHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/OtherCardHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/PasswordHandler.java create mode 100644 src/main/java/org/applesline/desensitize/handle/impl/UserIdHandler.java diff --git a/src/main/java/org/applesline/desensitize/handle/impl/ChineseNameHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/ChineseNameHandler.java new file mode 100644 index 0000000..e1e31a1 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/ChineseNameHandler.java @@ -0,0 +1,39 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class ChineseNameHandler extends DesensitizeAdapter { + + private static final List CHINESE_NAMES = Arrays.asList("欧阳", "太史", "端木", "上官", "司马", "东方", "独孤", "南宫", "万俟", "闻人", "夏侯", "诸葛", "尉迟", "公羊", "赫连", "澹台", "皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容", "仲孙", "钟离", "长孙", "宇文", "城池", "司徒", "鲜于", "司空", "汝嫣", "闾丘", "子车", "亓官", "司寇", "巫马", "公西", "颛孙", "壤驷", "公良", "漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐", "段干", "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户", "公玉", "公仪", "梁丘", "公仲", "公上", "公门", "公山", "公坚", "左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙", "南荣", "东里", "东宫", "仲长", "子书", "子桑", "即墨", "达奚", "褚师"); + + @Override + public String doMask(String fullName) { + if (isBlank(fullName)) { + return ""; + } else if (fullName.length() == 1) { + return "*"; + } else { + int csNameLen = 2; + if (CHINESE_NAMES.contains(fullName.substring(0, csNameLen))) { + return hide(fullName, 0, csNameLen); + } else { + return fullName.length() > 5 ? hide(fullName, 0, 3) : hide(fullName, 0, 1); + } + } + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.CHINESE_NAME; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/EmailHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/EmailHandler.java new file mode 100644 index 0000000..c66a7fa --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/EmailHandler.java @@ -0,0 +1,28 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class EmailHandler extends DesensitizeAdapter { + + @Override + public String doMask(String email) { + if (isBlank(email)) { + return ""; + } else { + int index = indexOf(email, 64); + return index <= 1 ? hide(email, 0, index) : hide(email, index <= 3 ? 1 : 3, index); + } + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.EMAIL; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/GenderHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/GenderHandler.java new file mode 100644 index 0000000..0fdb240 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/GenderHandler.java @@ -0,0 +1,22 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/19 + */ +@Component +public class GenderHandler extends DesensitizeAdapter { + @Override + public String doMask(String gender) { + return isBlank(gender) ? "" : "**"; + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.GENDER; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/IdCardNumHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/IdCardNumHandler.java new file mode 100644 index 0000000..9354775 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/IdCardNumHandler.java @@ -0,0 +1,23 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class IdCardNumHandler extends DesensitizeAdapter { + + @Override + public String doMask(String idCardNum) { + return maskCardNumber(idCardNum,2,2); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.ID_CARD; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/IpHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/IpHandler.java new file mode 100644 index 0000000..69f38a9 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/IpHandler.java @@ -0,0 +1,27 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/19 + */ +@Component +public class IpHandler extends DesensitizeAdapter { + + @Override + public String doMask(String ip) { + if (isBlank(ip)) { + return ""; + } + int max = 6; + return ip.length() <= max ? hide(ip, ip.length() - 1, ip.length()) : hide(ip, ip.length() - max, ip.length()); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.IP; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/MobileHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/MobileHandler.java new file mode 100644 index 0000000..b30f36d --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/MobileHandler.java @@ -0,0 +1,23 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class MobileHandler extends DesensitizeAdapter { + + @Override + public String doMask(String mobile) { + return isBlank(mobile) ? "" : hide(mobile, 3, mobile.length() - 4); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.MOBILE; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/OtherCardHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/OtherCardHandler.java new file mode 100644 index 0000000..23dd433 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/OtherCardHandler.java @@ -0,0 +1,23 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class OtherCardHandler extends DesensitizeAdapter { + + @Override + public String doMask(String idCardNum) { + return maskCardNumber(idCardNum,1,1); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.OTHER_CARD; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/PasswordHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/PasswordHandler.java new file mode 100644 index 0000000..fb165b7 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/PasswordHandler.java @@ -0,0 +1,23 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class PasswordHandler extends DesensitizeAdapter { + + @Override + public String doMask(String password) { + return isBlank(password) ? "" : repeat('*', password.length()); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.PASSWORD; + } +} diff --git a/src/main/java/org/applesline/desensitize/handle/impl/UserIdHandler.java b/src/main/java/org/applesline/desensitize/handle/impl/UserIdHandler.java new file mode 100644 index 0000000..7944580 --- /dev/null +++ b/src/main/java/org/applesline/desensitize/handle/impl/UserIdHandler.java @@ -0,0 +1,23 @@ +package org.applesline.desensitize.handle.impl; + +import org.applesline.desensitize.constants.DesensitizeType; +import org.applesline.desensitize.handle.DesensitizeAdapter; +import org.springframework.stereotype.Component; + +/** + * @author liuyaping + * @date 2022/1/13 + */ +@Component +public class UserIdHandler extends DesensitizeAdapter { + + @Override + public Long doMask() { + return super.doMask(); + } + + @Override + public DesensitizeType getFieldType() { + return DesensitizeType.USER_ID; + } +}