This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 a5fa591a7e2 add encrypt metadata for algorithm (#29737)
a5fa591a7e2 is described below
commit a5fa591a7e2c49484c843f63ee939e11b2589e01
Author: Chuxin Chen <[email protected]>
AuthorDate: Wed Jan 17 09:06:14 2024 +0800
add encrypt metadata for algorithm (#29737)
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
* add encrypt metadata for algorithm
---
.../TestQueryAssistedShardingEncryptAlgorithm.ftl | 18 +++++-
.../api/encrypt/like/LikeEncryptAlgorithm.java | 26 ---------
.../encrypt/standard/StandardEncryptAlgorithm.java | 36 ------------
.../encrypt/spi/EncryptAlgorithm.java | 16 ++++++
.../EncryptAlgorithmMetaData.java} | 21 +++++--
.../assisted/MD5AssistedEncryptAlgorithm.java | 17 +++++-
.../algorithm/standard/AESEncryptAlgorithm.java | 10 +++-
.../MismatchedEncryptAlgorithmTypeException.java | 6 +-
.../generator/EncryptAlterTableTokenGenerator.java | 6 +-
.../shardingsphere/encrypt/rule/EncryptRule.java | 64 ++++++----------------
.../shardingsphere/encrypt/rule/EncryptTable.java | 25 ++++-----
.../rule/column/item/AssistedQueryColumnItem.java | 7 +--
.../encrypt/rule/column/item/CipherColumnItem.java | 4 +-
.../rule/column/item/LikeQueryColumnItem.java | 4 +-
.../assisted/MD5AssistedEncryptAlgorithmTest.java | 5 +-
.../standard/AESEncryptAlgorithmTest.java | 5 +-
.../fixture/CoreEncryptAlgorithmFixture.java | 9 ++-
.../CoreQueryAssistedEncryptAlgorithmFixture.java | 23 +++++++-
.../CoreQueryLikeEncryptAlgorithmFixture.java | 25 ++++++++-
...atedEncryptShowCreateTableMergedResultTest.java | 2 +-
...rgedEncryptShowCreateTableMergedResultTest.java | 2 +-
.../EncryptAlterTableTokenGeneratorTest.java | 16 +++---
.../EncryptCreateTableTokenGeneratorTest.java | 10 ++--
...ryptInsertDerivedColumnsTokenGeneratorTest.java | 4 +-
.../encrypt/rule/EncryptTableTest.java | 4 +-
.../update/CreateEncryptRuleStatementUpdater.java | 30 +++++++---
.../fixture/DistSQLEncryptAlgorithmFixture.java | 9 ++-
.../encrypt/JDBCEncryptAlgorithmFixture.java | 9 ++-
.../JDBCQueryAssistedEncryptAlgorithmFixture.java | 23 +++++++-
.../e2e/fixture/ITEncryptLikeAlgorithmFixture.java | 18 +++++-
.../RewriteNormalEncryptAlgorithmFixture.java | 9 ++-
...ewriteQueryAssistedEncryptAlgorithmFixture.java | 23 +++++++-
.../RewriteQueryLikeEncryptAlgorithmFixture.java | 24 +++++++-
.../TestQueryAssistedShardingEncryptAlgorithm.java | 18 ++++--
34 files changed, 320 insertions(+), 208 deletions(-)
diff --git
a/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/java/TestQueryAssistedShardingEncryptAlgorithm.ftl
b/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/java/TestQueryAssistedShardingEncryptAlgorithm.ftl
index 24bad41c06a..625fc3a0cff 100644
---
a/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/java/TestQueryAssistedShardingEncryptAlgorithm.ftl
+++
b/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/java/TestQueryAssistedShardingEncryptAlgorithm.ftl
@@ -21,25 +21,37 @@ package
org.apache.shardingsphere.example.${package}.${framework?replace('-', '.
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import java.util.Properties;
@SuppressWarnings("LombokGetterMayBeUsed")
-public final class TestQueryAssistedShardingEncryptAlgorithm implements
AssistedEncryptAlgorithm {
+public final class TestQueryAssistedShardingEncryptAlgorithm implements
EncryptAlgorithm {
@Getter
private Properties properties;
-
+
+ @Getter
+ private EncryptAlgorithmMetaData metaData;
+
@Override
public void init(final Properties props) {
this.properties = props;
+ EncryptAlgorithmMetaData algorithmMetaData = new
EncryptAlgorithmMetaData();
+ algorithmMetaData.setSupportDecrypt(false);
+ metaData = algorithmMetaData;
}
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
return "assistedEncryptValue";
}
+
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
@Override
public String getType() {
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/like/LikeEncryptAlgorithm.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/like/LikeEncryptAlgorithm.java
deleted file mode 100644
index a534a530ab7..00000000000
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/like/LikeEncryptAlgorithm.java
+++ /dev/null
@@ -1,26 +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.encrypt.api.encrypt.like;
-
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-
-/**
- * Like encrypt algorithm.
- */
-public interface LikeEncryptAlgorithm extends EncryptAlgorithm {
-}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/standard/StandardEncryptAlgorithm.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/standard/StandardEncryptAlgorithm.java
deleted file mode 100644
index 69c5102592a..00000000000
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/standard/StandardEncryptAlgorithm.java
+++ /dev/null
@@ -1,36 +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.encrypt.api.encrypt.standard;
-
-import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-
-/**
- * Standard encrypt algorithm.
- */
-public interface StandardEncryptAlgorithm extends EncryptAlgorithm {
-
- /**
- * Decrypt.
- *
- * @param cipherValue cipher value
- * @param encryptContext encrypt context
- * @return plain value
- */
- Object decrypt(Object cipherValue, EncryptContext encryptContext);
-}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
index 27839f7e09c..d0916484851 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
@@ -33,4 +33,20 @@ public interface EncryptAlgorithm extends
ShardingSphereAlgorithm {
* @return cipher value
*/
Object encrypt(Object plainValue, EncryptContext encryptContext);
+
+ /**
+ * Decrypt.
+ *
+ * @param cipherValue cipher value
+ * @param encryptContext encrypt context
+ * @return plain value
+ */
+ Object decrypt(Object cipherValue, EncryptContext encryptContext);
+
+ /**
+ * Get meta data.
+ *
+ * @return meta data.
+ */
+ EncryptAlgorithmMetaData getMetaData();
}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/assisted/AssistedEncryptAlgorithm.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithmMetaData.java
similarity index 65%
rename from
features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/assisted/AssistedEncryptAlgorithm.java
rename to
features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithmMetaData.java
index 17f57b1c40f..ea725ed0ec1 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/encrypt/assisted/AssistedEncryptAlgorithm.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithmMetaData.java
@@ -15,12 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.api.encrypt.assisted;
+package org.apache.shardingsphere.encrypt.spi;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
/**
- * Assisted encrypt algorithm.
+ * Encrypt algorithm meta data.
*/
-public interface AssistedEncryptAlgorithm extends EncryptAlgorithm {
+@RequiredArgsConstructor
+@Getter
+public final class EncryptAlgorithmMetaData {
+
+ @Setter
+ private boolean supportDecrypt = true;
+
+ @Setter
+ private boolean supportEquivalentFilter = true;
+
+ @Setter
+ private boolean supportLike;
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
index 11f43bb3c0e..448b747a85a 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
@@ -18,9 +18,11 @@
package org.apache.shardingsphere.encrypt.algorithm.assisted;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import java.util.Properties;
@@ -28,15 +30,21 @@ import java.util.Properties;
* MD5 assisted encrypt algorithm.
*/
@EqualsAndHashCode
-public final class MD5AssistedEncryptAlgorithm implements
AssistedEncryptAlgorithm {
+public final class MD5AssistedEncryptAlgorithm implements EncryptAlgorithm {
private static final String SALT_KEY = "salt";
private String salt;
+ @Getter
+ private EncryptAlgorithmMetaData metaData;
+
@Override
public void init(final Properties props) {
this.salt = props.getProperty(SALT_KEY, "");
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
}
@Override
@@ -44,6 +52,11 @@ public final class MD5AssistedEncryptAlgorithm implements
AssistedEncryptAlgorit
return null == plainValue ? null : DigestUtils.md5Hex(plainValue +
salt);
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "MD5";
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
index 6433d355598..7884987bdb1 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
@@ -19,12 +19,14 @@ package
org.apache.shardingsphere.encrypt.algorithm.standard;
import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.MessageDigestAlgorithms;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import javax.crypto.Cipher;
@@ -42,16 +44,20 @@ import java.util.Properties;
* AES encrypt algorithm.
*/
@EqualsAndHashCode
-public final class AESEncryptAlgorithm implements StandardEncryptAlgorithm {
+public final class AESEncryptAlgorithm implements EncryptAlgorithm {
private static final String AES_KEY = "aes-key-value";
private static final String DIGEST_ALGORITHM_NAME =
"digest-algorithm-name";
+ @Getter
+ private EncryptAlgorithmMetaData metaData;
+
private byte[] secretKey;
@Override
public void init(final Properties props) {
+ metaData = new EncryptAlgorithmMetaData();
secretKey = createSecretKey(props);
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/algorithm/MismatchedEncryptAlgorithmTypeException.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/algorithm/MismatchedEncryptAlgorithmTypeException.java
index a90b556fa89..14d8fd764e9 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/algorithm/MismatchedEncryptAlgorithmTypeException.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/algorithm/MismatchedEncryptAlgorithmTypeException.java
@@ -27,8 +27,8 @@ public final class MismatchedEncryptAlgorithmTypeException
extends EncryptSQLExc
private static final long serialVersionUID = 4258928279099223870L;
- public MismatchedEncryptAlgorithmTypeException(final String databaseName,
final String columnType, final String encryptorName, final String
encryptAlgorithmType) {
- super(XOpenSQLState.GENERAL_ERROR, 81, "`%s` column's encryptor name
`%s` does not match encrypt algorithm type `%s` in database `%s`.",
- columnType, encryptorName, encryptAlgorithmType, databaseName);
+ public MismatchedEncryptAlgorithmTypeException(final String databaseName,
final String columnType, final String encryptorName, final String
algorithmFeature) {
+ super(XOpenSQLState.GENERAL_ERROR, 81, "`%s` column's encryptor `%s`
should support `%s` in database `%s`.",
+ columnType, encryptorName, algorithmFeature, databaseName);
}
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
index 6fa11e1e4ec..b86c8a327dd 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator;
import lombok.Setter;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.constant.EncryptColumnDataType;
import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptColumnAlterException;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
@@ -29,6 +28,7 @@ import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.encrypt.rule.column.item.AssistedQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -176,8 +176,8 @@ public final class EncryptAlterTableTokenGenerator
implements CollectionSQLToken
}
private void isSameEncryptColumn(final EncryptTable encryptTable, final
String previousColumnName, final String columnName) {
- Optional<StandardEncryptAlgorithm> previousEncryptor =
encryptTable.findEncryptor(previousColumnName);
- Optional<StandardEncryptAlgorithm> currentEncryptor =
encryptTable.findEncryptor(columnName);
+ Optional<EncryptAlgorithm> previousEncryptor =
encryptTable.findEncryptor(previousColumnName);
+ Optional<EncryptAlgorithm> currentEncryptor =
encryptTable.findEncryptor(columnName);
if (!previousEncryptor.isPresent() && !currentEncryptor.isPresent()) {
return;
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index f4548d0f970..c4ede51647a 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -22,9 +22,6 @@ import
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfigu
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.algorithm.MismatchedEncryptAlgorithmTypeException;
import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptTableNotFoundException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
@@ -56,16 +53,11 @@ public final class EncryptRule implements DatabaseRule,
TableContainedRule {
public EncryptRule(final String databaseName, final
EncryptRuleConfiguration ruleConfig) {
this.databaseName = databaseName;
configuration = ruleConfig;
- Map<String, StandardEncryptAlgorithm> standardEncryptors = new
LinkedHashMap<>();
- Map<String, AssistedEncryptAlgorithm> assistedEncryptors = new
LinkedHashMap<>();
- Map<String, LikeEncryptAlgorithm> likeEncryptors = new
LinkedHashMap<>();
- ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(
- key, TypedSPILoader.getService(EncryptAlgorithm.class,
value.getType(), value.getProps()), standardEncryptors, assistedEncryptors,
likeEncryptors));
+ Map<String, EncryptAlgorithm> encryptors = new LinkedHashMap<>();
+ ruleConfig.getEncryptors().forEach((key, value) -> encryptors.put(key,
TypedSPILoader.getService(EncryptAlgorithm.class, value.getType(),
value.getProps())));
for (EncryptTableRuleConfiguration each : ruleConfig.getTables()) {
- each.getColumns().forEach(columnRuleConfig ->
checkStandardEncryptorType(columnRuleConfig, standardEncryptors));
- each.getColumns().forEach(columnRuleConfig ->
checkAssistedQueryEncryptorType(columnRuleConfig, assistedEncryptors));
- each.getColumns().forEach(columnRuleConfig ->
checkLikeQueryEncryptorType(columnRuleConfig, likeEncryptors));
- tables.put(each.getName().toLowerCase(), new EncryptTable(each,
standardEncryptors, assistedEncryptors, likeEncryptors));
+ each.getColumns().forEach(columnRuleConfig ->
checkEncryptorType(columnRuleConfig, encryptors));
+ tables.put(each.getName().toLowerCase(), new EncryptTable(each,
encryptors));
tableNamesMapper.put(each.getName());
}
}
@@ -79,46 +71,24 @@ public final class EncryptRule implements DatabaseRule,
TableContainedRule {
public EncryptRule(final String databaseName, final
CompatibleEncryptRuleConfiguration ruleConfig) {
this.databaseName = databaseName;
configuration = ruleConfig;
- Map<String, StandardEncryptAlgorithm> standardEncryptors = new
LinkedHashMap<>();
- Map<String, AssistedEncryptAlgorithm> assistedEncryptors = new
LinkedHashMap<>();
- Map<String, LikeEncryptAlgorithm> likeEncryptors = new
LinkedHashMap<>();
- ruleConfig.getEncryptors().forEach((key, value) -> putAllEncryptors(
- key, TypedSPILoader.getService(EncryptAlgorithm.class,
value.getType(), value.getProps()), standardEncryptors, assistedEncryptors,
likeEncryptors));
+ Map<String, EncryptAlgorithm> encryptors = new LinkedHashMap<>();
+ ruleConfig.getEncryptors().forEach((key, value) -> encryptors.put(key,
TypedSPILoader.getService(EncryptAlgorithm.class, value.getType(),
value.getProps())));
for (EncryptTableRuleConfiguration each : ruleConfig.getTables()) {
- each.getColumns().forEach(columnRuleConfig ->
checkStandardEncryptorType(columnRuleConfig, standardEncryptors));
- each.getColumns().forEach(columnRuleConfig ->
checkAssistedQueryEncryptorType(columnRuleConfig, assistedEncryptors));
- each.getColumns().forEach(columnRuleConfig ->
checkLikeQueryEncryptorType(columnRuleConfig, likeEncryptors));
- tables.put(each.getName().toLowerCase(), new EncryptTable(each,
standardEncryptors, assistedEncryptors, likeEncryptors));
+ tables.put(each.getName().toLowerCase(), new EncryptTable(each,
encryptors));
tableNamesMapper.put(each.getName());
}
}
- private void putAllEncryptors(final String encryptorName, final
EncryptAlgorithm algorithm, final Map<String, StandardEncryptAlgorithm>
standardEncryptors,
- final Map<String, AssistedEncryptAlgorithm>
assistedEncryptors, final Map<String, LikeEncryptAlgorithm> likeEncryptors) {
- if (algorithm instanceof StandardEncryptAlgorithm) {
- standardEncryptors.put(encryptorName, (StandardEncryptAlgorithm)
algorithm);
- }
- if (algorithm instanceof AssistedEncryptAlgorithm) {
- assistedEncryptors.put(encryptorName, (AssistedEncryptAlgorithm)
algorithm);
- }
- if (algorithm instanceof LikeEncryptAlgorithm) {
- likeEncryptors.put(encryptorName, (LikeEncryptAlgorithm)
algorithm);
- }
- }
-
- private void checkStandardEncryptorType(final
EncryptColumnRuleConfiguration columnRuleConfig, final Map<String,
StandardEncryptAlgorithm> standardEncryptors) {
-
ShardingSpherePreconditions.checkState(standardEncryptors.containsKey(columnRuleConfig.getCipher().getEncryptorName()),
- () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Cipher",
columnRuleConfig.getCipher().getEncryptorName(),
StandardEncryptAlgorithm.class.getSimpleName()));
- }
-
- private void checkAssistedQueryEncryptorType(final
EncryptColumnRuleConfiguration columnRuleConfig, final Map<String,
AssistedEncryptAlgorithm> assistedEncryptors) {
- columnRuleConfig.getAssistedQuery().ifPresent(optional ->
ShardingSpherePreconditions.checkState(assistedEncryptors.containsKey(optional.getEncryptorName()),
- () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Assisted query",
optional.getEncryptorName(), AssistedEncryptAlgorithm.class.getSimpleName())));
- }
-
- private void checkLikeQueryEncryptorType(final
EncryptColumnRuleConfiguration columnRuleConfig, final Map<String,
LikeEncryptAlgorithm> likeEncryptors) {
- columnRuleConfig.getLikeQuery().ifPresent(optional ->
ShardingSpherePreconditions.checkState(likeEncryptors.containsKey(optional.getEncryptorName()),
- () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Like query",
optional.getEncryptorName(), LikeEncryptAlgorithm.class.getSimpleName())));
+ private void checkEncryptorType(final EncryptColumnRuleConfiguration
columnRuleConfig, final Map<String, EncryptAlgorithm> encryptors) {
+
ShardingSpherePreconditions.checkState(encryptors.containsKey(columnRuleConfig.getCipher().getEncryptorName())
+ &&
encryptors.get(columnRuleConfig.getCipher().getEncryptorName()).getMetaData().isSupportDecrypt(),
+ () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Cipher",
columnRuleConfig.getCipher().getEncryptorName(), "decrypt"));
+ columnRuleConfig.getAssistedQuery().ifPresent(optional ->
ShardingSpherePreconditions.checkState(encryptors.containsKey(optional.getEncryptorName())
+ &&
encryptors.get(optional.getEncryptorName()).getMetaData().isSupportEquivalentFilter(),
+ () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Assisted query",
columnRuleConfig.getCipher().getEncryptorName(), "equivalent filter")));
+ columnRuleConfig.getLikeQuery().ifPresent(optional ->
ShardingSpherePreconditions.checkState(encryptors.containsKey(optional.getEncryptorName())
+ &&
encryptors.get(optional.getEncryptorName()).getMetaData().isSupportLike(),
+ () -> new
MismatchedEncryptAlgorithmTypeException(databaseName, "Like query",
columnRuleConfig.getCipher().getEncryptorName(), "like")));
}
/**
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
index a364e18bd27..e48321d4a49 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
@@ -21,15 +21,13 @@ import com.cedarsoftware.util.CaseInsensitiveMap;
import lombok.Getter;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptColumnNotFoundException;
import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptLogicColumnNotFoundException;
import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.encrypt.rule.column.item.AssistedQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import java.util.Collection;
@@ -47,29 +45,26 @@ public final class EncryptTable {
private final Map<String, EncryptColumn> columns;
- public EncryptTable(final EncryptTableRuleConfiguration config, final
Map<String, StandardEncryptAlgorithm> standardEncryptors,
- final Map<String, AssistedEncryptAlgorithm>
assistedEncryptors, final Map<String, LikeEncryptAlgorithm> likeEncryptors) {
+ public EncryptTable(final EncryptTableRuleConfiguration config, final
Map<String, EncryptAlgorithm> encryptors) {
table = config.getName();
- columns = createEncryptColumns(config, standardEncryptors,
assistedEncryptors, likeEncryptors);
+ columns = createEncryptColumns(config, encryptors);
}
- private Map<String, EncryptColumn> createEncryptColumns(final
EncryptTableRuleConfiguration config, final Map<String,
StandardEncryptAlgorithm> standardEncryptors,
- final Map<String,
AssistedEncryptAlgorithm> assistedEncryptors, final Map<String,
LikeEncryptAlgorithm> likeEncryptors) {
+ private Map<String, EncryptColumn> createEncryptColumns(final
EncryptTableRuleConfiguration config, final Map<String, EncryptAlgorithm>
encryptors) {
Map<String, EncryptColumn> result = new CaseInsensitiveMap<>();
for (EncryptColumnRuleConfiguration each : config.getColumns()) {
- result.put(each.getName(), createEncryptColumn(each,
standardEncryptors, assistedEncryptors, likeEncryptors));
+ result.put(each.getName(), createEncryptColumn(each, encryptors));
}
return result;
}
- private EncryptColumn createEncryptColumn(final
EncryptColumnRuleConfiguration config, final Map<String,
StandardEncryptAlgorithm> standardEncryptors,
- final Map<String,
AssistedEncryptAlgorithm> assistedEncryptors, final Map<String,
LikeEncryptAlgorithm> likeEncryptors) {
- EncryptColumn result = new EncryptColumn(config.getName(), new
CipherColumnItem(config.getCipher().getName(),
standardEncryptors.get(config.getCipher().getEncryptorName())));
+ private EncryptColumn createEncryptColumn(final
EncryptColumnRuleConfiguration config, final Map<String, EncryptAlgorithm>
encryptors) {
+ EncryptColumn result = new EncryptColumn(config.getName(), new
CipherColumnItem(config.getCipher().getName(),
encryptors.get(config.getCipher().getEncryptorName())));
if (config.getAssistedQuery().isPresent()) {
- result.setAssistedQuery(new
AssistedQueryColumnItem(config.getAssistedQuery().get().getName(),
assistedEncryptors.get(config.getAssistedQuery().get().getEncryptorName())));
+ result.setAssistedQuery(new
AssistedQueryColumnItem(config.getAssistedQuery().get().getName(),
encryptors.get(config.getAssistedQuery().get().getEncryptorName())));
}
if (config.getLikeQuery().isPresent()) {
- result.setLikeQuery(new
LikeQueryColumnItem(config.getLikeQuery().get().getName(),
likeEncryptors.get(config.getLikeQuery().get().getEncryptorName())));
+ result.setLikeQuery(new
LikeQueryColumnItem(config.getLikeQuery().get().getName(),
encryptors.get(config.getLikeQuery().get().getEncryptorName())));
}
return result;
}
@@ -80,7 +75,7 @@ public final class EncryptTable {
* @param logicColumnName logic column name
* @return found encryptor
*/
- public Optional<StandardEncryptAlgorithm> findEncryptor(final String
logicColumnName) {
+ public Optional<EncryptAlgorithm> findEncryptor(final String
logicColumnName) {
return columns.containsKey(logicColumnName) ?
Optional.of(columns.get(logicColumnName).getCipher().getEncryptor()) :
Optional.empty();
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/AssistedQueryColumnItem.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/AssistedQueryColumnItem.java
index 9c69ed86c5d..ce42985593d 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/AssistedQueryColumnItem.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/AssistedQueryColumnItem.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.encrypt.rule.column.item;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import java.util.LinkedList;
import java.util.List;
@@ -30,13 +30,12 @@ import java.util.List;
* Assisted query column item.
*/
@RequiredArgsConstructor
+@Getter
public final class AssistedQueryColumnItem {
- @Getter
private final String name;
- @Getter
- private final AssistedEncryptAlgorithm encryptor;
+ private final EncryptAlgorithm encryptor;
/**
* Get encrypt assisted query value.
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItem.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItem.java
index 16a799e4062..afc9c32b645 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItem.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItem.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.encrypt.rule.column.item;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import java.util.LinkedList;
import java.util.List;
@@ -35,7 +35,7 @@ public final class CipherColumnItem {
private final String name;
- private final StandardEncryptAlgorithm encryptor;
+ private final EncryptAlgorithm encryptor;
/**
* Encrypt.
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/LikeQueryColumnItem.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/LikeQueryColumnItem.java
index 4003f6853cb..49b929e2941 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/LikeQueryColumnItem.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/column/item/LikeQueryColumnItem.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.encrypt.rule.column.item;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import java.util.LinkedList;
import java.util.List;
@@ -35,7 +35,7 @@ public final class LikeQueryColumnItem {
@Getter
private final String name;
- private final LikeEncryptAlgorithm encryptor;
+ private final EncryptAlgorithm encryptor;
/**
* Get encrypt like query value.
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
index f2c2207a747..fc2e32a199b 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.encrypt.algorithm.assisted;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -33,11 +32,11 @@ import static org.mockito.Mockito.mock;
class MD5AssistedEncryptAlgorithmTest {
- private AssistedEncryptAlgorithm encryptAlgorithm;
+ private EncryptAlgorithm encryptAlgorithm;
@BeforeEach
void setUp() {
- encryptAlgorithm = (AssistedEncryptAlgorithm)
TypedSPILoader.getService(EncryptAlgorithm.class, "MD5");
+ encryptAlgorithm = TypedSPILoader.getService(EncryptAlgorithm.class,
"MD5");
}
@Test
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
index 766a877538d..c0827e0fdcf 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.encrypt.algorithm.standard;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -42,11 +41,11 @@ import static org.mockito.Mockito.times;
class AESEncryptAlgorithmTest {
- private StandardEncryptAlgorithm encryptAlgorithm;
+ private EncryptAlgorithm encryptAlgorithm;
@BeforeEach
void setUp() {
- encryptAlgorithm = (StandardEncryptAlgorithm)
TypedSPILoader.getService(EncryptAlgorithm.class, "AES",
PropertiesBuilder.build(new Property("aes-key-value", "test")));
+ encryptAlgorithm = TypedSPILoader.getService(EncryptAlgorithm.class,
"AES", PropertiesBuilder.build(new Property("aes-key-value", "test")));
}
@Test
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreEncryptAlgorithmFixture.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreEncryptAlgorithmFixture.java
index 3e332ac8e0c..5b7a199da87 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreEncryptAlgorithmFixture.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreEncryptAlgorithmFixture.java
@@ -17,10 +17,15 @@
package org.apache.shardingsphere.encrypt.fixture;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class CoreEncryptAlgorithmFixture implements
StandardEncryptAlgorithm {
+@Getter
+public final class CoreEncryptAlgorithmFixture implements EncryptAlgorithm {
+
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData();
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
index 38e2ab8b39a..7943f6bfa77 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
@@ -17,16 +17,35 @@
package org.apache.shardingsphere.encrypt.fixture;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class CoreQueryAssistedEncryptAlgorithmFixture implements
AssistedEncryptAlgorithm {
+import java.util.Properties;
+
+@Getter
+public final class CoreQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private EncryptAlgorithmMetaData metaData;
+
+ @Override
+ public void init(final Properties props) {
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
+ }
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
return "assistedEncryptValue";
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "CORE.QUERY_ASSISTED.FIXTURE";
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
index 6fb9e9aa211..ca2231bb0a1 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
@@ -17,16 +17,37 @@
package org.apache.shardingsphere.encrypt.fixture;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class CoreQueryLikeEncryptAlgorithmFixture implements
LikeEncryptAlgorithm {
+import java.util.Properties;
+
+@Getter
+public final class CoreQueryLikeEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private EncryptAlgorithmMetaData metaData;
+
+ @Override
+ public void init(final Properties props) {
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportLike(true);
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ encryptAlgorithmMetaData.setSupportEquivalentFilter(false);
+ metaData = encryptAlgorithmMetaData;
+ }
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
return "likeEncryptValue";
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "CORE.QUERY_LIKE.FIXTURE";
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/DecoratedEncryptShowCreateTableMergedResultTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/DecoratedEncryptShowCreateTableMergedResultTest.java
index 52b3075670a..3eaa8e52b2f 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/DecoratedEncryptShowCreateTableMergedResultTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/DecoratedEncryptShowCreateTableMergedResultTest.java
@@ -95,7 +95,7 @@ class DecoratedEncryptShowCreateTableMergedResultTest {
private EncryptRule mockEncryptRule(final
Collection<EncryptColumnRuleConfiguration> encryptColumnRuleConfigs) {
EncryptRule result = mock(EncryptRule.class);
- EncryptTable encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt", encryptColumnRuleConfigs),
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
+ EncryptTable encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt", encryptColumnRuleConfigs),
Collections.emptyMap());
when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/MergedEncryptShowCreateTableMergedResultTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/MergedEncryptShowCreateTableMergedResultTest.java
index 3d16057d715..d151f935e51 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/MergedEncryptShowCreateTableMergedResultTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/MergedEncryptShowCreateTableMergedResultTest.java
@@ -93,7 +93,7 @@ class MergedEncryptShowCreateTableMergedResultTest {
private EncryptRule mockEncryptRule(final
Collection<EncryptColumnRuleConfiguration> columnRuleConfigs) {
EncryptRule result = mock(EncryptRule.class);
- EncryptTable encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt", columnRuleConfigs),
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
+ EncryptTable encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt", columnRuleConfigs),
Collections.emptyMap());
when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
index 60bccb82679..f53565e6602 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptColumnToken;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
@@ -27,6 +24,7 @@ import
org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.encrypt.rule.column.item.AssistedQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
@@ -79,17 +77,17 @@ class EncryptAlterTableTokenGeneratorTest {
}
private EncryptColumn mockEncryptColumn() {
- EncryptColumn result = new EncryptColumn("certificate_number", new
CipherColumnItem("cipher_certificate_number",
mock(StandardEncryptAlgorithm.class)));
- result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number",
mock(AssistedEncryptAlgorithm.class)));
- result.setLikeQuery(new LikeQueryColumnItem("like_certificate_number",
mock(LikeEncryptAlgorithm.class)));
+ EncryptColumn result = new EncryptColumn("certificate_number", new
CipherColumnItem("cipher_certificate_number", mock(EncryptAlgorithm.class)));
+ result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number",
mock(EncryptAlgorithm.class)));
+ result.setLikeQuery(new LikeQueryColumnItem("like_certificate_number",
mock(EncryptAlgorithm.class)));
return result;
}
private EncryptColumn mockNewEncryptColumn() {
EncryptColumn result = new EncryptColumn(
- "certificate_number_new", new
CipherColumnItem("cipher_certificate_number_new",
mock(StandardEncryptAlgorithm.class)));
- result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number_new",
mock(AssistedEncryptAlgorithm.class)));
- result.setLikeQuery(new
LikeQueryColumnItem("like_certificate_number_new",
mock(LikeEncryptAlgorithm.class)));
+ "certificate_number_new", new
CipherColumnItem("cipher_certificate_number_new",
mock(EncryptAlgorithm.class)));
+ result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number_new",
mock(EncryptAlgorithm.class)));
+ result.setLikeQuery(new
LikeQueryColumnItem("like_certificate_number_new",
mock(EncryptAlgorithm.class)));
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
index c1110657335..4cc537649cf 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
@@ -17,9 +17,6 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptColumnToken;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
@@ -27,6 +24,7 @@ import
org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.encrypt.rule.column.item.AssistedQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.CipherColumnItem;
import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
@@ -73,9 +71,9 @@ class EncryptCreateTableTokenGeneratorTest {
}
private EncryptColumn mockEncryptColumn() {
- EncryptColumn result = new EncryptColumn("certificate_number", new
CipherColumnItem("cipher_certificate_number",
mock(StandardEncryptAlgorithm.class)));
- result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number",
mock(AssistedEncryptAlgorithm.class)));
- result.setLikeQuery(new LikeQueryColumnItem("like_certificate_number",
mock(LikeEncryptAlgorithm.class)));
+ EncryptColumn result = new EncryptColumn("certificate_number", new
CipherColumnItem("cipher_certificate_number", mock(EncryptAlgorithm.class)));
+ result.setAssistedQuery(new
AssistedQueryColumnItem("assisted_certificate_number",
mock(EncryptAlgorithm.class)));
+ result.setLikeQuery(new LikeQueryColumnItem("like_certificate_number",
mock(EncryptAlgorithm.class)));
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertDerivedColumnsTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertDerivedColumnsTokenGeneratorTest.java
index 17256a124b0..ac749910b9e 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertDerivedColumnsTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertDerivedColumnsTokenGeneratorTest.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.encrypt.rewrite.token.generator.insert;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import
org.apache.shardingsphere.encrypt.rule.column.item.AssistedQueryColumnItem;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
@@ -91,7 +91,7 @@ class EncryptInsertDerivedColumnsTokenGeneratorTest {
EncryptRule result = mock(EncryptRule.class);
EncryptTable encryptTable = mock(EncryptTable.class,
RETURNS_DEEP_STUBS);
when(encryptTable.isEncryptColumn("foo_col")).thenReturn(true);
-
when(encryptTable.getEncryptColumn("foo_col").getAssistedQuery()).thenReturn(Optional.of(new
AssistedQueryColumnItem("assisted_query_col",
mock(AssistedEncryptAlgorithm.class))));
+
when(encryptTable.getEncryptColumn("foo_col").getAssistedQuery()).thenReturn(Optional.of(new
AssistedQueryColumnItem("assisted_query_col", mock(EncryptAlgorithm.class))));
when(result.getEncryptTable("foo_tbl")).thenReturn(encryptTable);
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
index 8442ec305ef..933d6ea36e1 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.encrypt.rule;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptLogicColumnNotFoundException;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -45,7 +45,7 @@ class EncryptTableTest {
columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("assistedQueryColumn",
"foo_assist_query_encryptor"));
columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("likeQueryColumn", "foo_like_encryptor"));
encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt",
- Collections.singleton(columnRuleConfig)),
Collections.singletonMap("myEncryptor", mock(StandardEncryptAlgorithm.class)),
Collections.emptyMap(), Collections.emptyMap());
+ Collections.singleton(columnRuleConfig)),
Collections.singletonMap("myEncryptor", mock(EncryptAlgorithm.class)));
}
@Test
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
index 58b6b1c4264..3d60ad54253 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java
@@ -25,9 +25,6 @@ import
org.apache.shardingsphere.distsql.handler.type.rdl.RuleDefinitionCreateUp
import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleStatementConverter;
import
org.apache.shardingsphere.encrypt.distsql.segment.EncryptColumnItemSegment;
import org.apache.shardingsphere.encrypt.distsql.segment.EncryptRuleSegment;
@@ -60,18 +57,35 @@ public final class CreateEncryptRuleStatementUpdater
implements RuleDefinitionCr
private void checkAlgorithmTypes(final CreateEncryptRuleStatement
sqlStatement) {
sqlStatement.getRules().stream().flatMap(each ->
each.getColumns().stream()).forEach(each -> {
- checkAlgorithmType(each.getCipher(), "standard encrypt",
StandardEncryptAlgorithm.class);
- checkAlgorithmType(each.getLikeQuery(), "like encrypt",
LikeEncryptAlgorithm.class);
- checkAlgorithmType(each.getAssistedQuery(), "assisted encrypt",
AssistedEncryptAlgorithm.class);
+ checkStandardAlgorithmType(each.getCipher());
+ checkLikeAlgorithmType(each.getLikeQuery());
+ checkAssistedAlgorithmType(each.getAssistedQuery());
});
}
- private void checkAlgorithmType(final EncryptColumnItemSegment
itemSegment, final String algorithmType, final Class<?> encryptAlgorithmClass) {
+ private void checkStandardAlgorithmType(final EncryptColumnItemSegment
itemSegment) {
if (null == itemSegment || null == itemSegment.getEncryptor()) {
return;
}
EncryptAlgorithm encryptAlgorithm =
TypedSPILoader.getService(EncryptAlgorithm.class,
itemSegment.getEncryptor().getName(), itemSegment.getEncryptor().getProps());
-
ShardingSpherePreconditions.checkState(encryptAlgorithmClass.isInstance(encryptAlgorithm),
() -> new InvalidAlgorithmConfigurationException(algorithmType,
encryptAlgorithm.getType()));
+
ShardingSpherePreconditions.checkState(encryptAlgorithm.getMetaData().isSupportDecrypt(),
() -> new InvalidAlgorithmConfigurationException("standard encrypt",
encryptAlgorithm.getType()));
+ }
+
+ private void checkLikeAlgorithmType(final EncryptColumnItemSegment
itemSegment) {
+ if (null == itemSegment || null == itemSegment.getEncryptor()) {
+ return;
+ }
+ EncryptAlgorithm encryptAlgorithm =
TypedSPILoader.getService(EncryptAlgorithm.class,
itemSegment.getEncryptor().getName(), itemSegment.getEncryptor().getProps());
+
ShardingSpherePreconditions.checkState(encryptAlgorithm.getMetaData().isSupportLike(),
() -> new InvalidAlgorithmConfigurationException("like encrypt",
encryptAlgorithm.getType()));
+ }
+
+ private void checkAssistedAlgorithmType(final EncryptColumnItemSegment
itemSegment) {
+ if (null == itemSegment || null == itemSegment.getEncryptor()) {
+ return;
+ }
+ EncryptAlgorithm encryptAlgorithm =
TypedSPILoader.getService(EncryptAlgorithm.class,
itemSegment.getEncryptor().getName(), itemSegment.getEncryptor().getProps());
+
ShardingSpherePreconditions.checkState(encryptAlgorithm.getMetaData().isSupportEquivalentFilter(),
+ () -> new InvalidAlgorithmConfigurationException("assisted
encrypt", encryptAlgorithm.getType()));
}
private void checkDuplicateRuleNames(final String databaseName, final
CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration
currentRuleConfig) {
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/fixture/DistSQLEncryptAlgorithmFixture.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/fixture/DistSQLEncryptAlgorithmFixture.java
index 66c7ea3b755..60b7cb9658b 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/fixture/DistSQLEncryptAlgorithmFixture.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/fixture/DistSQLEncryptAlgorithmFixture.java
@@ -17,10 +17,15 @@
package org.apache.shardingsphere.encrypt.distsql.handler.fixture;
+import lombok.Getter;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-public final class DistSQLEncryptAlgorithmFixture implements
StandardEncryptAlgorithm {
+@Getter
+public final class DistSQLEncryptAlgorithmFixture implements EncryptAlgorithm {
+
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData();
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
diff --git
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCEncryptAlgorithmFixture.java
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCEncryptAlgorithmFixture.java
index 294bd23ef9e..114b7c7d3a0 100644
---
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCEncryptAlgorithmFixture.java
+++
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCEncryptAlgorithmFixture.java
@@ -17,10 +17,15 @@
package org.apache.shardingsphere.test.e2e.driver.fixture.encrypt;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class JDBCEncryptAlgorithmFixture implements
StandardEncryptAlgorithm {
+@Getter
+public final class JDBCEncryptAlgorithmFixture implements EncryptAlgorithm {
+
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData();
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
diff --git
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
index 516fcb9419d..f5405383ef2 100644
---
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
+++
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
@@ -17,16 +17,35 @@
package org.apache.shardingsphere.test.e2e.driver.fixture.encrypt;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class JDBCQueryAssistedEncryptAlgorithmFixture implements
AssistedEncryptAlgorithm {
+import java.util.Properties;
+
+@Getter
+public final class JDBCQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private EncryptAlgorithmMetaData metaData;
+
+ @Override
+ public void init(final Properties props) {
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
+ }
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
return "assistedEncryptValue";
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "JDBC.QUERY_ASSISTED.FIXTURE";
diff --git
a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
index 42acf4f43ee..2e86de97152 100644
---
a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
+++
b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
@@ -18,10 +18,12 @@
package org.apache.shardingsphere.test.e2e.fixture;
import com.google.common.base.Strings;
+import lombok.Getter;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import lombok.SneakyThrows;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import java.io.IOException;
import java.io.InputStream;
@@ -32,7 +34,7 @@ import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-public final class ITEncryptLikeAlgorithmFixture implements
LikeEncryptAlgorithm {
+public final class ITEncryptLikeAlgorithmFixture implements EncryptAlgorithm {
private static final String DELTA_KEY = "delta";
@@ -58,12 +60,19 @@ public final class ITEncryptLikeAlgorithmFixture implements
LikeEncryptAlgorithm
private Map<Character, Integer> charIndexes;
+ @Getter
+ private EncryptAlgorithmMetaData metaData;
+
@Override
public void init(final Properties props) {
delta = createDelta(props);
mask = createMask(props);
start = createStart(props);
charIndexes = createCharIndexes(props);
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportLike(true);
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
}
private int createDelta(final Properties props) {
@@ -125,6 +134,11 @@ public final class ITEncryptLikeAlgorithmFixture
implements LikeEncryptAlgorithm
return null == plainValue ? null : digest(String.valueOf(plainValue));
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
private String digest(final String plainValue) {
StringBuilder result = new StringBuilder(plainValue.length());
for (char each : plainValue.toCharArray()) {
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteNormalEncryptAlgorithmFixture.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteNormalEncryptAlgorithmFixture.java
index 00f04881178..69c204bbc26 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteNormalEncryptAlgorithmFixture.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteNormalEncryptAlgorithmFixture.java
@@ -17,10 +17,15 @@
package org.apache.shardingsphere.test.it.rewrite.fixture.encrypt;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class RewriteNormalEncryptAlgorithmFixture implements
StandardEncryptAlgorithm {
+@Getter
+public final class RewriteNormalEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData();
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
index bec30f18926..34e0818aed4 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
@@ -17,10 +17,24 @@
package org.apache.shardingsphere.test.it.rewrite.fixture.encrypt;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class RewriteQueryAssistedEncryptAlgorithmFixture implements
AssistedEncryptAlgorithm {
+import java.util.Properties;
+
+@Getter
+public final class RewriteQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private EncryptAlgorithmMetaData metaData;
+
+ @Override
+ public void init(final Properties props) {
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
+ }
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
@@ -30,6 +44,11 @@ public final class
RewriteQueryAssistedEncryptAlgorithmFixture implements Assist
return "assisted_query_" + plainValue;
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "REWRITE.ASSISTED_QUERY.FIXTURE";
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
index 6ee95b055ea..61bd34ba541 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
@@ -17,16 +17,36 @@
package org.apache.shardingsphere.test.it.rewrite.fixture.encrypt;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import org.apache.shardingsphere.encrypt.api.encrypt.like.LikeEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
-public final class RewriteQueryLikeEncryptAlgorithmFixture implements
LikeEncryptAlgorithm {
+import java.util.Properties;
+
+@Getter
+public final class RewriteQueryLikeEncryptAlgorithmFixture implements
EncryptAlgorithm {
+
+ private EncryptAlgorithmMetaData metaData;
+
+ @Override
+ public void init(final Properties props) {
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportLike(true);
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
+ }
@Override
public String encrypt(final Object plainValue, final EncryptContext
encryptContext) {
return null == plainValue ? null : "like_query_" + plainValue;
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "REWRITE.LIKE_QUERY.FIXTURE";
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
index 464c00a5225..41ffd1e5712 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
@@ -19,19 +19,24 @@ package
org.apache.shardingsphere.test.natived.jdbc.commons.algorithm;
import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
-import
org.apache.shardingsphere.encrypt.api.encrypt.assisted.AssistedEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import java.util.Properties;
-@SuppressWarnings("LombokGetterMayBeUsed")
-public final class TestQueryAssistedShardingEncryptAlgorithm implements
AssistedEncryptAlgorithm {
+@Getter
+public final class TestQueryAssistedShardingEncryptAlgorithm implements
EncryptAlgorithm {
- @Getter
private Properties properties;
+ private EncryptAlgorithmMetaData metaData;
+
@Override
public void init(final Properties props) {
this.properties = props;
+ EncryptAlgorithmMetaData encryptAlgorithmMetaData = new
EncryptAlgorithmMetaData();
+ encryptAlgorithmMetaData.setSupportDecrypt(false);
+ metaData = encryptAlgorithmMetaData;
}
@Override
@@ -39,6 +44,11 @@ public final class TestQueryAssistedShardingEncryptAlgorithm
implements Assisted
return "assistedEncryptValue";
}
+ @Override
+ public Object decrypt(final Object cipherValue, final EncryptContext
encryptContext) {
+ throw new UnsupportedOperationException(String.format("Algorithm `%s`
is unsupported to decrypt", getType()));
+ }
+
@Override
public String getType() {
return "assistedTest";