This is an automated email from the ASF dual-hosted git repository.
chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 286f1cbea1f Remove useless mask algorithm and document (#28071)
286f1cbea1f is described below
commit 286f1cbea1f9d0a3a6761b6d823bf76be7fc5b7d
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Aug 14 12:35:19 2023 +0800
Remove useless mask algorithm and document (#28071)
* Remove useless mask algorithm and document
* remove config in org.apache.shardingsphere.mask.spi.MaskAlgorithm
---
docs/document/content/dev-manual/mask.cn.md | 5 -
docs/document/content/dev-manual/mask.en.md | 5 -
docs/document/content/reference/mask/_index.cn.md | 2 +-
docs/document/content/reference/mask/_index.en.md | 2 +-
.../common-config/builtin-algorithm/mask.cn.md | 52 -----------
.../common-config/builtin-algorithm/mask.en.md | 52 -----------
.../GenericTableRandomReplaceAlgorithm.java | 2 +-
.../replace/LandlineNumberRandomAlgorithm.java | 73 ---------------
...litaryIdentityNumberRandomReplaceAlgorithm.java | 72 --------------
...rsonalIdentityNumberRandomReplaceAlgorithm.java | 82 ----------------
.../replace/TelephoneRandomReplaceAlgorithm.java | 104 ---------------------
.../UnifiedCreditCodeRandomReplaceAlgorithm.java | 101 --------------------
...rg.apache.shardingsphere.mask.spi.MaskAlgorithm | 5 -
.../replace/LandlineNumberRandomAlgorithmTest.java | 58 ------------
...ryIdentityNumberRandomReplaceAlgorithmTest.java | 56 -----------
...alIdentityNumberRandomReplaceAlgorithmTest.java | 58 ------------
.../TelephoneRandomReplaceAlgorithmTest.java | 75 ---------------
...nifiedCreditCodeRandomReplaceAlgorithmTest.java | 81 ----------------
.../src/main/antlr4/imports/mask/BaseRule.g4 | 5 -
.../parser/src/main/antlr4/imports/mask/Keyword.g4 | 20 ----
20 files changed, 3 insertions(+), 907 deletions(-)
diff --git a/docs/document/content/dev-manual/mask.cn.md
b/docs/document/content/dev-manual/mask.cn.md
index f6f5215f504..8d88ccce787 100644
--- a/docs/document/content/dev-manual/mask.cn.md
+++ b/docs/document/content/dev-manual/mask.cn.md
@@ -26,9 +26,4 @@ chapter = true
| MASK_FROM_X_TO_Y | 遮盖自 x 至 y 数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskFromXToYMaskAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithm.java)
|
| MASK_BEFORE_SPECIAL_CHARS | 特殊字符前遮盖数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskBeforeSpecialCharsAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithm.java)
|
| MASK_AFTER_SPECIAL_CHARS | 特殊字符后遮盖数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskAfterSpecialCharsAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithm.java)
|
-| PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE | 身份证号随机替换数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.replace.PersonalIdentityNumberRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithm.java)
|
-| MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE | 军官证随机替换数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.replace.MilitaryIdentityNumberRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithm.java)
|
-| TELEPHONE_RANDOM_REPLACE | ⼿机号随机替换数据脱敏算法 |
[`org.apache.shardingsphere.mask.algorithm.replace.TelephoneRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithm.java)
|
-| LANDLINE_NUMBER_RANDOM_REPLACE | 座机号码随机替换 |
[`org.apache.shardingsphere.mask.algorithm.replace.LandlineNumberRandomAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithm.java)
|
| GENERIC_TABLE_RANDOM_REPLACE | 通⽤表格随机替换 |
[`org.apache.shardingsphere.mask.algorithm.replace.GenericTableRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java)
|
-| UNIFIED_CREDIT_CODE_RANDOM_REPLACE | 统⼀信⽤码随机替换 |
[`org.apache.shardingsphere.mask.algorithm.replace.UnifiedCreditCodeRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithm.java)
|
diff --git a/docs/document/content/dev-manual/mask.en.md
b/docs/document/content/dev-manual/mask.en.md
index dc77ef2926b..67580110eea 100644
--- a/docs/document/content/dev-manual/mask.en.md
+++ b/docs/document/content/dev-manual/mask.en.md
@@ -26,9 +26,4 @@ Data masking algorithm definition
| MASK_FROM_X_TO_Y | Mask from x to y data masking
algorithm |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskFromXToYMaskAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithm.java)
|
| MASK_BEFORE_SPECIAL_CHARS | Mask before special chars data
masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskBeforeSpecialCharsAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithm.java)
|
| MASK_AFTER_SPECIAL_CHARS | Mask after special chars data
masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.cover.MaskAfterSpecialCharsAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithm.java)
|
-| PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE | Personal identity number random
replace data masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.PersonalIdentityNumberRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithm.java)
|
-| MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE | Military identity number random
replace data masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.MilitaryIdentityNumberRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithm.java)
|
-| TELEPHONE_RANDOM_REPLACE | Telephone random replace data
masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.TelephoneRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithm.java)
|
-| LANDLINE_NUMBER_RANDOM_REPLACE | Landline number random replace
data masking algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.LandlineNumberRandomAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithm.java)
|
| GENERIC_TABLE_RANDOM_REPLACE | Generic table random replace
algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.GenericTableRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java)
|
-| UNIFIED_CREDIT_CODE_RANDOM_REPLACE | Unified credit code random replace
algorithm |
[`org.apache.shardingsphere.mask.algorithm.replace.UnifiedCreditCodeRandomReplaceAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithm.java)
|
diff --git a/docs/document/content/reference/mask/_index.cn.md
b/docs/document/content/reference/mask/_index.cn.md
index 3d51efa76ae..8dea432389a 100644
--- a/docs/document/content/reference/mask/_index.cn.md
+++ b/docs/document/content/reference/mask/_index.cn.md
@@ -22,7 +22,7 @@ Apache ShardingSphere 通过对用户查询的 SQL 进行解析,并依据用
**数据源配置**:指数据源配置。
-**脱敏算法配置**:指使用什么脱敏算法。目前 ShardingSphere
内置了多种脱敏算法:MD5、KEEP_FIRST_N_LAST_M、KEEP_FROM_X_TO_Y
、MASK_FIRST_N_LAST_M、MASK_FROM_X_TO_Y、MASK_BEFORE_SPECIAL_CHARS、MASK_AFTER_SPECIAL_CHARS、PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE、MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE
和 TELEPHONE_RANDOM_REPLACE。用户还可以通过实现 ShardingSphere 提供的接口,自行实现一套脱敏算法。
+**脱敏算法配置**:指使用什么脱敏算法。目前 ShardingSphere
内置了多种脱敏算法:MD5、KEEP_FIRST_N_LAST_M、KEEP_FROM_X_TO_Y
、MASK_FIRST_N_LAST_M、MASK_FROM_X_TO_Y、MASK_BEFORE_SPECIAL_CHARS、MASK_AFTER_SPECIAL_CHARS
和 GENERIC_TABLE_RANDOM_REPLACE。用户还可以通过实现 ShardingSphere 提供的接口,自行实现一套脱敏算法。
**脱敏表配置**:用于告诉 ShardingSphere 数据表里哪个列用于数据脱敏、使用什么算法脱敏。
diff --git a/docs/document/content/reference/mask/_index.en.md
b/docs/document/content/reference/mask/_index.en.md
index 1a869e21061..49110065433 100644
--- a/docs/document/content/reference/mask/_index.en.md
+++ b/docs/document/content/reference/mask/_index.en.md
@@ -22,7 +22,7 @@ Desensitization configuration is mainly divided into three
parts: data source co
**Data source configuration**: the configuration of the data source.
-**Mask algorithm configuration**: currently, ShardingSphere has a variety of
built-in desensitization algorithms: MD5, KEEP_FIRST_N_LAST_M, KEEP_FROM_X_TO_Y
, MASK_FIRST_N_LAST_M, MASK_FROM_X_TO_Y, MASK_BEFORE_SPECIAL_CHARS,
MASK_AFTER_SPECIAL_CHARS, PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE,
MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE, and TELEPHONE_RANDOM_REPLACE.
+**Mask algorithm configuration**: currently, ShardingSphere has a variety of
built-in desensitization algorithms: MD5, KEEP_FIRST_N_LAST_M, KEEP_FROM_X_TO_Y
, MASK_FIRST_N_LAST_M, MASK_FROM_X_TO_Y, MASK_BEFORE_SPECIAL_CHARS,
MASK_AFTER_SPECIAL_CHARS and GENERIC_TABLE_RANDOM_REPLACE.
Users can also implement a set of desensitization algorithms by implementing
the interface provided by ShardingSphere.
diff --git
a/docs/document/content/user-manual/common-config/builtin-algorithm/mask.cn.md
b/docs/document/content/user-manual/common-config/builtin-algorithm/mask.cn.md
index 2aa745c5659..7eb51f15321 100644
---
a/docs/document/content/user-manual/common-config/builtin-algorithm/mask.cn.md
+++
b/docs/document/content/user-manual/common-config/builtin-algorithm/mask.cn.md
@@ -95,46 +95,6 @@ weight = 9
### 替换脱敏算法
-#### 身份证随机替换脱敏算法
-
-类型:PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE
-
-可配置属性:
-
-| *名称* | *数据类型* | *说明* |
-|-----------------------------|--------|-----------------------|
-| alpha-two-country-area-code | String | 两位字母国家/地区编码(可选,默认:CN) |
-
-#### 军官证随机替换脱敏算法
-
-类型:MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE
-
-可配置属性:
-
-| *名称* | *数据类型* | *说明* |
-|------------|--------|-------------------------------|
-| type-codes | String | 军官证种类编码(以英文逗号分隔,例如:军,人,士,文,职) |
-
-#### 手机号随机替换脱敏算法
-
-类型:TELEPHONE_RANDOM_REPLACE
-
-可配置属性:
-
-| *名称* | *数据类型* | *说明*
|
-|-----------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| network-numbers | String |
⽹号(以英文逗号分隔,默认值:130,131,132,133,134,135,136,137,138,139,150,151,152,153,155,156,157,158,159,166,170,176,177,178,180,181,182,183,184,185,186,187,188,189,191,198,199)
|
-
-#### 座机号码随机替换
-
-类型:LANDLINE_NUMBER_RANDOM_REPLACE
-
-可配置属性:
-
-| *名称* | *数据类型* | *说明* |
-|------------------|--------|---------------|
-| landline-numbers | String | 座机号码(以英文逗号分隔) |
-
#### 通⽤表格随机替换
类型:GENERIC_TABLE_RANDOM_REPLACE
@@ -148,18 +108,6 @@ weight = 9
| digital-codes | String | 数字码表(以英文逗号分隔,默认值:0,1,2,3,4,5,6,7,8,9)
|
| special-codes | String |
特殊字符码表(以英文逗号分隔,默认值:~,!,@,#,$,%,^,&,*,:,<,>,¦) |
-#### 统⼀信⽤码随机替换
-
-类型:UNIFIED_CREDIT_CODE_RANDOM_REPLACE
-
-可配置属性:
-
-| *名称* | *数据类型* | *说明* |
-|-------------------------------|--------|-------------------|
-| registration-department-codes | String | 登记管理部门代码(以英文逗号分隔) |
-| category-codes | String | 机构类别代码(以英文逗号分隔) |
-| administrative-division-codes | String | 行政区划随机码表(以英文逗号分隔) |
-
## 操作步骤
1. 在脱敏规则中配置脱敏算法;
2. 为脱敏算法指定脱敏算法类型。
diff --git
a/docs/document/content/user-manual/common-config/builtin-algorithm/mask.en.md
b/docs/document/content/user-manual/common-config/builtin-algorithm/mask.en.md
index 8b493cb4eaa..d29b40d51ca 100644
---
a/docs/document/content/user-manual/common-config/builtin-algorithm/mask.en.md
+++
b/docs/document/content/user-manual/common-config/builtin-algorithm/mask.en.md
@@ -95,46 +95,6 @@ Attributes:
### Replace Data Masking Algorithm
-#### Personal Identity Number Random Replace Data Masking Algorithm
-
-Type: PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE
-
-Attributes:
-
-| *Name* | *DataType* | *Description*
|
-|-----------------------------|------------|-----------------------------------------------------------|
-| alpha-two-country-area-code | String | alpha two country area code
(Optional, default value: CN) |
-
-#### Military Identity Number Random Replace Data Masking Algorithm
-
-类型:MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE
-
-可配置属性:
-
-| *Name* | *DataType* | *Description*
|
-|-------------------------------|------------|------------------------------------------------------------|
-| type-codes | String | military identity number type
codes (separate with comma) |
-
-#### Telephone Random Replace Data Masking Algorithm
-
-Type: TELEPHONE_RANDOM_REPLACE
-
-Attributes:
-
-| *Name* | *DataType* | *Description*
|
-|-----------------|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| network-numbers | String | Network numbers (separate with comma, default
value:
130,131,132,133,134,135,136,137,138,139,150,151,152,153,155,156,157,158,159,166,170,176,177,178,180,181,182,183,184,185,186,187,188,189,191,198,199)
|
-
-#### Landline Number Random Replace Data Masking Algorithm
-
-Type: LANDLINE_NUMBER_RANDOM_REPLACE
-
-Attributes:
-
-| *Name* | *DataType* | *Description* |
-|------------------|------------|----------------------------------------|
-| landline-numbers | String | Landline numbers (separate with comma) |
-
#### Generic table random replace algorithm.
Type: GENERIC_TABLE_RANDOM_REPLACE
@@ -148,18 +108,6 @@ Attributes:
| digital-random-codes | String | Numbers (separate with comma, default
value: 0,1,2,3,4,5,6,7,8,9) |
| special-codes | String | Special codes (separate with comma,
default value: ~,!,@,#,$,%,^,&,*,:,<,>,¦) |
-#### Unified credit code random replace algorithm
-
-Type: UNIFIED_CREDIT_CODE_RANDOM_REPLACE
-
-Attributes:
-
-| *Name* | *DataType* | *Description*
|
-|-------------------------------|------------|----------------------------------------------------|
-| registration-department-codes | String | Registration department code
(separate with comma) |
-| category-codes | String | Category code (separate with
comma) |
-| administrative-division-codes | String | Administrative division code
(separate with comma) |
-
## Operating Procedure
1. Configure maskAlgorithms in a mask rule.
2. Use relevant algorithm types in maskAlgorithms.
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java
index 86dbfcca87f..0567762377f 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/GenericTableRandomReplaceAlgorithm.java
@@ -68,7 +68,7 @@ public final class GenericTableRandomReplaceAlgorithm
implements MaskAlgorithm<O
ShardingSpherePreconditions.checkState(!digitalCodes.isEmpty(),
() -> new MaskAlgorithmInitializationException(getType(),
String.format("'%s' must be not empty", DIGITAL_CODES)));
specialCodes = splitPropsToList(props.getProperty(SPECIAL_CODES,
DEFAULT_SPECIAL_CODES));
- ShardingSpherePreconditions.checkState(!SPECIAL_CODES.isEmpty(),
+ ShardingSpherePreconditions.checkState(!specialCodes.isEmpty(),
() -> new MaskAlgorithmInitializationException(getType(),
String.format("'%s' must be not empty", SPECIAL_CODES)));
}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithm.java
deleted file mode 100644
index ad32c3364ee..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithm.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.mask.algorithm.MaskAlgorithmPropsChecker;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-import java.security.SecureRandom;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-
-/**
- * Landline number replace algorithm.
- */
-public final class LandlineNumberRandomAlgorithm implements
MaskAlgorithm<Object, String> {
-
- private static final String LANDLINE_NUMBERS = "landline-numbers";
-
- private final Random random = new SecureRandom();
-
- private List<String> landLineNumbers;
-
- @Override
- public void init(final Properties props) {
- landLineNumbers = createLandLineNumbers(props);
- }
-
- private List<String> createLandLineNumbers(final Properties props) {
- MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props,
LANDLINE_NUMBERS, getType());
- return
Splitter.on(",").trimResults().splitToList(props.getProperty(LANDLINE_NUMBERS));
- }
-
- @Override
- public String mask(final Object plainValue) {
- String result = null == plainValue ? null : String.valueOf(plainValue);
- if (Strings.isNullOrEmpty(result)) {
- return result;
- }
- return
landLineNumbers.stream().filter(result::startsWith).findFirst().map(each ->
createRandValue(result, each)).orElse(result);
- }
-
- private String createRandValue(final String plainValue, final String
landLineNumber) {
- StringBuilder result = new StringBuilder();
-
result.append(landLineNumbers.get(random.nextInt(landLineNumbers.size())));
- for (int i = landLineNumber.length(); i < plainValue.length(); i++) {
- result.append(Character.forDigit(random.nextInt(10), 10));
- }
- return result.toString();
- }
-
- @Override
- public String getType() {
- return "LANDLINE_NUMBER_RANDOM_REPLACE";
- }
-}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithm.java
deleted file mode 100644
index ecfc1ffbed2..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithm.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.mask.algorithm.MaskAlgorithmPropsChecker;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-import java.security.SecureRandom;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.stream.Collectors;
-
-/**
- * Military identity number random replace algorithm.
- */
-public final class MilitaryIdentityNumberRandomReplaceAlgorithm implements
MaskAlgorithm<Object, String> {
-
- private static final String TYPE_CODE = "type-codes";
-
- private final Random random = new SecureRandom();
-
- private List<Character> typeCodes;
-
- @Override
- public void init(final Properties props) {
- typeCodes = createTypeCodes(props);
- }
-
- private List<Character> createTypeCodes(final Properties props) {
- MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props, TYPE_CODE,
getType());
- return
Splitter.on(",").trimResults().splitToList(props.getProperty(TYPE_CODE)).stream().map(each
-> each.charAt(0)).collect(Collectors.toList());
- }
-
- @Override
- public String mask(final Object plainValue) {
- String result = null == plainValue ? null : String.valueOf(plainValue);
- if (Strings.isNullOrEmpty(result)) {
- return result;
- }
- char[] chars = result.toCharArray();
- chars[0] = typeCodes.get(random.nextInt(typeCodes.size()));
- for (int i = 1; i < chars.length; i++) {
- if (Character.isDigit(chars[i])) {
- chars[i] = Character.forDigit(random.nextInt(10), 10);
- }
- }
- return new String(chars);
- }
-
- @Override
- public String getType() {
- return "MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE";
- }
-}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithm.java
deleted file mode 100644
index 4dbd547b82c..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithm.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import com.google.common.base.Strings;
-import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-import java.security.SecureRandom;
-import java.util.Properties;
-import java.util.Random;
-
-/**
- * Personal identity number random replace algorithm.
- */
-public final class PersonalIdentityNumberRandomReplaceAlgorithm implements
MaskAlgorithm<Object, String> {
-
- private static final String ALPHA_TWO_COUNTRY_AREA_CODE =
"alpha-two-country-area-code";
-
- private final Random random = new SecureRandom();
-
- private String alphaTwoCountryAreaCode;
-
- @Override
- public void init(final Properties props) {
- alphaTwoCountryAreaCode =
props.getProperty(ALPHA_TWO_COUNTRY_AREA_CODE, "CN");
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(alphaTwoCountryAreaCode),
- () -> new MaskAlgorithmInitializationException(getType(),
String.format("%s can not be empty", ALPHA_TWO_COUNTRY_AREA_CODE)));
- }
-
- @Override
- public String mask(final Object plainValue) {
- String result = null == plainValue ? null : String.valueOf(plainValue);
- if (Strings.isNullOrEmpty(result)) {
- return result;
- }
- if ("CN".equals(alphaTwoCountryAreaCode)) {
- return randomReplaceForChinesePersonalIdentityNumber(result);
- }
- return result;
- }
-
- private String randomReplaceForChinesePersonalIdentityNumber(final String
result) {
- switch (result.length()) {
- case 15:
- return randomReplaceNumber(result, 6, 12);
- case 18:
- return randomReplaceNumber(result, 6, 14);
- default:
- }
- return result;
- }
-
- private String randomReplaceNumber(final String result, final int from,
final int to) {
- char[] chars = result.toCharArray();
- for (int i = from; i < to; i++) {
- chars[i] = Character.forDigit(random.nextInt(10), 10);
- }
- return new String(chars);
- }
-
- @Override
- public String getType() {
- return "PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE";
- }
-}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithm.java
deleted file mode 100644
index 55d90571982..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithm.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import lombok.SneakyThrows;
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.SecureRandom;
-import java.util.List;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.Random;
-import java.util.Scanner;
-import java.util.stream.Collectors;
-
-/**
- * Telephone random replace algorithm.
- */
-public final class TelephoneRandomReplaceAlgorithm implements
MaskAlgorithm<Object, String> {
-
- private static final String NETWORK_NUMBERS = "network-numbers";
-
- private final Random random = new SecureRandom();
-
- private List<String> networkNumbers;
-
- @Override
- public void init(final Properties props) {
- networkNumbers = createNetworkNumbers(props);
- }
-
- private List<String> createNetworkNumbers(final Properties props) {
- String networkNumbers = props.containsKey(NETWORK_NUMBERS) &&
!Strings.isNullOrEmpty(props.getProperty(NETWORK_NUMBERS)) ?
props.getProperty(NETWORK_NUMBERS) : initDefaultNetworkNumbers();
- return
Splitter.on(",").trimResults().splitToList(networkNumbers).stream().map(this::getNetworkNumber).distinct().collect(Collectors.toList());
- }
-
- @SneakyThrows(IOException.class)
- private String initDefaultNetworkNumbers() {
- StringBuilder result = new StringBuilder();
- try (
- InputStream inputStream =
Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResourceAsStream("algorithm/replace/chinese_network_numbers.dict"));
- Scanner scanner = new Scanner(inputStream)) {
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- if (!line.isEmpty() && !line.startsWith("#")) {
- result.append(line);
- }
- }
- }
- return result.toString();
- }
-
- private String getNetworkNumber(final String networkNumber) {
- try {
- Integer.parseInt(networkNumber);
- return networkNumber;
- } catch (final NumberFormatException ignored) {
- throw new MaskAlgorithmInitializationException(getType(),
String.format("network-number %s can only be integer number", networkNumber));
- }
- }
-
- @Override
- public String mask(final Object plainValue) {
- String result = null == plainValue ? null : String.valueOf(plainValue);
- if (Strings.isNullOrEmpty(result)) {
- return result;
- }
- return
networkNumbers.stream().filter(result::startsWith).findFirst().map(each ->
createRandValue(result, each)).orElse(result);
- }
-
- private String createRandValue(final String plainValue, final String
networkNumber) {
- StringBuilder result = new StringBuilder();
-
result.append(networkNumbers.get(random.nextInt(networkNumbers.size())));
- for (int i = networkNumber.length(); i < plainValue.length(); i++) {
- result.append(Character.forDigit(random.nextInt(10), 10));
- }
- return result.toString();
- }
-
- @Override
- public String getType() {
- return "TELEPHONE_RANDOM_REPLACE";
- }
-}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithm.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithm.java
deleted file mode 100644
index 6a570f00920..00000000000
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithm.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import lombok.Getter;
-import org.apache.shardingsphere.mask.algorithm.MaskAlgorithmPropsChecker;
-import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
-
-import java.security.SecureRandom;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.stream.Collectors;
-
-/**
- * Unified credit code random replace algorithm.
- */
-public final class UnifiedCreditCodeRandomReplaceAlgorithm implements
MaskAlgorithm<Object, String> {
-
- private static final String REGISTRATION_DEPARTMENT_CODES =
"registration-department-codes";
-
- private static final String CATEGORY_CODES = "category-codes";
-
- private static final String ADMINISTRATIVE_DIVISION_CODES =
"administrative-division-codes";
-
- private final Random random = new SecureRandom();
-
- private List<Character> registrationDepartmentCodes;
-
- private List<Character> categoryCodes;
-
- private List<String> administrativeDivisionCodes;
-
- @Getter
- private Properties props;
-
- @Override
- public void init(final Properties props) {
- this.props = props;
- this.registrationDepartmentCodes =
createRegistrationDepartmentCodes(props);
- this.categoryCodes = createCategoryCodes(props);
- this.administrativeDivisionCodes =
createAdministrativeDivisionCodes(props);
- }
-
- private List<Character> createRegistrationDepartmentCodes(final Properties
props) {
- MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props,
REGISTRATION_DEPARTMENT_CODES, getType());
- return
Splitter.on(",").trimResults().splitToList(props.getProperty(REGISTRATION_DEPARTMENT_CODES)).stream().map(each
-> each.charAt(0)).collect(Collectors.toList());
- }
-
- private List<Character> createCategoryCodes(final Properties props) {
- MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props,
CATEGORY_CODES, getType());
- return
Splitter.on(",").trimResults().splitToList(props.getProperty(CATEGORY_CODES)).stream().map(each
-> each.charAt(0)).collect(Collectors.toList());
- }
-
- private List<String> createAdministrativeDivisionCodes(final Properties
props) {
- MaskAlgorithmPropsChecker.checkAtLeastOneCharConfig(props,
ADMINISTRATIVE_DIVISION_CODES, getType());
- return
Splitter.on(",").trimResults().splitToList(props.getProperty(ADMINISTRATIVE_DIVISION_CODES));
- }
-
- @Override
- public String mask(final Object plainValue) {
- String result = null == plainValue ? null : String.valueOf(plainValue);
- if (Strings.isNullOrEmpty(result)) {
- return result;
- }
- return randomReplace();
- }
-
- private String randomReplace() {
- StringBuilder result = new StringBuilder();
-
result.append(registrationDepartmentCodes.get(random.nextInt(registrationDepartmentCodes.size())))
-
.append(categoryCodes.get(random.nextInt(categoryCodes.size())))
-
.append(administrativeDivisionCodes.get(random.nextInt(administrativeDivisionCodes.size())));
- for (int i = 0; i < 10; i++) {
- result.append(Character.forDigit(random.nextInt(10), 10));
- }
- return result.toString();
- }
-
- @Override
- public String getType() {
- return "UNIFIED_CREDIT_CODE_RANDOM_REPLACE";
- }
-}
diff --git
a/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mask.spi.MaskAlgorithm
b/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mask.spi.MaskAlgorithm
index 8653596044b..c7f54ad98c1 100644
---
a/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mask.spi.MaskAlgorithm
+++
b/features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mask.spi.MaskAlgorithm
@@ -22,9 +22,4 @@
org.apache.shardingsphere.mask.algorithm.cover.MaskAfterSpecialCharsAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.MaskBeforeSpecialCharsAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.MaskFirstNLastMMaskAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.MaskFromXToYMaskAlgorithm
-org.apache.shardingsphere.mask.algorithm.replace.TelephoneRandomReplaceAlgorithm
-org.apache.shardingsphere.mask.algorithm.replace.PersonalIdentityNumberRandomReplaceAlgorithm
-org.apache.shardingsphere.mask.algorithm.replace.MilitaryIdentityNumberRandomReplaceAlgorithm
-org.apache.shardingsphere.mask.algorithm.replace.LandlineNumberRandomAlgorithm
org.apache.shardingsphere.mask.algorithm.replace.GenericTableRandomReplaceAlgorithm
-org.apache.shardingsphere.mask.algorithm.replace.UnifiedCreditCodeRandomReplaceAlgorithm
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
deleted file mode 100644
index 4cbeee97576..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class LandlineNumberRandomAlgorithmTest {
-
- private LandlineNumberRandomAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- maskAlgorithm = new LandlineNumberRandomAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("landline-numbers", "025, 027, 028, 029, 0310, 0311, 0313")));
- }
-
- @Test
- void assertMask() {
- assertThat(maskAlgorithm.mask(""), is(""));
- assertThat(maskAlgorithm.mask("0251234567"), not("0251234567"));
- assertThat(maskAlgorithm.mask("03101234567"), not("03101234567"));
- }
-
- @Test
- void assertInitWhenConfigIsEmpty() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build()));
- }
-
- @Test
- void assertMaskWithInvalidConfig() {
- assertThrows(MaskAlgorithmInitializationException.class,
- () -> maskAlgorithm.init(PropertiesBuilder.build(new
Property("landline-numbers", ""))));
- }
-}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithmTest.java
deleted file mode 100644
index 0b42067a4ec..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/MilitaryIdentityNumberRandomReplaceAlgorithmTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class MilitaryIdentityNumberRandomReplaceAlgorithmTest {
-
- private MilitaryIdentityNumberRandomReplaceAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- maskAlgorithm = new MilitaryIdentityNumberRandomReplaceAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new Property("type-codes",
"军,人,士,文,职")));
- }
-
- @Test
- void assertMask() {
- assertThat(maskAlgorithm.mask("军字第1234567号"), not("军字第1234567号"));
- assertThat(maskAlgorithm.mask(""), is(""));
- assertNull(maskAlgorithm.mask(null));
- }
-
- @Test
- void assertMaskWithInvalidProps() {
- MilitaryIdentityNumberRandomReplaceAlgorithm algorithm = new
MilitaryIdentityNumberRandomReplaceAlgorithm();
- assertThrows(MaskAlgorithmInitializationException.class, () ->
algorithm.init(new Properties()));
- }
-}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
deleted file mode 100644
index 526253899da..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class PersonalIdentityNumberRandomReplaceAlgorithmTest {
-
- private PersonalIdentityNumberRandomReplaceAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- maskAlgorithm = new PersonalIdentityNumberRandomReplaceAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("alpha-two-country-area-code", "CN")));
- }
-
- @Test
- void assertMask() {
- assertThat(maskAlgorithm.mask("372928198312103215"),
not("372928198312103215"));
- assertThat(maskAlgorithm.mask("372928231210321"),
not("372928231210321"));
- assertThat(maskAlgorithm.mask("1234567891011121314"),
is("1234567891011121314"));
- assertThat(maskAlgorithm.mask("123456"), is("123456"));
- assertThat(maskAlgorithm.mask(""), is(""));
- assertThat(maskAlgorithm.mask(null), is(nullValue()));
- }
-
- @Test
- void assertMaskWithDifferentCountryCode() {
- PersonalIdentityNumberRandomReplaceAlgorithm maskAlgorithmCN = new
PersonalIdentityNumberRandomReplaceAlgorithm();
- maskAlgorithmCN.init(PropertiesBuilder.build(new
Property("alpha-two-country-area-code", "CN")));
- PersonalIdentityNumberRandomReplaceAlgorithm maskAlgorithmJP = new
PersonalIdentityNumberRandomReplaceAlgorithm();
- maskAlgorithmJP.init(PropertiesBuilder.build(new
Property("alpha-two-country-area-code", "JP")));
- assertThat(maskAlgorithmCN.mask("372928198312103215"),
not(maskAlgorithmJP.mask("372928198312103215")));
- }
-}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
deleted file mode 100644
index 62be4eb06bc..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import org.apache.shardingsphere.infra.util.reflection.ReflectionUtils;
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class TelephoneRandomReplaceAlgorithmTest {
-
- private static final Collection<String> DEFAULT_NETWORK_NUMBERS =
Arrays.asList("130", "131", "132", "133", "134", "135", "136", "137", "138",
"139", "150", "151", "152", "153", "155", "156",
- "157", "158", "159", "166", "170", "176", "177", "178", "180",
"181", "182", "183", "184", "185", "186", "187", "188", "189", "191", "198",
"199");
-
- private TelephoneRandomReplaceAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- maskAlgorithm = new TelephoneRandomReplaceAlgorithm();
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("network-numbers", "130, 130, 155,1702")));
- }
-
- @Test
- void assertInitWithEmptyProps() {
- maskAlgorithm.init(new Properties());
- Optional<Object> actual = ReflectionUtils.getFieldValue(maskAlgorithm,
"networkNumbers");
- assertTrue(actual.isPresent());
- assertThat(actual.get(), is(DEFAULT_NETWORK_NUMBERS));
- }
-
- @Test
- void assertMaskWithNullPlaintext() {
- assertNull(maskAlgorithm.mask(null));
- }
-
- @Test
- void assertMask() {
- assertThat(maskAlgorithm.mask(""), is(""));
- assertThat(maskAlgorithm.mask("13012345678"), not("13012345678"));
- }
-
- @Test
- void assertInitWhenConfigNotNumberProps() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build(new Property("network-numbers",
"130, x130, 155,1702"))));
- }
-}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
deleted file mode 100644
index 27124e0deee..00000000000
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/UnifiedCreditCodeRandomReplaceAlgorithmTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mask.algorithm.replace;
-
-import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class UnifiedCreditCodeRandomReplaceAlgorithmTest {
-
- private UnifiedCreditCodeRandomReplaceAlgorithm maskAlgorithm;
-
- @BeforeEach
- void setUp() {
- maskAlgorithm = new UnifiedCreditCodeRandomReplaceAlgorithm();
- }
-
- @Test
- void assertMask() {
- maskAlgorithm.init(PropertiesBuilder.build(new
Property("registration-department-codes", "1,2,3,4"), new
Property("category-codes", "1,2,3,4"),
- new Property("administrative-division-codes",
"100000,200000,300000")));
- assertThat(maskAlgorithm.mask("123456781234567890"),
not("123456781234567890"));
- assertThat(maskAlgorithm.mask("123456781234567890").length(), is(18));
- }
-
- @Test
- void assertInitWhenConfigIsNull() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build(new
Property("registration-department-codes", "1,2,3,4"))));
- }
-
- @Test
- void assertInitWhenConfigIsEmpty() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build()));
- }
-
- @Test
- void assertInitWhenRegistrationDepartmentCodesIsEmpty() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build(
- new Property("registration-department-codes", ""),
- new Property("category-codes", "1,2,3,4"),
- new Property("administrative-division-codes",
"100000,200000,300000"))));
- }
-
- @Test
- void assertInitWhenCategoryCodesIsEmpty() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build(
- new Property("registration-department-codes", "1,2,3,4"),
- new Property("category-codes", ""),
- new Property("administrative-division-codes",
"100000,200000,300000"))));
- }
-
- @Test
- void assertInitWhenAdministrativeDivisionCodesIsEmpty() {
- assertThrows(MaskAlgorithmInitializationException.class, () ->
maskAlgorithm.init(PropertiesBuilder.build(
- new Property("registration-department-codes", "1,2,3,4"),
- new Property("category-codes", "1,2,3,4"),
- new Property("administrative-division-codes", ""))));
- }
-}
diff --git
a/features/mask/distsql/parser/src/main/antlr4/imports/mask/BaseRule.g4
b/features/mask/distsql/parser/src/main/antlr4/imports/mask/BaseRule.g4
index 959519b325b..0fa88395181 100644
--- a/features/mask/distsql/parser/src/main/antlr4/imports/mask/BaseRule.g4
+++ b/features/mask/distsql/parser/src/main/antlr4/imports/mask/BaseRule.g4
@@ -39,11 +39,6 @@ buildInMaskAlgorithmType
| MASK_FROM_X_TO_Y
| MASK_BEFORE_SPECIAL_CHARS
| MASK_AFTER_SPECIAL_CHARS
- | PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE
- | MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE
- | LANDLINE_NUMBER_RANDOM_REPLACE
- | TELEPHONE_RANDOM_REPLACE
- | UNIFIED_CREDIT_CODE_RANDOM_REPLACE
| GENERIC_TABLE_RANDOM_REPLACE
;
diff --git
a/features/mask/distsql/parser/src/main/antlr4/imports/mask/Keyword.g4
b/features/mask/distsql/parser/src/main/antlr4/imports/mask/Keyword.g4
index 653700886f5..695bacacc22 100644
--- a/features/mask/distsql/parser/src/main/antlr4/imports/mask/Keyword.g4
+++ b/features/mask/distsql/parser/src/main/antlr4/imports/mask/Keyword.g4
@@ -131,26 +131,6 @@ MASK_AFTER_SPECIAL_CHARS
: M A S K UL_ A F T E R UL_ S P E C I A L UL_ C H A R S
;
-PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE
- : P E R S O N A L UL_ I D E N T I T Y UL_ N U M B E R UL_ R A N D O M UL_
R E P L A C E
- ;
-
-MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE
- : M I L I T A R Y UL_ I D E N T I T Y UL_ N U M B E R UL_ R A N D O M UL_
R E P L A C E
- ;
-
-LANDLINE_NUMBER_RANDOM_REPLACE
- : L A N D L I N E UL_ N U M B E R UL_ R A N D O M UL_ R E P L A C E
- ;
-
-TELEPHONE_RANDOM_REPLACE
- : T E L E P H O N E UL_ R A N D O M UL_ R E P L A C E
- ;
-
-UNIFIED_CREDIT_CODE_RANDOM_REPLACE
- : U N I F I E D UL_ C R E D I T UL_ C O D E UL_ R A N D O M UL_ R E P L A
C E
- ;
-
GENERIC_TABLE_RANDOM_REPLACE
: G E N E R I C UL_ T A B L E UL_ R A N D O M UL_ R E P L A C E
;