This is an automated email from the ASF dual-hosted git repository.
panjuan 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 a1fd42e3249 Modify encrypt rule configuration to new structure (#25548)
a1fd42e3249 is described below
commit a1fd42e3249a64c62be18bfdd3b68da2a38bcd41
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed May 10 13:44:36 2023 +0800
Modify encrypt rule configuration to new structure (#25548)
---
.../rule/EncryptColumnItemRuleConfiguration.java} | 22 ++++----
.../rule/EncryptColumnRuleConfiguration.java | 34 ++++++++----
.../checker/EncryptRuleConfigurationChecker.java | 48 ++++++++--------
.../generator/EncryptAlterTableTokenGenerator.java | 11 ++--
.../shardingsphere/encrypt/rule/EncryptColumn.java | 35 +++++-------
.../EncryptColumnItem.java} | 22 ++++----
.../shardingsphere/encrypt/rule/EncryptTable.java | 44 +++++++++------
...=> YamlCompatibleEncryptRuleConfiguration.java} | 9 ++-
...lCompatibleEncryptColumnRuleConfiguration.java} | 5 +-
...mlCompatibleEncryptTableRuleConfiguration.java} | 7 ++-
...CompatibleEncryptRuleConfigurationSwapper.java} | 27 +++++----
...tibleEncryptColumnRuleConfigurationSwapper.java | 64 ++++++++++++++++++++++
...tibleEncryptTableRuleConfigurationSwapper.java} | 23 ++++----
.../YamlEncryptColumnRuleConfigurationSwapper.java | 48 ----------------
...onfig.swapper.rule.YamlRuleConfigurationSwapper | 2 +-
.../EncryptRuleConfigurationCheckerTest.java | 17 ++++--
...atedEncryptShowCreateTableMergedResultTest.java | 17 ++++--
...rgedEncryptShowCreateTableMergedResultTest.java | 10 +++-
.../impl/EncryptAlterTableTokenGeneratorTest.java | 11 +++-
.../impl/EncryptCreateTableTokenGeneratorTest.java | 12 ++--
.../impl/EncryptProjectionTokenGeneratorTest.java | 4 +-
.../fixture/EncryptGeneratorFixtureBuilder.java | 5 +-
.../encrypt/rule/EncryptColumnTest.java | 10 +++-
.../encrypt/rule/EncryptRuleTest.java | 30 +++++-----
.../encrypt/rule/EncryptTableTest.java | 7 ++-
.../yaml/EncryptRuleConfigurationYamlIT.java | 10 ++--
...atibleEncryptRuleConfigurationSwapperTest.java} | 18 +++---
...EncryptColumnRuleConfigurationSwapperTest.java} | 31 ++++++-----
...eEncryptTableRuleConfigurationSwapperTest.java} | 47 +++++++++-------
.../converter/EncryptRuleStatementConverter.java | 11 +++-
.../handler/query/ShowEncryptRuleExecutor.java | 15 ++---
.../update/AlterEncryptRuleStatementUpdater.java | 10 ++--
.../update/DropEncryptRuleStatementUpdater.java | 14 +++--
.../EncryptRuleStatementConverterTest.java | 10 ++--
.../handler/query/ShowEncryptRuleExecutorTest.java | 5 +-
.../AlterEncryptRuleStatementUpdaterTest.java | 3 +-
.../DropEncryptRuleStatementUpdaterTest.java | 8 ++-
.../EncryptRuleConfigurationImportChecker.java | 9 ++-
.../ConvertYamlConfigurationExecutor.java | 37 +++++++------
.../YamlDatabaseConfigurationImportExecutor.java | 10 ++--
.../config/ProxyConfigurationLoaderTest.java | 14 +++--
41 files changed, 455 insertions(+), 321 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnItemRuleConfiguration.java
similarity index 64%
copy from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
copy to
features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnItemRuleConfiguration.java
index 3738a9329b6..2077bc44467 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnItemRuleConfiguration.java
@@ -15,23 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.yaml.config.rule;
+package org.apache.shardingsphere.encrypt.api.config.rule;
import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
+import lombok.RequiredArgsConstructor;
/**
- * Encrypt table rule configuration for YAML.
+ * Encrypt column item rule configuration.
*/
+@RequiredArgsConstructor
@Getter
-@Setter
-public final class YamlEncryptTableRuleConfiguration implements
YamlConfiguration {
+public final class EncryptColumnItemRuleConfiguration {
+
+ private final String name;
- private String name;
+ private final String encryptorName;
- private Map<String, YamlEncryptColumnRuleConfiguration> columns = new
LinkedHashMap<>();
+ public EncryptColumnItemRuleConfiguration(final String name) {
+ this(name, null);
+ }
}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
index 4dc68494e1a..2e9abe2824d 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
@@ -19,29 +19,41 @@ package org.apache.shardingsphere.encrypt.api.config.rule;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+
+import java.util.Optional;
/**
* Encrypt column rule configuration.
*/
@RequiredArgsConstructor
@Getter
+@Setter
public final class EncryptColumnRuleConfiguration {
- private final String logicColumn;
-
- private final String cipherColumn;
+ private final String name;
- private final String assistedQueryColumn;
+ private final EncryptColumnItemRuleConfiguration cipher;
- private final String likeQueryColumn;
+ private EncryptColumnItemRuleConfiguration assistedQuery;
- private final String encryptorName;
+ private EncryptColumnItemRuleConfiguration likeQuery;
- private final String assistedQueryEncryptorName;
-
- private final String likeQueryEncryptorName;
+ /**
+ * Get assisted query.
+ *
+ * @return assisted query column item rule configuration
+ */
+ public Optional<EncryptColumnItemRuleConfiguration> getAssistedQuery() {
+ return Optional.ofNullable(assistedQuery);
+ }
- public EncryptColumnRuleConfiguration(final String logicColumn, final
String cipherColumn, final String assistedQueryColumn, final String
likeQueryColumn, final String encryptorName) {
- this(logicColumn, cipherColumn, assistedQueryColumn, likeQueryColumn,
encryptorName, null, null);
+ /**
+ * Get like query.
+ *
+ * @return like query column item rule configuration
+ */
+ public Optional<EncryptColumnItemRuleConfiguration> getLikeQuery() {
+ return Optional.ofNullable(likeQuery);
}
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
index 84dbdd314eb..9269c4074a4 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.encrypt.checker;
import com.google.common.base.Strings;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.constant.EncryptOrder;
@@ -49,41 +50,42 @@ public final class EncryptRuleConfigurationChecker
implements RuleConfigurationC
private void checkTableConfiguration(final String databaseName, final
Collection<EncryptTableRuleConfiguration> tables, final Collection<String>
encryptors) {
for (EncryptTableRuleConfiguration each : tables) {
for (EncryptColumnRuleConfiguration column : each.getColumns()) {
- checkCipherColumnConfiguration(databaseName, encryptors,
column);
- checkAssistColumnConfiguration(databaseName, encryptors,
column);
- checkLikeColumnConfiguration(databaseName, encryptors, column);
+ checkCipherColumnConfiguration(databaseName, encryptors,
column.getCipher(), column.getName());
+ column.getAssistedQuery().ifPresent(optional ->
checkAssistColumnConfiguration(databaseName, encryptors, optional,
column.getName()));
+ column.getLikeQuery().ifPresent(optional ->
checkLikeColumnConfiguration(databaseName, encryptors, optional,
column.getName()));
}
}
}
- private void checkCipherColumnConfiguration(final String databaseName,
final Collection<String> encryptors, final EncryptColumnRuleConfiguration
column) {
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getCipherColumn()),
() -> new EncryptCipherColumnNotFoundException(column.getLogicColumn(),
databaseName));
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getEncryptorName()),
- () -> new
EncryptEncryptorNotFoundException(String.format("Encryptor name of `%s` can not
be null in database `%s`.", column.getLogicColumn(), databaseName)));
-
ShardingSpherePreconditions.checkState(encryptors.contains(column.getEncryptorName()),
- () -> new EncryptEncryptorNotFoundException(String.format("Can
not find encryptor `%s` in database `%s`.", column.getEncryptorName(),
databaseName)));
+ private void checkCipherColumnConfiguration(final String databaseName,
final Collection<String> encryptors, final EncryptColumnItemRuleConfiguration
cipherColumn, final String logicColumn) {
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumn.getName()),
() -> new EncryptCipherColumnNotFoundException(logicColumn, databaseName));
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumn.getEncryptorName()),
+ () -> new
EncryptEncryptorNotFoundException(String.format("Encryptor name of `%s` can not
be null in database `%s`.", logicColumn, databaseName)));
+
ShardingSpherePreconditions.checkState(encryptors.contains(cipherColumn.getEncryptorName()),
+ () -> new EncryptEncryptorNotFoundException(String.format("Can
not find encryptor `%s` in database `%s`.", cipherColumn.getEncryptorName(),
databaseName)));
}
- private void checkAssistColumnConfiguration(final String databaseName,
final Collection<String> encryptors, final EncryptColumnRuleConfiguration
column) {
- if (Strings.isNullOrEmpty(column.getAssistedQueryColumn()) &&
Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())) {
+ private void checkAssistColumnConfiguration(final String databaseName,
final Collection<String> encryptors, final EncryptColumnItemRuleConfiguration
assistedQueryColumn,
+ final String logicColumn) {
+ if (Strings.isNullOrEmpty(assistedQueryColumn.getName()) &&
Strings.isNullOrEmpty(assistedQueryColumn.getEncryptorName())) {
return;
}
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getAssistedQueryColumn()),
() -> new EncryptAssistedQueryColumnNotFoundException(column.getLogicColumn(),
databaseName));
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName()),
() -> new EncryptAssistedQueryEncryptorNotFoundException(
- String.format("Assisted query encryptor name of `%s` can not
be null in database `%s`.", column.getLogicColumn(), databaseName)));
-
ShardingSpherePreconditions.checkState(encryptors.contains(column.getAssistedQueryEncryptorName()),
() -> new EncryptAssistedQueryEncryptorNotFoundException(
- String.format("Can not find assisted query encryptor `%s` in
database `%s`.", column.getAssistedQueryEncryptorName(), databaseName)));
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumn.getName()),
() -> new EncryptAssistedQueryColumnNotFoundException(logicColumn,
databaseName));
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumn.getEncryptorName()),
() -> new EncryptAssistedQueryEncryptorNotFoundException(
+ String.format("Assisted query encryptor name of `%s` can not
be null in database `%s`.", logicColumn, databaseName)));
+
ShardingSpherePreconditions.checkState(encryptors.contains(assistedQueryColumn.getEncryptorName()),
() -> new EncryptAssistedQueryEncryptorNotFoundException(
+ String.format("Can not find assisted query encryptor `%s` in
database `%s`.", assistedQueryColumn.getEncryptorName(), databaseName)));
}
- private void checkLikeColumnConfiguration(final String databaseName, final
Collection<String> encryptors, final EncryptColumnRuleConfiguration column) {
- if (Strings.isNullOrEmpty(column.getLikeQueryColumn()) &&
Strings.isNullOrEmpty(column.getLikeQueryEncryptorName())) {
+ private void checkLikeColumnConfiguration(final String databaseName, final
Collection<String> encryptors, final EncryptColumnItemRuleConfiguration
likeQueryColumn, final String logicColumn) {
+ if (Strings.isNullOrEmpty(likeQueryColumn.getName()) &&
Strings.isNullOrEmpty(likeQueryColumn.getEncryptorName())) {
return;
}
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getLikeQueryColumn()),
() -> new EncryptLikeQueryColumnNotFoundException(column.getLogicColumn(),
databaseName));
-
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(column.getLikeQueryEncryptorName()),
- () -> new
EncryptLikeQueryEncryptorNotFoundException(String.format("Like query encryptor
name of `%s` can not be null in database `%s`.", column.getLogicColumn(),
databaseName)));
-
ShardingSpherePreconditions.checkState(encryptors.contains(column.getLikeQueryEncryptorName()),
- () -> new
EncryptLikeQueryEncryptorNotFoundException(String.format("Can not find like
query encryptor `%s` in database `%s`.", column.getLikeQueryEncryptorName(),
databaseName)));
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumn.getName()),
() -> new EncryptLikeQueryColumnNotFoundException(logicColumn, databaseName));
+
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumn.getEncryptorName()),
+ () -> new
EncryptLikeQueryEncryptorNotFoundException(String.format("Like query encryptor
name of `%s` can not be null in database `%s`.", logicColumn, databaseName)));
+
ShardingSpherePreconditions.checkState(encryptors.contains(likeQueryColumn.getEncryptorName()),
+ () -> new
EncryptLikeQueryEncryptorNotFoundException(String.format("Can not find like
query encryptor `%s` in database `%s`.", likeQueryColumn.getEncryptorName(),
databaseName)));
}
@Override
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 e7a5aaa5ca2..0713944ea50 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
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.encrypt.exception.metadata.EncryptColumnNotFoun
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptRuleAware;
import
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAlterTableToken;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
+import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.AlterTableStatementContext;
@@ -226,13 +227,13 @@ public final class EncryptAlterTableTokenGenerator
implements CollectionSQLToken
private boolean checkPreviousAndAfterHasSameColumnNumber(final String
tableName, final ChangeColumnDefinitionSegment segment) {
EncryptColumn previousColumn = getEncryptColumn(tableName,
segment.getPreviousColumn().getIdentifier().getValue());
EncryptColumn currentColumn = getEncryptColumn(tableName,
segment.getColumnDefinition().getColumnName().getIdentifier().getValue());
- if (previousColumn.getAssistedQueryColumn().isPresent() &&
!currentColumn.getAssistedQueryColumn().isPresent()) {
+ if (previousColumn.getAssistedQuery().isPresent() &&
!currentColumn.getAssistedQuery().isPresent()) {
return false;
}
- if (previousColumn.getLikeQueryColumn().isPresent() &&
!currentColumn.getLikeQueryColumn().isPresent()) {
+ if (previousColumn.getLikeQuery().isPresent() &&
!currentColumn.getLikeQuery().isPresent()) {
return false;
}
- return previousColumn.getAssistedQueryColumn().isPresent() ||
!currentColumn.getAssistedQueryColumn().isPresent();
+ return previousColumn.getAssistedQuery().isPresent() ||
!currentColumn.getAssistedQuery().isPresent();
}
private Collection<? extends SQLToken> getColumnTokens(final String
tableName, final ChangeColumnDefinitionSegment segment) {
@@ -244,11 +245,11 @@ public final class EncryptAlterTableTokenGenerator
implements CollectionSQLToken
EncryptColumn encryptColumn = getEncryptColumn(tableName,
segment.getColumnDefinition().getColumnName().getIdentifier().getValue());
encryptRule.findAssistedQueryColumn(tableName, previousColumnName)
.map(optional -> new
EncryptAlterTableToken(segment.getStopIndex() + 1,
segment.getColumnDefinition().getColumnName().getStopIndex(),
- encryptColumn.getAssistedQueryColumn().orElse(""), ",
CHANGE COLUMN " + optional))
+
encryptColumn.getAssistedQuery().map(EncryptColumnItem::getName).orElse(""), ",
CHANGE COLUMN " + optional))
.ifPresent(result::add);
encryptRule.findLikeQueryColumn(tableName, previousColumnName)
.map(optional -> new
EncryptAlterTableToken(segment.getStopIndex() + 1,
segment.getColumnDefinition().getColumnName().getStopIndex(),
- encryptColumn.getLikeQueryColumn().orElse(""), ",
CHANGE COLUMN " + optional))
+
encryptColumn.getLikeQuery().map(EncryptColumnItem::getName).orElse(""), ",
CHANGE COLUMN " + optional))
.ifPresent(result::add);
return result;
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
index e68b6cab473..53a739c44ff 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.encrypt.rule;
-import com.google.common.base.Strings;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.Setter;
import java.util.Optional;
@@ -28,39 +28,32 @@ import java.util.Optional;
*/
@RequiredArgsConstructor
@Getter
+@Setter
public final class EncryptColumn {
- private final String cipherColumn;
+ private final String name;
- private final String assistedQueryColumn;
+ private final EncryptColumnItem cipher;
- private final String likeQueryColumn;
+ private EncryptColumnItem assistedQuery;
- private final String encryptorName;
-
- private final String assistedQueryEncryptorName;
-
- private final String likeQueryEncryptorName;
-
- public EncryptColumn(final String cipherColumn, final String
assistedQueryColumn, final String likeQueryColumn, final String encryptorName) {
- this(cipherColumn, assistedQueryColumn, likeQueryColumn,
encryptorName, null, null);
- }
+ private EncryptColumnItem likeQuery;
/**
- * Get assisted query column.
+ * Get assisted query.
*
- * @return assisted query column
+ * @return assisted query column item
*/
- public Optional<String> getAssistedQueryColumn() {
- return Strings.isNullOrEmpty(assistedQueryColumn) ? Optional.empty() :
Optional.of(assistedQueryColumn);
+ public Optional<EncryptColumnItem> getAssistedQuery() {
+ return Optional.ofNullable(assistedQuery);
}
/**
- * Get like query column.
+ * Get like query.
*
- * @return like query column
+ * @return like query column item
*/
- public Optional<String> getLikeQueryColumn() {
- return Strings.isNullOrEmpty(likeQueryColumn) ? Optional.empty() :
Optional.of(likeQueryColumn);
+ public Optional<EncryptColumnItem> getLikeQuery() {
+ return Optional.ofNullable(likeQuery);
}
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnItem.java
similarity index 64%
copy from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
copy to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnItem.java
index 3738a9329b6..27bbdf01832 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnItem.java
@@ -15,23 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.yaml.config.rule;
+package org.apache.shardingsphere.encrypt.rule;
import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
+import lombok.RequiredArgsConstructor;
/**
- * Encrypt table rule configuration for YAML.
+ * Encrypt column.
*/
+@RequiredArgsConstructor
@Getter
-@Setter
-public final class YamlEncryptTableRuleConfiguration implements
YamlConfiguration {
+public final class EncryptColumnItem {
+
+ private final String name;
- private String name;
+ private final String encryptorName;
- private Map<String, YamlEncryptColumnRuleConfiguration> columns = new
LinkedHashMap<>();
+ public EncryptColumnItem(final String name) {
+ this(name, null);
+ }
}
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 4691ef19447..b9dbbbf8fbb 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
@@ -42,9 +42,21 @@ public final class EncryptTable {
private Map<String, EncryptColumn> createEncryptColumns(final
EncryptTableRuleConfiguration config) {
Map<String, EncryptColumn> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (EncryptColumnRuleConfiguration each : config.getColumns()) {
- EncryptColumn encryptColumn = new
EncryptColumn(each.getCipherColumn(), each.getAssistedQueryColumn(),
- each.getLikeQueryColumn(), each.getEncryptorName(),
each.getAssistedQueryEncryptorName(), each.getLikeQueryEncryptorName());
- result.put(each.getLogicColumn(), encryptColumn);
+ result.put(each.getName(), createEncryptColumn(each));
+ }
+ return result;
+ }
+
+ private EncryptColumn createEncryptColumn(final
EncryptColumnRuleConfiguration config) {
+ EncryptColumnItem cipherColumnItem = new
EncryptColumnItem(config.getCipher().getName(),
config.getCipher().getEncryptorName());
+ EncryptColumn result = new EncryptColumn(config.getName(),
cipherColumnItem);
+ if (config.getAssistedQuery().isPresent()) {
+ EncryptColumnItem assistedQueryColumn = new
EncryptColumnItem(config.getAssistedQuery().get().getName(),
config.getAssistedQuery().get().getEncryptorName());
+ result.setAssistedQuery(assistedQueryColumn);
+ }
+ if (config.getLikeQuery().isPresent()) {
+ EncryptColumnItem likeQueryColumn = new
EncryptColumnItem(config.getLikeQuery().get().getName(),
config.getLikeQuery().get().getEncryptorName());
+ result.setLikeQuery(likeQueryColumn);
}
return result;
}
@@ -56,7 +68,7 @@ public final class EncryptTable {
* @return encrypt algorithm name
*/
public Optional<String> findEncryptorName(final String logicColumn) {
- return columns.containsKey(logicColumn) ?
Optional.of(columns.get(logicColumn).getEncryptorName()) : Optional.empty();
+ return columns.containsKey(logicColumn) ?
Optional.of(columns.get(logicColumn).getCipher().getEncryptorName()) :
Optional.empty();
}
/**
@@ -66,7 +78,7 @@ public final class EncryptTable {
* @return assist encrypt algorithm name
*/
public Optional<String> findAssistedQueryEncryptorName(final String
logicColumn) {
- return columns.containsKey(logicColumn) ?
Optional.ofNullable(columns.get(logicColumn).getAssistedQueryEncryptorName()) :
Optional.empty();
+ return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getAssistedQuery().map(EncryptColumnItem::getEncryptorName)
: Optional.empty();
}
/**
@@ -76,7 +88,7 @@ public final class EncryptTable {
* @return like encrypt algorithm name
*/
public Optional<String> findLikeQueryEncryptorName(final String
logicColumn) {
- return columns.containsKey(logicColumn) ?
Optional.ofNullable(columns.get(logicColumn).getLikeQueryEncryptorName()) :
Optional.empty();
+ return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getLikeQuery().map(EncryptColumnItem::getEncryptorName)
: Optional.empty();
}
/**
@@ -97,7 +109,7 @@ public final class EncryptTable {
*/
public String getLogicColumnByCipherColumn(final String cipherColumn) {
for (Entry<String, EncryptColumn> entry : columns.entrySet()) {
- if (entry.getValue().getCipherColumn().equals(cipherColumn)) {
+ if
(entry.getValue().getCipher().getName().equalsIgnoreCase(cipherColumn)) {
return entry.getKey();
}
}
@@ -111,7 +123,7 @@ public final class EncryptTable {
* @return cipher column or not
*/
public boolean isCipherColumn(final String columnName) {
- return columns.values().stream().anyMatch(each ->
each.getCipherColumn().equalsIgnoreCase(columnName));
+ return columns.values().stream().anyMatch(each ->
each.getCipher().getName().equalsIgnoreCase(columnName));
}
/**
@@ -121,7 +133,7 @@ public final class EncryptTable {
* @return cipher column
*/
public String getCipherColumn(final String logicColumn) {
- return columns.get(logicColumn).getCipherColumn();
+ return columns.get(logicColumn).getCipher().getName();
}
/**
@@ -132,8 +144,8 @@ public final class EncryptTable {
public Collection<String> getAssistedQueryColumns() {
Collection<String> result = new LinkedList<>();
for (EncryptColumn each : columns.values()) {
- if (each.getAssistedQueryColumn().isPresent()) {
- result.add(each.getAssistedQueryColumn().get());
+ if (each.getAssistedQuery().isPresent()) {
+ result.add(each.getAssistedQuery().get().getName());
}
}
return result;
@@ -147,8 +159,8 @@ public final class EncryptTable {
public Collection<String> getLikeQueryColumns() {
Collection<String> result = new LinkedList<>();
for (EncryptColumn each : columns.values()) {
- if (each.getLikeQueryColumn().isPresent()) {
- result.add(each.getLikeQueryColumn().get());
+ if (each.getLikeQuery().isPresent()) {
+ result.add(each.getLikeQuery().get().getName());
}
}
return result;
@@ -161,7 +173,7 @@ public final class EncryptTable {
* @return assisted query column
*/
public Optional<String> findAssistedQueryColumn(final String logicColumn) {
- return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getAssistedQueryColumn() : Optional.empty();
+ return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getAssistedQuery().map(EncryptColumnItem::getName) :
Optional.empty();
}
/**
@@ -171,7 +183,7 @@ public final class EncryptTable {
* @return like query column
*/
public Optional<String> findLikeQueryColumn(final String logicColumn) {
- return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getLikeQueryColumn() : Optional.empty();
+ return columns.containsKey(logicColumn) ?
columns.get(logicColumn).getLikeQuery().map(EncryptColumnItem::getName) :
Optional.empty();
}
/**
@@ -182,7 +194,7 @@ public final class EncryptTable {
public Map<String, String> getLogicAndCipherColumns() {
Map<String, String> result = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (Entry<String, EncryptColumn> entry : columns.entrySet()) {
- result.put(entry.getKey(), entry.getValue().getCipherColumn());
+ result.put(entry.getKey(), entry.getValue().getCipher().getName());
}
return result;
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlEncryptRuleConfiguration.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlCompatibleEncryptRuleConfiguration.java
similarity index 79%
rename from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlEncryptRuleConfiguration.java
rename to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlCompatibleEncryptRuleConfiguration.java
index 36fdaa96ba7..12d29915372 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlEncryptRuleConfiguration.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/YamlCompatibleEncryptRuleConfiguration.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.encrypt.yaml.config;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptTableRuleConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
@@ -29,12 +29,15 @@ import java.util.Map;
/**
* Encrypt rule configuration for YAML.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
*/
@Getter
@Setter
-public final class YamlEncryptRuleConfiguration implements
YamlRuleConfiguration {
+@Deprecated
+public final class YamlCompatibleEncryptRuleConfiguration implements
YamlRuleConfiguration {
- private Map<String, YamlEncryptTableRuleConfiguration> tables = new
LinkedHashMap<>();
+ private Map<String, YamlCompatibleEncryptTableRuleConfiguration> tables =
new LinkedHashMap<>();
private Map<String, YamlAlgorithmConfiguration> encryptors = new
LinkedHashMap<>();
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptColumnRuleConfiguration.java
similarity index 87%
rename from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
rename to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptColumnRuleConfiguration.java
index 05b8e547b4d..079f0099fb0 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptColumnRuleConfiguration.java
@@ -23,10 +23,13 @@ import
org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
/**
* Encrypt column rule configuration for YAML.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
*/
@Getter
@Setter
-public final class YamlEncryptColumnRuleConfiguration implements
YamlConfiguration {
+@Deprecated
+public final class YamlCompatibleEncryptColumnRuleConfiguration implements
YamlConfiguration {
private String logicColumn;
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptTableRuleConfiguration.java
similarity index 79%
rename from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
rename to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptTableRuleConfiguration.java
index 3738a9329b6..970eedac742 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptTableRuleConfiguration.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlCompatibleEncryptTableRuleConfiguration.java
@@ -26,12 +26,15 @@ import java.util.Map;
/**
* Encrypt table rule configuration for YAML.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
*/
@Getter
@Setter
-public final class YamlEncryptTableRuleConfiguration implements
YamlConfiguration {
+@Deprecated
+public final class YamlCompatibleEncryptTableRuleConfiguration implements
YamlConfiguration {
private String name;
- private Map<String, YamlEncryptColumnRuleConfiguration> columns = new
LinkedHashMap<>();
+ private Map<String, YamlCompatibleEncryptColumnRuleConfiguration> columns
= new LinkedHashMap<>();
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapper.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapper.java
similarity index 70%
rename from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapper.java
rename to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapper.java
index a32dd1b8334..beb254287d2 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapper.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapper.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.encrypt.yaml.swapper;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.swapper.rule.YamlEncryptTableRuleConfigurationSwapper;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.swapper.rule.YamlCompatibleEncryptTableRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.swapper.algorithm.YamlAlgorithmConfigurationSwapper;
@@ -36,37 +36,40 @@ import java.util.Map.Entry;
/**
* YAML encrypt rule configuration swapper.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
*/
-public final class YamlEncryptRuleConfigurationSwapper implements
YamlRuleConfigurationSwapper<YamlEncryptRuleConfiguration,
EncryptRuleConfiguration> {
+@Deprecated
+public final class YamlCompatibleEncryptRuleConfigurationSwapper implements
YamlRuleConfigurationSwapper<YamlCompatibleEncryptRuleConfiguration,
EncryptRuleConfiguration> {
- private final YamlEncryptTableRuleConfigurationSwapper tableSwapper = new
YamlEncryptTableRuleConfigurationSwapper();
+ private final YamlCompatibleEncryptTableRuleConfigurationSwapper
tableSwapper = new YamlCompatibleEncryptTableRuleConfigurationSwapper();
private final YamlAlgorithmConfigurationSwapper algorithmSwapper = new
YamlAlgorithmConfigurationSwapper();
@Override
- public YamlEncryptRuleConfiguration swapToYamlConfiguration(final
EncryptRuleConfiguration data) {
- YamlEncryptRuleConfiguration result = new
YamlEncryptRuleConfiguration();
+ public YamlCompatibleEncryptRuleConfiguration
swapToYamlConfiguration(final EncryptRuleConfiguration data) {
+ YamlCompatibleEncryptRuleConfiguration result = new
YamlCompatibleEncryptRuleConfiguration();
data.getTables().forEach(each ->
result.getTables().put(each.getName(),
tableSwapper.swapToYamlConfiguration(each)));
data.getEncryptors().forEach((key, value) ->
result.getEncryptors().put(key,
algorithmSwapper.swapToYamlConfiguration(value)));
return result;
}
@Override
- public EncryptRuleConfiguration swapToObject(final
YamlEncryptRuleConfiguration yamlConfig) {
+ public EncryptRuleConfiguration swapToObject(final
YamlCompatibleEncryptRuleConfiguration yamlConfig) {
return new EncryptRuleConfiguration(swapTables(yamlConfig),
swapEncryptAlgorithm(yamlConfig));
}
- private Collection<EncryptTableRuleConfiguration> swapTables(final
YamlEncryptRuleConfiguration yamlConfig) {
+ private Collection<EncryptTableRuleConfiguration> swapTables(final
YamlCompatibleEncryptRuleConfiguration yamlConfig) {
Collection<EncryptTableRuleConfiguration> result = new LinkedList<>();
- for (Entry<String, YamlEncryptTableRuleConfiguration> entry :
yamlConfig.getTables().entrySet()) {
- YamlEncryptTableRuleConfiguration yamlEncryptTableRuleConfig =
entry.getValue();
+ for (Entry<String, YamlCompatibleEncryptTableRuleConfiguration> entry
: yamlConfig.getTables().entrySet()) {
+ YamlCompatibleEncryptTableRuleConfiguration
yamlEncryptTableRuleConfig = entry.getValue();
yamlEncryptTableRuleConfig.setName(entry.getKey());
result.add(tableSwapper.swapToObject(yamlEncryptTableRuleConfig));
}
return result;
}
- private Map<String, AlgorithmConfiguration> swapEncryptAlgorithm(final
YamlEncryptRuleConfiguration yamlConfig) {
+ private Map<String, AlgorithmConfiguration> swapEncryptAlgorithm(final
YamlCompatibleEncryptRuleConfiguration yamlConfig) {
Map<String, AlgorithmConfiguration> result = new
LinkedHashMap<>(yamlConfig.getEncryptors().size(), 1);
for (Entry<String, YamlAlgorithmConfiguration> entry :
yamlConfig.getEncryptors().entrySet()) {
result.put(entry.getKey(),
algorithmSwapper.swapToObject(entry.getValue()));
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapper.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapper.java
new file mode 100644
index 00000000000..4fba05e770d
--- /dev/null
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapper.java
@@ -0,0 +1,64 @@
+/*
+ * 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.yaml.swapper.rule;
+
+import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
+
+/**
+ * YAML encrypt column rule configuration swapper.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
+ */
+@Deprecated
+public final class YamlCompatibleEncryptColumnRuleConfigurationSwapper
implements
YamlConfigurationSwapper<YamlCompatibleEncryptColumnRuleConfiguration,
EncryptColumnRuleConfiguration> {
+
+ @Override
+ public YamlCompatibleEncryptColumnRuleConfiguration
swapToYamlConfiguration(final EncryptColumnRuleConfiguration data) {
+ YamlCompatibleEncryptColumnRuleConfiguration result = new
YamlCompatibleEncryptColumnRuleConfiguration();
+ result.setLogicColumn(data.getName());
+ result.setCipherColumn(data.getCipher().getName());
+ result.setEncryptorName(data.getCipher().getEncryptorName());
+ if (data.getLikeQuery().isPresent()) {
+ result.setLikeQueryColumn(data.getLikeQuery().get().getName());
+
result.setLikeQueryEncryptorName(data.getLikeQuery().get().getEncryptorName());
+ }
+ if (data.getAssistedQuery().isPresent()) {
+
result.setAssistedQueryColumn(data.getAssistedQuery().get().getName());
+
result.setAssistedQueryEncryptorName(data.getAssistedQuery().get().getEncryptorName());
+ }
+ return result;
+ }
+
+ @Override
+ public EncryptColumnRuleConfiguration swapToObject(final
YamlCompatibleEncryptColumnRuleConfiguration yamlConfig) {
+ EncryptColumnItemRuleConfiguration cipherColumnConfig = new
EncryptColumnItemRuleConfiguration(yamlConfig.getCipherColumn(),
yamlConfig.getEncryptorName());
+ EncryptColumnRuleConfiguration result = new
EncryptColumnRuleConfiguration(yamlConfig.getLogicColumn(), cipherColumnConfig);
+ if (null != yamlConfig.getAssistedQueryColumn()) {
+ EncryptColumnItemRuleConfiguration assistedQueryColumnConfig = new
EncryptColumnItemRuleConfiguration(yamlConfig.getAssistedQueryColumn(),
yamlConfig.getAssistedQueryEncryptorName());
+ result.setAssistedQuery(assistedQueryColumnConfig);
+ }
+ if (null != yamlConfig.getLikeQueryColumn()) {
+ EncryptColumnItemRuleConfiguration likeQueryColumnConfig = new
EncryptColumnItemRuleConfiguration(yamlConfig.getLikeQueryColumn(),
yamlConfig.getLikeQueryEncryptorName());
+ result.setLikeQuery(likeQueryColumnConfig);
+ }
+ return result;
+ }
+}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapper.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapper.java
similarity index 59%
rename from
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapper.java
rename to
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapper.java
index 430ae6c417e..41eea35af30 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapper.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapper.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.encrypt.yaml.swapper.rule;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptColumnRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptTableRuleConfiguration;
import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
import java.util.Collection;
@@ -29,26 +29,29 @@ import java.util.Map.Entry;
/**
* YAML encrypt table configuration swapper.
+ *
+ * @deprecated Should use new api, compatible api will remove in next version.
*/
-public final class YamlEncryptTableRuleConfigurationSwapper implements
YamlConfigurationSwapper<YamlEncryptTableRuleConfiguration,
EncryptTableRuleConfiguration> {
+@Deprecated
+public final class YamlCompatibleEncryptTableRuleConfigurationSwapper
implements
YamlConfigurationSwapper<YamlCompatibleEncryptTableRuleConfiguration,
EncryptTableRuleConfiguration> {
- private final YamlEncryptColumnRuleConfigurationSwapper columnSwapper =
new YamlEncryptColumnRuleConfigurationSwapper();
+ private final YamlCompatibleEncryptColumnRuleConfigurationSwapper
columnSwapper = new YamlCompatibleEncryptColumnRuleConfigurationSwapper();
@Override
- public YamlEncryptTableRuleConfiguration swapToYamlConfiguration(final
EncryptTableRuleConfiguration data) {
- YamlEncryptTableRuleConfiguration result = new
YamlEncryptTableRuleConfiguration();
+ public YamlCompatibleEncryptTableRuleConfiguration
swapToYamlConfiguration(final EncryptTableRuleConfiguration data) {
+ YamlCompatibleEncryptTableRuleConfiguration result = new
YamlCompatibleEncryptTableRuleConfiguration();
for (EncryptColumnRuleConfiguration each : data.getColumns()) {
- result.getColumns().put(each.getLogicColumn(),
columnSwapper.swapToYamlConfiguration(each));
+ result.getColumns().put(each.getName(),
columnSwapper.swapToYamlConfiguration(each));
}
result.setName(data.getName());
return result;
}
@Override
- public EncryptTableRuleConfiguration swapToObject(final
YamlEncryptTableRuleConfiguration yamlConfig) {
+ public EncryptTableRuleConfiguration swapToObject(final
YamlCompatibleEncryptTableRuleConfiguration yamlConfig) {
Collection<EncryptColumnRuleConfiguration> columns = new
LinkedList<>();
- for (Entry<String, YamlEncryptColumnRuleConfiguration> entry :
yamlConfig.getColumns().entrySet()) {
- YamlEncryptColumnRuleConfiguration yamlEncryptColumnRuleConfig =
entry.getValue();
+ for (Entry<String, YamlCompatibleEncryptColumnRuleConfiguration> entry
: yamlConfig.getColumns().entrySet()) {
+ YamlCompatibleEncryptColumnRuleConfiguration
yamlEncryptColumnRuleConfig = entry.getValue();
yamlEncryptColumnRuleConfig.setLogicColumn(entry.getKey());
columns.add(columnSwapper.swapToObject(yamlEncryptColumnRuleConfig));
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapper.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapper.java
deleted file mode 100644
index 1cab7bb5c96..00000000000
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapper.java
+++ /dev/null
@@ -1,48 +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.yaml.swapper.rule;
-
-import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptColumnRuleConfiguration;
-import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-
-/**
- * YAML encrypt column rule configuration swapper.
- */
-public final class YamlEncryptColumnRuleConfigurationSwapper implements
YamlConfigurationSwapper<YamlEncryptColumnRuleConfiguration,
EncryptColumnRuleConfiguration> {
-
- @Override
- public YamlEncryptColumnRuleConfiguration swapToYamlConfiguration(final
EncryptColumnRuleConfiguration data) {
- YamlEncryptColumnRuleConfiguration result = new
YamlEncryptColumnRuleConfiguration();
- result.setLogicColumn(data.getLogicColumn());
- result.setLikeQueryColumn(data.getLikeQueryColumn());
- result.setCipherColumn(data.getCipherColumn());
- result.setAssistedQueryColumn(data.getAssistedQueryColumn());
- result.setEncryptorName(data.getEncryptorName());
-
result.setAssistedQueryEncryptorName(data.getAssistedQueryEncryptorName());
- result.setLikeQueryEncryptorName(data.getLikeQueryEncryptorName());
- return result;
- }
-
- @Override
- public EncryptColumnRuleConfiguration swapToObject(final
YamlEncryptColumnRuleConfiguration yamlConfig) {
- return new EncryptColumnRuleConfiguration(
- yamlConfig.getLogicColumn(), yamlConfig.getCipherColumn(),
yamlConfig.getAssistedQueryColumn(), yamlConfig.getLikeQueryColumn(),
- yamlConfig.getEncryptorName(),
yamlConfig.getAssistedQueryEncryptorName(),
yamlConfig.getLikeQueryEncryptorName());
- }
-}
diff --git
a/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
b/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
index 9d0d7a17822..c12f25cd20c 100644
---
a/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
+++
b/features/encrypt/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptRuleConfigurationSwapper
+org.apache.shardingsphere.encrypt.yaml.swapper.YamlCompatibleEncryptRuleConfigurationSwapper
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
index f033eecce53..6ed4de4b15c 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.encrypt.checker;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.exception.metadata.EncryptEncryptorNotFoundException;
@@ -46,7 +47,8 @@ class EncryptRuleConfigurationCheckerTest {
private EncryptRuleConfiguration createValidConfiguration() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.singletonMap("aes_encryptor",
mock(AlgorithmConfiguration.class)));
- Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(new EncryptColumnRuleConfiguration("user_id",
"user_cipher", null, null, "aes_encryptor"));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
+ Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(columnRuleConfig);
when(result.getTables()).thenReturn(Collections.singletonList(new
EncryptTableRuleConfiguration("t_encrypt", columns)));
return result;
}
@@ -62,7 +64,8 @@ class EncryptRuleConfigurationCheckerTest {
private EncryptRuleConfiguration createInvalidCipherColumnConfig() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
- Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(new EncryptColumnRuleConfiguration("user_id",
"user_cipher", null, null, "aes_encryptor"));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
+ Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(columnRuleConfig);
when(result.getTables()).thenReturn(Collections.singletonList(new
EncryptTableRuleConfiguration("t_encrypt", columns)));
return result;
}
@@ -78,8 +81,9 @@ class EncryptRuleConfigurationCheckerTest {
private EncryptRuleConfiguration createInvalidAssistColumnConfig() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
- Collection<EncryptColumnRuleConfiguration> columns =
- Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "user_assisted", "",
"aes_encryptor", "aes_assisted_encryptor", null));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
+ Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(columnRuleConfig);
+ columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_assisted", "aes_assisted_encryptor"));
when(result.getTables()).thenReturn(Collections.singletonList(new
EncryptTableRuleConfiguration("t_encrypt", columns)));
return result;
}
@@ -95,8 +99,9 @@ class EncryptRuleConfigurationCheckerTest {
private EncryptRuleConfiguration createInvalidLikeColumnConfig() {
EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
when(result.getEncryptors()).thenReturn(Collections.emptyMap());
- Collection<EncryptColumnRuleConfiguration> columns =
- Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "user_like",
"aes_encryptor", null, "like_cn_encryptor"));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "aes_encryptor"));
+ Collection<EncryptColumnRuleConfiguration> columns =
Collections.singletonList(columnRuleConfig);
+ columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_like", "like_cn_encryptor"));
when(result.getTables()).thenReturn(Collections.singletonList(new
EncryptTableRuleConfiguration("t_encrypt", columns)));
return result;
}
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 ab7b8f9238e..462b645c4c3 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
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.encrypt.merge.dal.show;
+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.rule.EncryptRule;
@@ -67,8 +68,10 @@ class DecoratedEncryptShowCreateTableMergedResultTest {
when(mergedResult.getValue(2, String.class)).thenReturn(
"CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id_cipher`
VARCHAR(100) NOT NULL, "
+ "`user_id_assisted` VARCHAR(100) NOT NULL,
`order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4;");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_id_cipher"));
+ columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_id_assisted"));
DecoratedEncryptShowCreateTableMergedResult actual =
createDecoratedEncryptShowCreateTableMergedResult(mergedResult,
- mockEncryptRule(Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_id_cipher", "user_id_assisted",
"", null))));
+ mockEncryptRule(Collections.singletonList(columnRuleConfig)));
assertTrue(actual.next());
assertThat(actual.getValue(2, String.class),
is("CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id`
VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"));
@@ -80,8 +83,10 @@ class DecoratedEncryptShowCreateTableMergedResultTest {
when(mergedResult.getValue(2, String.class)).thenReturn(
"CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id_cipher`
VARCHAR(100) NOT NULL, "
+ "`user_id_like` VARCHAR(100) NOT NULL, `order_id`
VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4;");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_id_cipher"));
+ columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_id_like"));
DecoratedEncryptShowCreateTableMergedResult actual =
createDecoratedEncryptShowCreateTableMergedResult(mergedResult,
- mockEncryptRule(Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_id_cipher", "", "user_id_like",
null, null, null))));
+ mockEncryptRule(Collections.singletonList(columnRuleConfig)));
assertTrue(actual.next());
assertThat(actual.getValue(2, String.class),
is("CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id`
VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL,"
@@ -102,8 +107,12 @@ class DecoratedEncryptShowCreateTableMergedResultTest {
"CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id_cipher`
VARCHAR(100) NOT NULL, `user_id_like` VARCHAR(100) NOT NULL, "
+ "`order_id_cipher` VARCHAR(30) NOT NULL,
`order_id_like` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4;");
Collection<EncryptColumnRuleConfiguration> columns = new
LinkedList<>();
- columns.add(new EncryptColumnRuleConfiguration("user_id",
"user_id_cipher", "", "user_id_like", null, null, null));
- columns.add(new EncryptColumnRuleConfiguration("order_id",
"order_id_cipher", "", "order_id_like", null, null, null));
+ EncryptColumnRuleConfiguration userIdColumnConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_id_cipher"));
+ userIdColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_id_like"));
+ columns.add(userIdColumnConfig);
+ EncryptColumnRuleConfiguration orderIdColumnConfig = new
EncryptColumnRuleConfiguration("order_id", new
EncryptColumnItemRuleConfiguration("order_id_cipher"));
+ orderIdColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("order_id_like"));
+ columns.add(orderIdColumnConfig);
DecoratedEncryptShowCreateTableMergedResult actual =
createDecoratedEncryptShowCreateTableMergedResult(mergedResult,
mockEncryptRule(columns));
assertTrue(actual.next());
assertThat(actual.getValue(2, String.class),
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 f526335374f..7e47492844f 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
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.encrypt.merge.dal.show;
+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.rule.EncryptRule;
@@ -66,8 +67,10 @@ class MergedEncryptShowCreateTableMergedResultTest {
when(queryResult.getValue(2, String.class)).thenReturn(
"CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id_cipher`
VARCHAR(100) NOT NULL, "
+ "`user_id_assisted` VARCHAR(100) NOT NULL,
`order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4;");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_id_cipher"));
+ columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_id_assisted"));
MergedEncryptShowCreateTableMergedResult actual =
createMergedEncryptShowCreateTableMergedResult(queryResult,
- mockEncryptRule(Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_id_cipher", "user_id_assisted",
"", null))));
+ mockEncryptRule(Collections.singletonList(columnRuleConfig)));
assertTrue(actual.next());
assertThat(actual.getValue(2, String.class),
is("CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id`
VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"));
@@ -79,8 +82,9 @@ class MergedEncryptShowCreateTableMergedResultTest {
when(queryResult.getValue(2, String.class)).thenReturn(
"CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id_cipher`
VARCHAR(100) NOT NULL, "
+ "`user_id_like` VARCHAR(100) NOT NULL, `order_id`
VARCHAR(30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4;");
- MergedEncryptShowCreateTableMergedResult actual =
createMergedEncryptShowCreateTableMergedResult(queryResult,
- mockEncryptRule(Collections.singletonList(new
EncryptColumnRuleConfiguration("user_id", "user_id_cipher", "", "user_id_like",
"", "", ""))));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_id_cipher"));
+ columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_id_like"));
+ MergedEncryptShowCreateTableMergedResult actual =
createMergedEncryptShowCreateTableMergedResult(queryResult,
mockEncryptRule(Collections.singletonList(columnRuleConfig)));
assertTrue(actual.next());
assertThat(actual.getValue(2, String.class),
is("CREATE TABLE `t_encrypt` (`id` INT NOT NULL, `user_id`
VARCHAR(100) NOT NULL, `order_id` VARCHAR(30) NOT NULL,"
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
index f4629b3da09..ec6f5231a83 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlg
import
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAlterTableTokenGenerator;
import
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAlterTableToken;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
+import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import
org.apache.shardingsphere.infra.binder.statement.ddl.AlterTableStatementContext;
@@ -76,11 +77,17 @@ class EncryptAlterTableTokenGeneratorTest {
}
private EncryptColumn mockEncryptColumn() {
- return new EncryptColumn("cipher_certificate_number",
"assisted_certificate_number", "like_certificate_number", "test");
+ EncryptColumn result = new EncryptColumn("certificate_number", new
EncryptColumnItem("cipher_certificate_number", "test"));
+ result.setAssistedQuery(new
EncryptColumnItem("assisted_certificate_number"));
+ result.setLikeQuery(new EncryptColumnItem("like_certificate_number"));
+ return result;
}
private EncryptColumn mockNewEncryptColumn() {
- return new EncryptColumn("cipher_certificate_number_new",
"assisted_certificate_number_new", "like_certificate_number_new", "test");
+ EncryptColumn result = new EncryptColumn("certificate_number_new", new
EncryptColumnItem("cipher_certificate_number_new", "test"));
+ result.setAssistedQuery(new
EncryptColumnItem("assisted_certificate_number_new"));
+ result.setLikeQuery(new
EncryptColumnItem("like_certificate_number_new"));
+ return result;
}
@Test
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
index e4ac3d97934..fd8a1bba158 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.encrypt.rewrite.impl;
import
org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateTableTokenGenerator;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
+import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import
org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext;
@@ -92,14 +93,17 @@ class EncryptCreateTableTokenGeneratorTest {
when(result.findStandardEncryptor("t_encrypt",
"certificate_number")).thenReturn(Optional.of(mock(StandardEncryptAlgorithm.class)));
when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
EncryptColumn column = mockEncryptColumn();
- when(result.getCipherColumn("t_encrypt",
"certificate_number")).thenReturn(column.getCipherColumn());
- when(result.findAssistedQueryColumn("t_encrypt",
"certificate_number")).thenReturn(column.getAssistedQueryColumn());
- when(result.findLikeQueryColumn("t_encrypt",
"certificate_number")).thenReturn(column.getLikeQueryColumn());
+ when(result.getCipherColumn("t_encrypt",
"certificate_number")).thenReturn(column.getCipher().getName());
+ when(result.findAssistedQueryColumn("t_encrypt",
"certificate_number")).thenReturn(column.getAssistedQuery().map(EncryptColumnItem::getName));
+ when(result.findLikeQueryColumn("t_encrypt",
"certificate_number")).thenReturn(column.getLikeQuery().map(EncryptColumnItem::getName));
when(encryptTable.findEncryptColumn("certificate_number")).thenReturn(Optional.of(column));
return result;
}
private EncryptColumn mockEncryptColumn() {
- return new EncryptColumn("cipher_certificate_number",
"assisted_certificate_number", "like_certificate_number", "test");
+ EncryptColumn result = new EncryptColumn("certificate_number", new
EncryptColumnItem("cipher_certificate_number", "test"));
+ result.setAssistedQuery(new
EncryptColumnItem("assisted_certificate_number"));
+ result.setLikeQuery(new EncryptColumnItem("like_certificate_number"));
+ return result;
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
index 5d78e685659..0bb6dda183c 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.encrypt.rewrite.impl;
import
org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptProjectionTokenGenerator;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
+import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
@@ -69,7 +70,8 @@ class EncryptProjectionTokenGeneratorTest {
when(encryptTable2.getLogicColumns()).thenReturn(Collections.singletonList("mobile"));
when(result.findEncryptTable("doctor")).thenReturn(Optional.of(encryptTable1));
when(result.findEncryptTable("doctor1")).thenReturn(Optional.of(encryptTable2));
- EncryptColumn column = new EncryptColumn("mobile", null, null, null);
+ EncryptColumn column = new EncryptColumn("mobile", new
EncryptColumnItem("mobile"));
+ column.setLikeQuery(new EncryptColumnItem("mobile"));
when(result.findEncryptColumn("doctor",
"mobile")).thenReturn(Optional.of(column));
return result;
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
index 2b718feaf7a..f0e0aad4dee 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.rewrite.token.pojo.EncryptInsertValuesToken;
@@ -81,7 +82,9 @@ public final class EncryptGeneratorFixtureBuilder {
encryptors.put("assisted_encryptor", new
AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties()));
encryptors.put("like_encryptor", new
AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new Properties()));
EncryptColumnRuleConfiguration pwdColumnConfig =
- new EncryptColumnRuleConfiguration("pwd", "pwd_cipher",
"pwd_assist", "pwd_like", "standard_encryptor", "assisted_encryptor",
"like_encryptor");
+ new EncryptColumnRuleConfiguration("pwd", new
EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
+ pwdColumnConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("pwd_assist", "assisted_encryptor"));
+ pwdColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("pwd_like", "like_encryptor"));
return new EncryptRule(
new EncryptRuleConfiguration(Collections.singleton(new
EncryptTableRuleConfiguration("t_user",
Collections.singletonList(pwdColumnConfig))), encryptors));
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnTest.java
index 6241f88b8c7..ad1dea47cc0 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptColumnTest.java
@@ -25,11 +25,17 @@ class EncryptColumnTest {
@Test
void assertGetAssistedQueryColumn() {
- assertTrue(new EncryptColumn("cipherColumn", "assistedQueryColumn",
"likeQueryColumn", "encryptorName").getAssistedQueryColumn().isPresent());
+ EncryptColumn encryptColumn = new EncryptColumn("logicColumn", new
EncryptColumnItem("cipherColumn", "encryptorName"));
+ encryptColumn.setLikeQuery(new EncryptColumnItem("likeQueryColumn"));
+ encryptColumn.setAssistedQuery(new
EncryptColumnItem("assistedQueryColumn"));
+ assertTrue(encryptColumn.getAssistedQuery().isPresent());
}
@Test
void assertGetLikeQueryColumn() {
- assertTrue(new EncryptColumn("cipherColumn", "assistedQueryColumn",
"likeQueryColumn", "encryptorName").getLikeQueryColumn().isPresent());
+ EncryptColumn encryptColumn = new EncryptColumn("logicColumn", new
EncryptColumnItem("cipherColumn", "encryptorName"));
+ encryptColumn.setAssistedQuery(new
EncryptColumnItem("assistedQueryColumn"));
+ encryptColumn.setLikeQuery(new EncryptColumnItem("likeQueryColumn"));
+ assertTrue(encryptColumn.getLikeQuery().isPresent());
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index 06dac9aa53f..7b645562942 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.encrypt.rule;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.infra.config.algorithm.AlgorithmConfiguration;
@@ -132,36 +133,39 @@ class EncryptRuleTest {
}
private EncryptRuleConfiguration createEncryptRuleConfiguration() {
- AlgorithmConfiguration standardEncryptConfig = new
AlgorithmConfiguration("CORE.FIXTURE", new Properties());
- AlgorithmConfiguration queryAssistedEncryptConfig = new
AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties());
- AlgorithmConfiguration queryLikeEncryptConfig = new
AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new Properties());
- EncryptColumnRuleConfiguration pwdColumnConfig =
- new EncryptColumnRuleConfiguration("pwd", "pwd_cipher",
"pwd_assist", "pwd_like", "standard_encryptor", "assisted_encryptor",
"like_encryptor");
- EncryptColumnRuleConfiguration creditCardColumnConfig = new
EncryptColumnRuleConfiguration("credit_card", "credit_card_cipher", "", "",
"test_encryptor");
+ EncryptColumnRuleConfiguration pwdColumnConfig = new
EncryptColumnRuleConfiguration("pwd", new
EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
+ pwdColumnConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("pwd_assist", "assisted_encryptor"));
+ pwdColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("pwd_like", "like_encryptor"));
+ EncryptColumnRuleConfiguration creditCardColumnConfig = new
EncryptColumnRuleConfiguration("credit_card", new
EncryptColumnItemRuleConfiguration("credit_card_cipher", "standard_encryptor"));
EncryptTableRuleConfiguration tableConfig = new
EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig,
creditCardColumnConfig));
- return new
EncryptRuleConfiguration(Collections.singleton(tableConfig),
getEncryptors(standardEncryptConfig, queryAssistedEncryptConfig,
queryLikeEncryptConfig));
+ return new
EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(new
AlgorithmConfiguration("CORE.FIXTURE", new Properties()),
+ new AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new
Properties()), new AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new
Properties())));
}
@Test
void assertAssistedQueryEncryptorNameSpecified() {
EncryptColumnRuleConfiguration pwdColumnConfig =
- new EncryptColumnRuleConfiguration("pwd", "pwd_cipher",
"pwd_assist", "", "standard_encryptor", "assisted_query_test_encryptor", null);
- assertThat(pwdColumnConfig.getAssistedQueryEncryptorName(),
is("assisted_query_test_encryptor"));
+ new EncryptColumnRuleConfiguration("pwd", new
EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
+ pwdColumnConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("pwd_assist",
"assisted_query_test_encryptor"));
+ assertTrue(pwdColumnConfig.getAssistedQuery().isPresent());
+
assertThat(pwdColumnConfig.getAssistedQuery().get().getEncryptorName(),
is("assisted_query_test_encryptor"));
}
@Test
void assertLikeQueryEncryptorNameSpecified() {
EncryptColumnRuleConfiguration pwdColumnConfig =
- new EncryptColumnRuleConfiguration("pwd", "pwd_cipher", "",
"pwd_like", "standard_encryptor", "", "like_query_test_encryptor");
- assertThat(pwdColumnConfig.getLikeQueryEncryptorName(),
is("like_query_test_encryptor"));
+ new EncryptColumnRuleConfiguration("pwd", new
EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
+ pwdColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("pwd_like", "like_query_test_encryptor"));
+ assertTrue(pwdColumnConfig.getLikeQuery().isPresent());
+ assertThat(pwdColumnConfig.getLikeQuery().get().getEncryptorName(),
is("like_query_test_encryptor"));
}
private EncryptRuleConfiguration
createEncryptRuleConfigurationWithUpperCaseLogicTable() {
AlgorithmConfiguration standardEncryptConfig = new
AlgorithmConfiguration("CORE.FIXTURE", new Properties());
AlgorithmConfiguration queryAssistedEncryptConfig = new
AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties());
AlgorithmConfiguration queryLikeEncryptConfig = new
AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new Properties());
- EncryptColumnRuleConfiguration pwdColumnConfig = new
EncryptColumnRuleConfiguration("pwd", "pwd_cipher", "", "", "test_encryptor");
- EncryptColumnRuleConfiguration creditCardColumnConfig = new
EncryptColumnRuleConfiguration("credit_card", "credit_card_cipher", "", "",
"test_encryptor");
+ EncryptColumnRuleConfiguration pwdColumnConfig = new
EncryptColumnRuleConfiguration("pwd", new
EncryptColumnItemRuleConfiguration("pwd_cipher", "test_encryptor"));
+ EncryptColumnRuleConfiguration creditCardColumnConfig = new
EncryptColumnRuleConfiguration("credit_card", new
EncryptColumnItemRuleConfiguration("credit_card_cipher", "test_encryptor"));
EncryptTableRuleConfiguration tableConfig = new
EncryptTableRuleConfiguration("T_ENCRYPT", Arrays.asList(pwdColumnConfig,
creditCardColumnConfig));
return new
EncryptRuleConfiguration(Collections.singleton(tableConfig),
getEncryptors(standardEncryptConfig, queryAssistedEncryptConfig,
queryLikeEncryptConfig));
}
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 a580619ff53..39416e82134 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
@@ -17,6 +17,7 @@
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.exception.metadata.EncryptLogicColumnNotFoundException;
@@ -39,8 +40,10 @@ class EncryptTableTest {
@BeforeEach
void setUp() {
- encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt",
- Collections.singleton(new
EncryptColumnRuleConfiguration("logicColumn", "cipherColumn",
"assistedQueryColumn", "likeQueryColumn", "myEncryptor"))));
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("logicColumn", new
EncryptColumnItemRuleConfiguration("cipherColumn", "myEncryptor"));
+ columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("assistedQueryColumn"));
+ columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("likeQueryColumn"));
+ encryptTable = new EncryptTable(new
EncryptTableRuleConfiguration("t_encrypt",
Collections.singleton(columnRuleConfig)));
}
@Test
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
index d6283828b2d..c5d3e59fcc4 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.encrypt.yaml;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
@@ -32,15 +32,15 @@ class EncryptRuleConfigurationYamlIT extends
YamlRuleConfigurationIT {
@Override
protected void assertYamlRootConfiguration(final YamlRootConfiguration
actual) {
- assertEncryptRule((YamlEncryptRuleConfiguration)
actual.getRules().iterator().next());
+ assertEncryptRule((YamlCompatibleEncryptRuleConfiguration)
actual.getRules().iterator().next());
}
- private void assertEncryptRule(final YamlEncryptRuleConfiguration actual) {
+ private void assertEncryptRule(final
YamlCompatibleEncryptRuleConfiguration actual) {
assertColumns(actual);
assertEncryptAlgorithm(actual);
}
- private void assertColumns(final YamlEncryptRuleConfiguration actual) {
+ private void assertColumns(final YamlCompatibleEncryptRuleConfiguration
actual) {
assertThat(actual.getTables().size(), is(1));
assertThat(actual.getTables().get("t_user").getColumns().size(),
is(1));
assertThat(actual.getTables().get("t_user").getColumns().get("username").getCipherColumn(),
is("username_cipher"));
@@ -51,7 +51,7 @@ class EncryptRuleConfigurationYamlIT extends
YamlRuleConfigurationIT {
assertThat(actual.getTables().get("t_user").getColumns().get("username").getLikeQueryEncryptorName(),
is("like_encryptor"));
}
- private void assertEncryptAlgorithm(final YamlEncryptRuleConfiguration
actual) {
+ private void assertEncryptAlgorithm(final
YamlCompatibleEncryptRuleConfiguration actual) {
assertThat(actual.getEncryptors().size(), is(2));
assertThat(actual.getEncryptors().get("username_encryptor").getType(),
is("AES"));
assertThat(actual.getEncryptors().get("username_encryptor").getProps().get("aes-key-value"),
is("123456abc"));
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapperTest.java
similarity index 76%
rename from
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
rename to
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapperTest.java
index 35551fd70d5..d34fdd9fde5 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptRuleConfigurationSwapperTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlCompatibleEncryptRuleConfigurationSwapperTest.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.encrypt.yaml.swapper;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptTableRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPILoader;
import
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
@@ -36,11 +36,11 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
-class YamlEncryptRuleConfigurationSwapperTest {
+class YamlCompatibleEncryptRuleConfigurationSwapperTest {
@Test
void assertSwapToYamlConfiguration() {
- YamlEncryptRuleConfiguration actual =
getSwapper().swapToYamlConfiguration(createEncryptRuleConfiguration());
+ YamlCompatibleEncryptRuleConfiguration actual =
getSwapper().swapToYamlConfiguration(createEncryptRuleConfiguration());
assertThat(actual.getTables().size(), is(1));
assertThat(actual.getEncryptors().size(), is(1));
}
@@ -58,9 +58,9 @@ class YamlEncryptRuleConfigurationSwapperTest {
assertThat(actual.getEncryptors().size(), is(1));
}
- private YamlEncryptRuleConfiguration createYamlEncryptRuleConfiguration() {
- YamlEncryptRuleConfiguration result = new
YamlEncryptRuleConfiguration();
- YamlEncryptTableRuleConfiguration tableRuleConfig = new
YamlEncryptTableRuleConfiguration();
+ private YamlCompatibleEncryptRuleConfiguration
createYamlEncryptRuleConfiguration() {
+ YamlCompatibleEncryptRuleConfiguration result = new
YamlCompatibleEncryptRuleConfiguration();
+ YamlCompatibleEncryptTableRuleConfiguration tableRuleConfig = new
YamlCompatibleEncryptTableRuleConfiguration();
tableRuleConfig.setName("t_encrypt");
result.getTables().put("t_encrypt", tableRuleConfig);
YamlAlgorithmConfiguration algorithmConfig = new
YamlAlgorithmConfiguration();
@@ -69,8 +69,8 @@ class YamlEncryptRuleConfigurationSwapperTest {
return result;
}
- private YamlEncryptRuleConfigurationSwapper getSwapper() {
+ private YamlCompatibleEncryptRuleConfigurationSwapper getSwapper() {
EncryptRuleConfiguration ruleConfig =
mock(EncryptRuleConfiguration.class);
- return (YamlEncryptRuleConfigurationSwapper)
OrderedSPILoader.getServices(YamlRuleConfigurationSwapper.class,
Collections.singleton(ruleConfig)).get(ruleConfig);
+ return (YamlCompatibleEncryptRuleConfigurationSwapper)
OrderedSPILoader.getServices(YamlRuleConfigurationSwapper.class,
Collections.singleton(ruleConfig)).get(ruleConfig);
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapperTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapperTest.java
similarity index 55%
rename from
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapperTest.java
rename to
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapperTest.java
index b75282abed4..07ca6cd22dc 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptColumnRuleConfigurationSwapperTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptColumnRuleConfigurationSwapperTest.java
@@ -17,21 +17,24 @@
package org.apache.shardingsphere.encrypt.yaml.swapper.rule;
+import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptColumnRuleConfiguration;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-class YamlEncryptColumnRuleConfigurationSwapperTest {
+class YamlCompatibleEncryptColumnRuleConfigurationSwapperTest {
@Test
void assertSwapToYamlConfiguration() {
- YamlEncryptColumnRuleConfigurationSwapper swapper = new
YamlEncryptColumnRuleConfigurationSwapper();
- EncryptColumnRuleConfiguration encryptColumnRuleConfig =
- new EncryptColumnRuleConfiguration("logicColumn",
"cipherColumn", "assistedQueryColumn", "likeQueryColumn", "encryptorName");
- YamlEncryptColumnRuleConfiguration actual =
swapper.swapToYamlConfiguration(encryptColumnRuleConfig);
+ YamlCompatibleEncryptColumnRuleConfigurationSwapper swapper = new
YamlCompatibleEncryptColumnRuleConfigurationSwapper();
+ EncryptColumnRuleConfiguration encryptColumnRuleConfig = new
EncryptColumnRuleConfiguration("logicColumn", new
EncryptColumnItemRuleConfiguration("cipherColumn", "encryptorName"));
+ encryptColumnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("assistedQueryColumn"));
+ encryptColumnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("likeQueryColumn"));
+ YamlCompatibleEncryptColumnRuleConfiguration actual =
swapper.swapToYamlConfiguration(encryptColumnRuleConfig);
assertThat(actual.getLogicColumn(), is("logicColumn"));
assertThat(actual.getCipherColumn(), is("cipherColumn"));
assertThat(actual.getAssistedQueryColumn(), is("assistedQueryColumn"));
@@ -41,18 +44,20 @@ class YamlEncryptColumnRuleConfigurationSwapperTest {
@Test
void assertSwapToObject() {
- YamlEncryptColumnRuleConfigurationSwapper swapper = new
YamlEncryptColumnRuleConfigurationSwapper();
- YamlEncryptColumnRuleConfiguration yamlEncryptColumnRuleConfig = new
YamlEncryptColumnRuleConfiguration();
+ YamlCompatibleEncryptColumnRuleConfigurationSwapper swapper = new
YamlCompatibleEncryptColumnRuleConfigurationSwapper();
+ YamlCompatibleEncryptColumnRuleConfiguration
yamlEncryptColumnRuleConfig = new
YamlCompatibleEncryptColumnRuleConfiguration();
yamlEncryptColumnRuleConfig.setLogicColumn("logicColumn");
yamlEncryptColumnRuleConfig.setCipherColumn("cipherColumn");
yamlEncryptColumnRuleConfig.setAssistedQueryColumn("assistedQueryColumn");
yamlEncryptColumnRuleConfig.setLikeQueryColumn("likeQueryColumn");
yamlEncryptColumnRuleConfig.setEncryptorName("encryptorName");
EncryptColumnRuleConfiguration actual =
swapper.swapToObject(yamlEncryptColumnRuleConfig);
- assertThat(actual.getLogicColumn(), is("logicColumn"));
- assertThat(actual.getCipherColumn(), is("cipherColumn"));
- assertThat(actual.getAssistedQueryColumn(), is("assistedQueryColumn"));
- assertThat(actual.getLikeQueryColumn(), is("likeQueryColumn"));
- assertThat(actual.getEncryptorName(), is("encryptorName"));
+ assertThat(actual.getName(), is("logicColumn"));
+ assertThat(actual.getCipher().getName(), is("cipherColumn"));
+ assertTrue(actual.getAssistedQuery().isPresent());
+ assertThat(actual.getAssistedQuery().get().getName(),
is("assistedQueryColumn"));
+ assertTrue(actual.getLikeQuery().isPresent());
+ assertThat(actual.getLikeQuery().get().getName(),
is("likeQueryColumn"));
+ assertThat(actual.getCipher().getEncryptorName(), is("encryptorName"));
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapperTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapperTest.java
similarity index 56%
rename from
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapperTest.java
rename to
features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapperTest.java
index 03a77adda74..f39a6f46e4d 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlEncryptTableRuleConfigurationSwapperTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/YamlCompatibleEncryptTableRuleConfigurationSwapperTest.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.encrypt.yaml.swapper.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.yaml.config.rule.YamlEncryptColumnRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.rule.YamlCompatibleEncryptTableRuleConfiguration;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
@@ -30,44 +31,48 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-class YamlEncryptTableRuleConfigurationSwapperTest {
+class YamlCompatibleEncryptTableRuleConfigurationSwapperTest {
- private final YamlEncryptTableRuleConfigurationSwapper swapper = new
YamlEncryptTableRuleConfigurationSwapper();
+ private final YamlCompatibleEncryptTableRuleConfigurationSwapper swapper =
new YamlCompatibleEncryptTableRuleConfigurationSwapper();
@Test
void assertSwapToYamlConfiguration() {
+ EncryptColumnRuleConfiguration encryptColumnTwoConfig = new
EncryptColumnRuleConfiguration("encrypt_column_2", new
EncryptColumnItemRuleConfiguration("encrypt_cipher_2", "test_encryptor_2"));
+ EncryptColumnRuleConfiguration encryptColumnThreeConfig =
+ new EncryptColumnRuleConfiguration("encrypt_column_3", new
EncryptColumnItemRuleConfiguration("encrypt_cipher_3", "test_encryptor_3"));
Collection<EncryptColumnRuleConfiguration> encryptColumnRuleConfigs =
Arrays.asList(
- new EncryptColumnRuleConfiguration("encrypt_column_1",
"encrypt_cipher_1", "", "", "test_encryptor_1"),
- new EncryptColumnRuleConfiguration("encrypt_column_2",
"encrypt_cipher_2", "", "", "test_encryptor_2"),
- new EncryptColumnRuleConfiguration("encrypt_column_3",
"encrypt_cipher_3", "", "", "test_encryptor_3"));
+ new EncryptColumnRuleConfiguration("encrypt_column_1", new
EncryptColumnItemRuleConfiguration("encrypt_cipher_1", "test_encryptor_1")),
+ encryptColumnTwoConfig,
+ encryptColumnThreeConfig);
EncryptTableRuleConfiguration encryptTableRuleConfig = new
EncryptTableRuleConfiguration("test_table", encryptColumnRuleConfigs);
- YamlEncryptTableRuleConfiguration actualYamlEncryptTableRuleConfig =
swapper.swapToYamlConfiguration(encryptTableRuleConfig);
+ YamlCompatibleEncryptTableRuleConfiguration
actualYamlEncryptTableRuleConfig =
swapper.swapToYamlConfiguration(encryptTableRuleConfig);
assertThat(actualYamlEncryptTableRuleConfig.getName(),
is("test_table"));
- Map<String, YamlEncryptColumnRuleConfiguration> actualColumns =
actualYamlEncryptTableRuleConfig.getColumns();
+ Map<String, YamlCompatibleEncryptColumnRuleConfiguration>
actualColumns = actualYamlEncryptTableRuleConfig.getColumns();
assertThat(actualColumns.size(), is(3));
- YamlEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigFirst = actualColumns.get("encrypt_column_1");
+ YamlCompatibleEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigFirst = actualColumns.get("encrypt_column_1");
assertThat(actualYamlEncryptColumnRuleConfigFirst.getCipherColumn(),
is("encrypt_cipher_1"));
assertThat(actualYamlEncryptColumnRuleConfigFirst.getEncryptorName(),
is("test_encryptor_1"));
- YamlEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigSecond = actualColumns.get("encrypt_column_2");
+ YamlCompatibleEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigSecond = actualColumns.get("encrypt_column_2");
assertThat(actualYamlEncryptColumnRuleConfigSecond.getCipherColumn(),
is("encrypt_cipher_2"));
assertThat(actualYamlEncryptColumnRuleConfigSecond.getEncryptorName(),
is("test_encryptor_2"));
- YamlEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigThird = actualColumns.get("encrypt_column_3");
+ YamlCompatibleEncryptColumnRuleConfiguration
actualYamlEncryptColumnRuleConfigThird = actualColumns.get("encrypt_column_3");
assertThat(actualYamlEncryptColumnRuleConfigThird.getCipherColumn(),
is("encrypt_cipher_3"));
assertThat(actualYamlEncryptColumnRuleConfigThird.getEncryptorName(),
is("test_encryptor_3"));
}
@Test
void assertSwapToObject() {
- YamlEncryptColumnRuleConfiguration encryptColumnRuleConfig = new
YamlEncryptColumnRuleConfiguration();
+ YamlCompatibleEncryptColumnRuleConfiguration encryptColumnRuleConfig =
new YamlCompatibleEncryptColumnRuleConfiguration();
encryptColumnRuleConfig.setLogicColumn("encrypt_column");
encryptColumnRuleConfig.setCipherColumn("encrypt_cipher");
encryptColumnRuleConfig.setAssistedQueryColumn("encrypt_assisted");
encryptColumnRuleConfig.setLikeQueryColumn("encrypt_like");
encryptColumnRuleConfig.setEncryptorName("test_encryptor");
- Map<String, YamlEncryptColumnRuleConfiguration> columns = new
LinkedHashMap<>(1);
+ Map<String, YamlCompatibleEncryptColumnRuleConfiguration> columns =
new LinkedHashMap<>(1);
columns.put("test_column", encryptColumnRuleConfig);
- YamlEncryptTableRuleConfiguration yamlEncryptTableRuleConfig = new
YamlEncryptTableRuleConfiguration();
+ YamlCompatibleEncryptTableRuleConfiguration yamlEncryptTableRuleConfig
= new YamlCompatibleEncryptTableRuleConfiguration();
yamlEncryptTableRuleConfig.setName("test_table");
yamlEncryptTableRuleConfig.setColumns(columns);
EncryptTableRuleConfiguration actualEncryptTableRuleConfig =
swapper.swapToObject(yamlEncryptTableRuleConfig);
@@ -75,10 +80,12 @@ class YamlEncryptTableRuleConfigurationSwapperTest {
Collection<EncryptColumnRuleConfiguration> actualColumns =
actualEncryptTableRuleConfig.getColumns();
assertThat(actualColumns.size(), is(1));
EncryptColumnRuleConfiguration actualEncryptColumnRuleConfig =
actualColumns.iterator().next();
- assertThat(actualEncryptColumnRuleConfig.getLogicColumn(),
is("test_column"));
- assertThat(actualEncryptColumnRuleConfig.getCipherColumn(),
is("encrypt_cipher"));
- assertThat(actualEncryptColumnRuleConfig.getAssistedQueryColumn(),
is("encrypt_assisted"));
- assertThat(actualEncryptColumnRuleConfig.getLikeQueryColumn(),
is("encrypt_like"));
- assertThat(actualEncryptColumnRuleConfig.getEncryptorName(),
is("test_encryptor"));
+ assertThat(actualEncryptColumnRuleConfig.getName(), is("test_column"));
+ assertThat(actualEncryptColumnRuleConfig.getCipher().getName(),
is("encrypt_cipher"));
+
assertTrue(actualEncryptColumnRuleConfig.getAssistedQuery().isPresent());
+
assertThat(actualEncryptColumnRuleConfig.getAssistedQuery().get().getName(),
is("encrypt_assisted"));
+ assertTrue(actualEncryptColumnRuleConfig.getLikeQuery().isPresent());
+
assertThat(actualEncryptColumnRuleConfig.getLikeQuery().get().getName(),
is("encrypt_like"));
+
assertThat(actualEncryptColumnRuleConfig.getCipher().getEncryptorName(),
is("test_encryptor"));
}
}
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
index 5ecc48f865f..7a41d02830a 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.encrypt.distsql.handler.converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.distsql.parser.segment.EncryptColumnSegment;
@@ -62,11 +63,15 @@ public final class EncryptRuleStatementConverter {
}
private static EncryptColumnRuleConfiguration
createEncryptColumnRuleConfiguration(final String tableName, final
EncryptColumnSegment columnSegment) {
+ EncryptColumnItemRuleConfiguration cipherColumnConfig = new
EncryptColumnItemRuleConfiguration(columnSegment.getCipherColumn(),
getEncryptorName(tableName, columnSegment.getName()));
+ EncryptColumnRuleConfiguration result = new
EncryptColumnRuleConfiguration(columnSegment.getName(), cipherColumnConfig);
String assistedQueryEncryptorName = null ==
columnSegment.getAssistedQueryEncryptor() ? null :
getAssistedQueryEncryptorName(tableName, columnSegment.getName());
+ EncryptColumnItemRuleConfiguration assistedQueryColumnConfig = new
EncryptColumnItemRuleConfiguration(columnSegment.getAssistedQueryColumn(),
assistedQueryEncryptorName);
+ result.setAssistedQuery(assistedQueryColumnConfig);
String likeQueryEncryptorName = null ==
columnSegment.getLikeQueryEncryptor() ? null :
getLikeQueryEncryptorName(tableName, columnSegment.getName());
- return new EncryptColumnRuleConfiguration(columnSegment.getName(),
columnSegment.getCipherColumn(), columnSegment.getAssistedQueryColumn(),
- columnSegment.getLikeQueryColumn(),
getEncryptorName(tableName, columnSegment.getName()),
- assistedQueryEncryptorName, likeQueryEncryptorName);
+ EncryptColumnItemRuleConfiguration likeQueryColumnConfig = new
EncryptColumnItemRuleConfiguration(columnSegment.getLikeQueryColumn(),
likeQueryEncryptorName);
+ result.setLikeQuery(likeQueryColumnConfig);
+ return result;
}
private static Map<String, AlgorithmConfiguration>
createEncryptorConfigurations(final EncryptRuleSegment ruleSegment) {
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
index f9b09f98a2a..1f74f43ab98 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.encrypt.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.distsql.parser.statement.ShowEncryptRulesStatement;
@@ -60,15 +61,15 @@ public final class ShowEncryptRuleExecutor implements
RQLExecutor<ShowEncryptRul
private Collection<LocalDataQueryResultRow> buildColumnData(final
EncryptTableRuleConfiguration tableRuleConfig, final Map<String,
AlgorithmConfiguration> encryptors) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (EncryptColumnRuleConfiguration each :
tableRuleConfig.getColumns()) {
- AlgorithmConfiguration encryptorAlgorithmConfig =
encryptors.get(each.getEncryptorName());
- AlgorithmConfiguration assistedQueryEncryptorAlgorithmConfig =
encryptors.get(each.getAssistedQueryEncryptorName());
- AlgorithmConfiguration likeQueryEncryptorAlgorithmConfig =
encryptors.get(each.getLikeQueryEncryptorName());
+ AlgorithmConfiguration encryptorAlgorithmConfig =
encryptors.get(each.getCipher().getEncryptorName());
+ AlgorithmConfiguration assistedQueryEncryptorAlgorithmConfig =
each.getAssistedQuery().isPresent() ?
encryptors.get(each.getAssistedQuery().get().getEncryptorName()) : null;
+ AlgorithmConfiguration likeQueryEncryptorAlgorithmConfig =
each.getLikeQuery().isPresent() ?
encryptors.get(each.getLikeQuery().get().getEncryptorName()) : null;
result.add(new LocalDataQueryResultRow(Arrays.asList(
tableRuleConfig.getName(),
- each.getLogicColumn(),
- each.getCipherColumn(),
- nullToEmptyString(each.getAssistedQueryColumn()),
- nullToEmptyString(each.getLikeQueryColumn()),
+ each.getName(),
+ each.getCipher().getName(),
+
each.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
+
each.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
encryptorAlgorithmConfig.getType(),
PropertiesConverter.convert(encryptorAlgorithmConfig.getProps()),
Objects.isNull(assistedQueryEncryptorAlgorithmConfig) ?
nullToEmptyString(null) : assistedQueryEncryptorAlgorithmConfig.getType(),
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
index 4a80df60a6e..f12bb21b1d8 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java
@@ -23,7 +23,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredR
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionAlterUpdater;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
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.EncryptColumnItemRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import
org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleStatementConverter;
import
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
@@ -118,11 +118,13 @@ public final class AlterEncryptRuleStatementUpdater
implements RuleDefinitionAlt
}
private void dropUnusedEncryptor(final EncryptRuleConfiguration
currentRuleConfig) {
- Collection<String> inUsedEncryptors =
currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getEncryptorName)
+ Collection<String> inUsedEncryptors =
currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(optional ->
optional.getCipher().getEncryptorName())
.collect(Collectors.toSet());
-
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getAssistedQueryEncryptorName)
+
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream())
+ .map(optional ->
optional.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(""))
.collect(Collectors.toSet()));
-
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getLikeQueryEncryptorName)
+
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream())
+ .map(optional ->
optional.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(""))
.collect(Collectors.toSet()));
Collection<String> unusedEncryptors =
currentRuleConfig.getEncryptors().keySet().stream().filter(each ->
!inUsedEncryptors.contains(each)).collect(Collectors.toSet());
unusedEncryptors.forEach(each ->
currentRuleConfig.getEncryptors().remove(each));
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
index 4dcdcb336e5..40a3c737bbd 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.encrypt.distsql.handler.update;
+import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
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.EncryptColumnItemRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
-import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
-import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -69,11 +69,13 @@ public final class DropEncryptRuleStatementUpdater
implements RuleDefinitionDrop
}
private void dropUnusedEncryptor(final EncryptRuleConfiguration
currentRuleConfig) {
- Collection<String> inUsedEncryptors =
currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getEncryptorName)
+ Collection<String> inUsedEncryptors =
currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(optional ->
optional.getCipher().getEncryptorName())
.collect(Collectors.toSet());
-
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getAssistedQueryEncryptorName)
+
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream())
+ .map(optional ->
optional.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(""))
.collect(Collectors.toSet()));
-
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream()).map(EncryptColumnRuleConfiguration::getLikeQueryEncryptorName)
+
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each ->
each.getColumns().stream())
+ .map(optional ->
optional.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(""))
.collect(Collectors.toSet()));
Collection<String> unusedEncryptors =
currentRuleConfig.getEncryptors().keySet().stream().filter(each ->
!inUsedEncryptors.contains(each)).collect(Collectors.toSet());
unusedEncryptors.forEach(each ->
currentRuleConfig.getEncryptors().remove(each));
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
index 72e342bee8c..b9a4660ef20 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
@@ -30,6 +30,7 @@ import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class EncryptRuleStatementConverterTest {
@@ -37,10 +38,11 @@ class EncryptRuleStatementConverterTest {
void assertCovert() {
EncryptRuleConfiguration actual =
EncryptRuleStatementConverter.convert(Collections.singleton(new
EncryptRuleSegment("t_encrypt", createColumns())));
assertThat(actual.getTables().iterator().next().getName(),
is("t_encrypt"));
-
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getLogicColumn(),
is("user_id"));
-
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getCipherColumn(),
is("user_cipher"));
-
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getAssistedQueryColumn(),
is("assisted_column"));
-
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getEncryptorName(),
is("t_encrypt_user_id"));
+
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getName(),
is("user_id"));
+
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getCipher().getName(),
is("user_cipher"));
+
assertTrue(actual.getTables().iterator().next().getColumns().iterator().next().getAssistedQuery().isPresent());
+
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getAssistedQuery().get().getName(),
is("assisted_column"));
+
assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getCipher().getEncryptorName(),
is("t_encrypt_user_id"));
}
private Collection<EncryptColumnSegment> createColumns() {
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
index 5c9f50e5480..91ae4f3949a 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.encrypt.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.distsql.parser.statement.ShowEncryptRulesStatement;
@@ -92,7 +93,9 @@ class ShowEncryptRuleExecutorTest {
}
private RuleConfiguration getRuleConfiguration() {
- EncryptColumnRuleConfiguration encryptColumnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "user_assisted",
"user_like", "test");
+ EncryptColumnRuleConfiguration encryptColumnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "test"));
+ encryptColumnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_assisted"));
+ encryptColumnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_like"));
EncryptTableRuleConfiguration encryptTableRuleConfig = new
EncryptTableRuleConfiguration("t_encrypt",
Collections.singleton(encryptColumnRuleConfig));
AlgorithmConfiguration shardingSphereAlgorithmConfig = new
AlgorithmConfiguration("md5", new Properties());
return new
EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig),
Collections.singletonMap("test", shardingSphereAlgorithmConfig));
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
index 1b8dbd96b69..a700db57641 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfi
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.distsql.parser.segment.EncryptColumnSegment;
@@ -102,7 +103,7 @@ class AlterEncryptRuleStatementUpdaterTest {
}
private EncryptRuleConfiguration
createCurrentRuleConfigurationWithMultipleTableRules() {
- EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "",
"t_encrypt_user_id_MD5");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "t_encrypt_user_id_MD5"));
EncryptTableRuleConfiguration tableRuleConfig = new
EncryptTableRuleConfiguration("t_encrypt",
Collections.singleton(columnRuleConfig));
Map<String, AlgorithmConfiguration> encryptors =
Collections.singletonMap("t_encrypt_user_id_MD5", new
AlgorithmConfiguration("TEST", new Properties()));
return new EncryptRuleConfiguration(new
LinkedList<>(Arrays.asList(tableRuleConfig,
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
index c454aa69105..37ea8a43ddb 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.encrypt.distsql.handler.update;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.distsql.parser.statement.DropEncryptRuleStatement;
@@ -95,8 +96,9 @@ class DropEncryptRuleStatementUpdaterTest {
}
private EncryptRuleConfiguration createCurrentRuleConfiguration() {
- EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "",
"t_encrypt_user_id_MD5", "t_encrypt_test_assisted",
- "t_encrypt_test_like");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "t_encrypt_user_id_MD5"));
+ columnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_assisted", "t_encrypt_test_assisted"));
+ columnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_like", "t_encrypt_test_like"));
Map<String, AlgorithmConfiguration> encryptors = new HashMap<>(3, 1);
encryptors.put("t_encrypt_user_id_MD5", new
AlgorithmConfiguration("TEST", new Properties()));
encryptors.put("t_encrypt_test_assisted", new
AlgorithmConfiguration("TEST", new Properties()));
@@ -106,7 +108,7 @@ class DropEncryptRuleStatementUpdaterTest {
}
private EncryptRuleConfiguration
createCurrentRuleConfigurationWithMultipleTableRules() {
- EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "",
"t_encrypt_user_id_MD5");
+ EncryptColumnRuleConfiguration columnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "t_encrypt_user_id_MD5"));
EncryptTableRuleConfiguration tableRuleConfig = new
EncryptTableRuleConfiguration("t_encrypt",
Collections.singleton(columnRuleConfig));
Map<String, AlgorithmConfiguration> encryptors =
Collections.singletonMap("t_encrypt_user_id_MD5", new
AlgorithmConfiguration("TEST", new Properties()));
return new EncryptRuleConfiguration(new
LinkedList<>(Arrays.asList(tableRuleConfig,
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
index 4203471d076..c500aeb4b52 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/EncryptRuleConfigurationImportChecker.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.check
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.spi.EncryptAlgorithm;
@@ -67,9 +68,11 @@ public final class EncryptRuleConfigurationImportChecker {
private void checkTableEncryptorsExisted(final EncryptRuleConfiguration
configuration, final String databaseName) {
Collection<EncryptColumnRuleConfiguration> columns = new
LinkedList<>();
configuration.getTables().forEach(each ->
columns.addAll(each.getColumns()));
- Collection<String> notExistedEncryptors =
columns.stream().map(EncryptColumnRuleConfiguration::getEncryptorName).collect(Collectors.toList());
-
notExistedEncryptors.addAll(columns.stream().map(EncryptColumnRuleConfiguration::getLikeQueryEncryptorName).filter(Objects::nonNull).collect(Collectors.toList()));
-
notExistedEncryptors.addAll(columns.stream().map(EncryptColumnRuleConfiguration::getAssistedQueryEncryptorName).filter(Objects::nonNull).collect(Collectors.toList()));
+ Collection<String> notExistedEncryptors =
columns.stream().map(optional ->
optional.getCipher().getEncryptorName()).collect(Collectors.toList());
+ notExistedEncryptors.addAll(
+ columns.stream().map(optional ->
optional.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList()));
+ notExistedEncryptors.addAll(columns.stream().map(optional ->
optional.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse(null)).filter(Objects::nonNull)
+ .collect(Collectors.toList()));
Collection<String> encryptors = configuration.getEncryptors().keySet();
notExistedEncryptors.removeIf(encryptors::contains);
ShardingSpherePreconditions.checkState(notExistedEncryptors.isEmpty(),
() -> new MissingRequiredAlgorithmException(databaseName,
notExistedEncryptors));
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
index 4debc62b29a..e1da9ec4621 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
@@ -23,10 +23,11 @@ import com.zaxxer.hikari.HikariDataSource;
import
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.yaml.config.YamlEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptRuleConfigurationSwapper;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlCompatibleEncryptRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
@@ -133,9 +134,9 @@ public final class ConvertYamlConfigurationExecutor
implements QueryableRALExecu
} else if (each instanceof
YamlReadwriteSplittingRuleConfiguration) {
YamlReadwriteSplittingRuleConfigurationSwapper swapper = new
YamlReadwriteSplittingRuleConfigurationSwapper();
result.put(swapper.getOrder(),
swapper.swapToObject((YamlReadwriteSplittingRuleConfiguration) each));
- } else if (each instanceof YamlEncryptRuleConfiguration) {
- YamlEncryptRuleConfigurationSwapper swapper = new
YamlEncryptRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlEncryptRuleConfiguration) each));
+ } else if (each instanceof YamlCompatibleEncryptRuleConfiguration)
{
+ YamlCompatibleEncryptRuleConfigurationSwapper swapper = new
YamlCompatibleEncryptRuleConfigurationSwapper();
+ result.put(swapper.getOrder(),
swapper.swapToObject((YamlCompatibleEncryptRuleConfiguration) each));
} else if (each instanceof YamlShadowRuleConfiguration) {
YamlShadowRuleConfigurationSwapper swapper = new
YamlShadowRuleConfigurationSwapper();
result.put(swapper.getOrder(),
swapper.swapToObject((YamlShadowRuleConfiguration) each));
@@ -449,7 +450,7 @@ public final class ConvertYamlConfigurationExecutor
implements QueryableRALExecu
while (iterator.hasNext()) {
EncryptColumnRuleConfiguration columnRuleConfig = iterator.next();
result.append(String.format(DistSQLScriptConstants.ENCRYPT_COLUMN,
- columnRuleConfig.getLogicColumn(),
getColumns(columnRuleConfig), getEncryptAlgorithms(columnRuleConfig,
encryptors)));
+ columnRuleConfig.getName(), getColumns(columnRuleConfig),
getEncryptAlgorithms(columnRuleConfig, encryptors)));
if (iterator.hasNext()) {
result.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
}
@@ -459,32 +460,32 @@ public final class ConvertYamlConfigurationExecutor
implements QueryableRALExecu
private String getColumns(final EncryptColumnRuleConfiguration ruleConfig)
{
StringBuilder result = new StringBuilder();
- String cipherColumnName = ruleConfig.getCipherColumn();
- if (null != cipherColumnName) {
+ String cipherColumnName = ruleConfig.getCipher().getName();
+ if (!Strings.isNullOrEmpty(cipherColumnName)) {
result.append(String.format(DistSQLScriptConstants.CIPHER,
cipherColumnName));
}
- if (null != ruleConfig.getAssistedQueryColumn()) {
- result.append(DistSQLScriptConstants.COMMA).append('
').append(String.format(DistSQLScriptConstants.ASSISTED_QUERY_COLUMN,
ruleConfig.getAssistedQueryColumn()));
+ if (ruleConfig.getAssistedQuery().isPresent()) {
+ result.append(DistSQLScriptConstants.COMMA).append('
').append(String.format(DistSQLScriptConstants.ASSISTED_QUERY_COLUMN,
ruleConfig.getAssistedQuery().get().getName()));
}
- if (null != ruleConfig.getLikeQueryColumn()) {
- result.append(DistSQLScriptConstants.COMMA).append('
').append(String.format(DistSQLScriptConstants.LIKE_QUERY_COLUMN,
ruleConfig.getLikeQueryColumn()));
+ if (ruleConfig.getLikeQuery().isPresent()) {
+ result.append(DistSQLScriptConstants.COMMA).append('
').append(String.format(DistSQLScriptConstants.LIKE_QUERY_COLUMN,
ruleConfig.getLikeQuery().get().getName()));
}
return result.toString();
}
private String getEncryptAlgorithms(final EncryptColumnRuleConfiguration
ruleConfig, final Map<String, AlgorithmConfiguration> encryptors) {
StringBuilder result = new StringBuilder();
- String cipherEncryptorName = ruleConfig.getEncryptorName();
- String assistedQueryEncryptorName =
ruleConfig.getAssistedQueryEncryptorName();
- String likeQueryEncryptorName = ruleConfig.getLikeQueryEncryptorName();
- if (null != cipherEncryptorName) {
+ String cipherEncryptorName = ruleConfig.getCipher().getEncryptorName();
+ String assistedQueryEncryptorName =
ruleConfig.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse("");
+ String likeQueryEncryptorName =
ruleConfig.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getEncryptorName).orElse("");
+ if (!Strings.isNullOrEmpty(cipherEncryptorName)) {
result.append(String.format(DistSQLScriptConstants.ENCRYPT_ALGORITHM,
getAlgorithmType(encryptors.get(cipherEncryptorName))));
}
- if (null != assistedQueryEncryptorName) {
+ if (!Strings.isNullOrEmpty(assistedQueryEncryptorName)) {
result.append(DistSQLScriptConstants.COMMA).append(' ')
.append(String.format(DistSQLScriptConstants.ASSISTED_QUERY_ALGORITHM,
getAlgorithmType(encryptors.get(assistedQueryEncryptorName))));
}
- if (null != likeQueryEncryptorName) {
+ if (!Strings.isNullOrEmpty(likeQueryEncryptorName)) {
result.append(DistSQLScriptConstants.COMMA).append(' ')
.append(String.format(DistSQLScriptConstants.LIKE_QUERY_ALGORITHM,
getAlgorithmType(encryptors.get(likeQueryEncryptorName))));
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 869984dab4c..e7bcfc6373e 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -24,8 +24,8 @@ import
org.apache.shardingsphere.distsql.handler.exception.storageunit.InvalidSt
import
org.apache.shardingsphere.distsql.handler.validate.DataSourcePropertiesValidateHandler;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptRuleConfigurationSwapper;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlCompatibleEncryptRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
@@ -169,9 +169,9 @@ public final class YamlDatabaseConfigurationImportExecutor {
ReadwriteSplittingRuleConfiguration
readwriteSplittingRuleConfig =
swapper.swapToObject((YamlReadwriteSplittingRuleConfiguration) each);
ruleConfigsMap.computeIfAbsent(swapper.getOrder(), key -> new
LinkedList<>());
ruleConfigsMap.get(swapper.getOrder()).add(readwriteSplittingRuleConfig);
- } else if (each instanceof YamlEncryptRuleConfiguration) {
- YamlEncryptRuleConfigurationSwapper swapper = new
YamlEncryptRuleConfigurationSwapper();
- EncryptRuleConfiguration encryptRuleConfig =
swapper.swapToObject((YamlEncryptRuleConfiguration) each);
+ } else if (each instanceof YamlCompatibleEncryptRuleConfiguration)
{
+ YamlCompatibleEncryptRuleConfigurationSwapper swapper = new
YamlCompatibleEncryptRuleConfigurationSwapper();
+ EncryptRuleConfiguration encryptRuleConfig =
swapper.swapToObject((YamlCompatibleEncryptRuleConfiguration) each);
ruleConfigsMap.computeIfAbsent(swapper.getOrder(), key -> new
LinkedList<>());
ruleConfigsMap.get(swapper.getOrder()).add(encryptRuleConfig);
} else if (each instanceof YamlShadowRuleConfiguration) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
index daf185372ae..632483f8f54 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.config;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import
org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
@@ -76,7 +76,8 @@ class ProxyConfigurationLoaderTest {
.filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each);
assertTrue(shardingRuleConfig.isPresent());
assertShardingRuleConfiguration(shardingRuleConfig.get());
- assertFalse(actual.getRules().stream().filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each).isPresent());
+ assertFalse(
+ actual.getRules().stream().filter(each -> each instanceof
YamlCompatibleEncryptRuleConfiguration).findFirst().map(each ->
(YamlCompatibleEncryptRuleConfiguration) each).isPresent());
}
private void assertShardingRuleConfiguration(final
YamlShardingRuleConfiguration actual) {
@@ -96,7 +97,8 @@ class ProxyConfigurationLoaderTest {
assertDataSourceConfiguration(actual.getDataSources().get("read_ds_0"),
"jdbc:mysql://127.0.0.1:3306/read_ds_0");
assertDataSourceConfiguration(actual.getDataSources().get("read_ds_1"),
"jdbc:mysql://127.0.0.1:3306/read_ds_1");
assertFalse(actual.getRules().stream().filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each).isPresent());
- assertFalse(actual.getRules().stream().filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each).isPresent());
+ assertFalse(
+ actual.getRules().stream().filter(each -> each instanceof
YamlCompatibleEncryptRuleConfiguration).findFirst().map(each ->
(YamlCompatibleEncryptRuleConfiguration) each).isPresent());
Optional<YamlReadwriteSplittingRuleConfiguration> ruleConfig =
actual.getRules().stream()
.filter(each -> each instanceof
YamlReadwriteSplittingRuleConfiguration).findFirst().map(each ->
(YamlReadwriteSplittingRuleConfiguration) each);
assertTrue(ruleConfig.isPresent());
@@ -116,13 +118,13 @@ class ProxyConfigurationLoaderTest {
assertDataSourceConfiguration(actual.getDataSources().get("ds_0"),
"jdbc:mysql://127.0.0.1:3306/encrypt_ds");
assertFalse(actual.getRules().stream()
.filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each).isPresent());
- Optional<YamlEncryptRuleConfiguration> encryptRuleConfig =
actual.getRules().stream()
- .filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each);
+ Optional<YamlCompatibleEncryptRuleConfiguration> encryptRuleConfig =
actual.getRules().stream()
+ .filter(each -> each instanceof
YamlCompatibleEncryptRuleConfiguration).findFirst().map(each ->
(YamlCompatibleEncryptRuleConfiguration) each);
assertTrue(encryptRuleConfig.isPresent());
assertEncryptRuleConfiguration(encryptRuleConfig.get());
}
- private void assertEncryptRuleConfiguration(final
YamlEncryptRuleConfiguration actual) {
+ private void assertEncryptRuleConfiguration(final
YamlCompatibleEncryptRuleConfiguration actual) {
assertThat(actual.getEncryptors().size(), is(2));
assertTrue(actual.getEncryptors().containsKey("aes_encryptor"));
assertTrue(actual.getEncryptors().containsKey("rc4_encryptor"));