You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/22 23:19:34 UTC

[shardingsphere] branch master updated: Move EncryptRuleConfiguration check logic from EncryptRule to EncryptRuleConfigurationChecker (#19476)

This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 41bc836852f Move EncryptRuleConfiguration check logic from EncryptRule to EncryptRuleConfigurationChecker (#19476)
41bc836852f is described below

commit 41bc836852f6cbc7641773290878c4f4d9c508d6
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Sat Jul 23 07:19:26 2022 +0800

    Move EncryptRuleConfiguration check logic from EncryptRule to EncryptRuleConfigurationChecker (#19476)
    
    * Move EncryptRuleConfiguration check logic from EncryptRule to EncryptRuleConfigurationChecker
    
    * fix unit test
---
 .../AbstractEncryptRuleConfigurationChecker.java   | 41 +++++++++++++-
 ...thmProvidedEncryptRuleConfigurationChecker.java | 12 +++-
 .../checker/EncryptRuleConfigurationChecker.java   | 12 +++-
 .../shardingsphere/encrypt/rule/EncryptRule.java   | 64 ----------------------
 ...rovidedEncryptRuleConfigurationCheckerTest.java | 38 +++++++++++--
 .../EncryptRuleConfigurationCheckerTest.java       | 36 ++++++++++--
 .../encrypt/rule/EncryptRuleTest.java              | 18 ------
 ...ReadwriteSplittingRuleConfigurationChecker.java |  9 +--
 .../AbstractShardingRuleConfigurationChecker.java  | 34 ++++++------
 9 files changed, 144 insertions(+), 120 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AbstractEncryptRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AbstractEncryptRuleConfigurationChecker.java
index 0241dc95542..076914023f3 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AbstractEncryptRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AbstractEncryptRuleConfigurationChecker.java
@@ -18,9 +18,14 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
 
+import java.util.Collection;
+
 /**
  * Abstract encrypt rule configuration checker.
  * 
@@ -30,8 +35,40 @@ public abstract class AbstractEncryptRuleConfigurationChecker<T extends RuleConf
     
     @Override
     public final void check(final String databaseName, final T config) {
-        Preconditions.checkState(!isEmptyEncryptors(config), "No available encrypt rule configuration in database `%s`.", databaseName);
+        checkTableConfiguration(databaseName, getTables(config), getEncryptors(config));
+    }
+    
+    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);
+            }
+        }
+    }
+    
+    private void checkCipherColumnConfiguration(final String databaseName, final Collection<String> encryptors, final EncryptColumnRuleConfiguration column) {
+        Preconditions.checkState(!Strings.isNullOrEmpty(column.getCipherColumn()),
+                "Cipher column of `%s` can not be null in database `%s`.", column.getLogicColumn(), databaseName);
+        Preconditions.checkState(!Strings.isNullOrEmpty(column.getEncryptorName()),
+                "Encryptor name of `%s` can not be null in database `%s`.", column.getLogicColumn(), databaseName);
+        Preconditions.checkState(encryptors.contains(column.getEncryptorName()),
+                "Can not find encryptor `%s` in database `%s`.", column.getEncryptorName(), databaseName);
+    }
+    
+    private void checkAssistColumnConfiguration(final String databaseName, final Collection<String> encryptors, final EncryptColumnRuleConfiguration column) {
+        if (Strings.isNullOrEmpty(column.getAssistedQueryColumn()) && Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())) {
+            return;
+        }
+        Preconditions.checkState(!Strings.isNullOrEmpty(column.getAssistedQueryColumn()),
+                "Assisted query column of `%s` can not be null in database `%s`.", column.getLogicColumn(), databaseName);
+        Preconditions.checkState(!Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName()),
+                "Assisted query encryptor name of `%s` can not be null in database `%s`.", column.getLogicColumn(), databaseName);
+        Preconditions.checkState(encryptors.contains(column.getAssistedQueryEncryptorName()),
+                "Can not find assisted query encryptor `%s` in database `%s`.", column.getEncryptorName(), databaseName);
     }
     
-    protected abstract boolean isEmptyEncryptors(T config);
+    protected abstract Collection<String> getEncryptors(T config);
+    
+    protected abstract Collection<EncryptTableRuleConfiguration> getTables(T config);
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
index c4f38e8438d..bffb8c22861 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationChecker.java
@@ -18,16 +18,24 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 import org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
 
+import java.util.Collection;
+
 /**
  * Algorithm provided encrypt rule configuration checker.
  */
 public final class AlgorithmProvidedEncryptRuleConfigurationChecker extends AbstractEncryptRuleConfigurationChecker<AlgorithmProvidedEncryptRuleConfiguration> {
     
     @Override
-    protected boolean isEmptyEncryptors(final AlgorithmProvidedEncryptRuleConfiguration config) {
-        return config.getEncryptors().isEmpty();
+    protected Collection<String> getEncryptors(final AlgorithmProvidedEncryptRuleConfiguration config) {
+        return config.getEncryptors().keySet();
+    }
+    
+    @Override
+    protected Collection<EncryptTableRuleConfiguration> getTables(final AlgorithmProvidedEncryptRuleConfiguration config) {
+        return config.getTables();
     }
     
     @Override
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
index 8e0a0ca108a..c95c263855e 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
@@ -18,16 +18,24 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 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 java.util.Collection;
+
 /**
  * Encrypt rule configuration checker.
  */
 public final class EncryptRuleConfigurationChecker extends AbstractEncryptRuleConfigurationChecker<EncryptRuleConfiguration> {
     
     @Override
-    protected boolean isEmptyEncryptors(final EncryptRuleConfiguration config) {
-        return config.getEncryptors().isEmpty();
+    protected Collection<String> getEncryptors(final EncryptRuleConfiguration config) {
+        return config.getEncryptors().keySet();
+    }
+    
+    @Override
+    protected Collection<EncryptTableRuleConfiguration> getTables(final EncryptRuleConfiguration config) {
+        return config.getTables();
     }
     
     @Override
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index 5ba03d72e8b..aff04eea771 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -18,12 +18,9 @@
 package org.apache.shardingsphere.encrypt.rule;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
 import lombok.Getter;
 import org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.encrypt.context.EncryptContextBuilder;
 import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
@@ -60,7 +57,6 @@ public final class EncryptRule implements DatabaseRule, TableContainedRule {
     
     public EncryptRule(final EncryptRuleConfiguration ruleConfig) {
         configuration = ruleConfig;
-        Preconditions.checkArgument(isValidRuleConfiguration(ruleConfig), "Invalid encrypt column configurations in EncryptTableRuleConfigurations.");
         ruleConfig.getEncryptors().forEach((key, value) -> encryptors.put(key, EncryptAlgorithmFactory.newInstance(value)));
         ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new EncryptTable(each)));
         queryWithCipherColumn = ruleConfig.isQueryWithCipherColumn();
@@ -68,71 +64,11 @@ public final class EncryptRule implements DatabaseRule, TableContainedRule {
     
     public EncryptRule(final AlgorithmProvidedEncryptRuleConfiguration ruleConfig) {
         configuration = ruleConfig;
-        Preconditions.checkArgument(isValidRuleConfigurationWithAlgorithmProvided(ruleConfig), "Invalid encrypt column configurations in EncryptTableRuleConfigurations.");
         encryptors.putAll(ruleConfig.getEncryptors());
         ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new EncryptTable(each)));
         queryWithCipherColumn = ruleConfig.isQueryWithCipherColumn();
     }
     
-    private boolean isValidRuleConfiguration(final EncryptRuleConfiguration config) {
-        return (config.getTables().isEmpty() && config.getEncryptors().isEmpty()) || isValidTableConfiguration(config);
-    }
-    
-    private boolean isValidTableConfiguration(final EncryptRuleConfiguration config) {
-        for (EncryptTableRuleConfiguration table : config.getTables()) {
-            for (EncryptColumnRuleConfiguration column : table.getColumns()) {
-                if (!isValidCipherColumnConfiguration(config, column) || !isValidAssistColumnConfiguration(config, column)) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-    
-    private boolean isValidCipherColumnConfiguration(final EncryptRuleConfiguration encryptRuleConfig, final EncryptColumnRuleConfiguration column) {
-        return !Strings.isNullOrEmpty(column.getCipherColumn()) && !Strings.isNullOrEmpty(column.getEncryptorName()) && containsEncryptors(encryptRuleConfig, column.getEncryptorName());
-    }
-    
-    private boolean isValidAssistColumnConfiguration(final EncryptRuleConfiguration encryptRuleConfig, final EncryptColumnRuleConfiguration column) {
-        if (Strings.isNullOrEmpty(column.getAssistedQueryColumn()) && Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())) {
-            return true;
-        }
-        return !Strings.isNullOrEmpty(column.getAssistedQueryColumn()) && !Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())
-                && containsEncryptors(encryptRuleConfig, column.getAssistedQueryEncryptorName());
-    }
-    
-    private boolean containsEncryptors(final EncryptRuleConfiguration encryptRuleConfig, final String encryptorName) {
-        return encryptRuleConfig.getEncryptors().keySet().stream().anyMatch(each -> each.equals(encryptorName));
-    }
-    
-    private boolean isValidRuleConfigurationWithAlgorithmProvided(final AlgorithmProvidedEncryptRuleConfiguration config) {
-        return (config.getTables().isEmpty() && config.getEncryptors().isEmpty()) || isValidTableConfigurationWithAlgorithmProvided(config);
-    }
-    
-    private boolean isValidTableConfigurationWithAlgorithmProvided(final AlgorithmProvidedEncryptRuleConfiguration config) {
-        for (EncryptTableRuleConfiguration table : config.getTables()) {
-            for (EncryptColumnRuleConfiguration column : table.getColumns()) {
-                if (!isValidCipherColumnConfigurationWithAlgorithmProvided(config, column) || !isValidAssistColumnConfigurationWithAlgorithmProvided(config, column)) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-    
-    private boolean isValidCipherColumnConfigurationWithAlgorithmProvided(final AlgorithmProvidedEncryptRuleConfiguration encryptRuleConfig, final EncryptColumnRuleConfiguration column) {
-        return !Strings.isNullOrEmpty(column.getCipherColumn()) && !Strings.isNullOrEmpty(column.getEncryptorName())
-                && encryptRuleConfig.getEncryptors().containsKey(column.getEncryptorName());
-    }
-    
-    private boolean isValidAssistColumnConfigurationWithAlgorithmProvided(final AlgorithmProvidedEncryptRuleConfiguration encryptRuleConfig, final EncryptColumnRuleConfiguration column) {
-        if (Strings.isNullOrEmpty(column.getAssistedQueryColumn()) && Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())) {
-            return true;
-        }
-        return !Strings.isNullOrEmpty(column.getAssistedQueryColumn()) && !Strings.isNullOrEmpty(column.getAssistedQueryEncryptorName())
-                && encryptRuleConfig.getEncryptors().containsKey(column.getAssistedQueryEncryptorName());
-    }
-    
     /**
      * Find encrypt table.
      * 
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationCheckerTest.java
index 8ec69cf26f7..3440d21c59e 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationCheckerTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/AlgorithmProvidedEncryptRuleConfigurationCheckerTest.java
@@ -18,11 +18,14 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 import org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+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;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationCheckerFactory;
 import org.junit.Test;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Optional;
 
@@ -36,7 +39,7 @@ public final class AlgorithmProvidedEncryptRuleConfigurationCheckerTest {
     
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
-    public void assertValidCheck() {
+    public void assertCheckWhenConfigValidConfiguration() {
         AlgorithmProvidedEncryptRuleConfiguration config = createValidConfiguration();
         Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
         assertTrue(checker.isPresent());
@@ -44,26 +47,49 @@ public final class AlgorithmProvidedEncryptRuleConfigurationCheckerTest {
         checker.get().check("test", config);
     }
     
+    @SuppressWarnings("unchecked")
     private AlgorithmProvidedEncryptRuleConfiguration createValidConfiguration() {
         AlgorithmProvidedEncryptRuleConfiguration result = mock(AlgorithmProvidedEncryptRuleConfiguration.class);
-        EncryptAlgorithm<?, ?> encryptAlgorithm = mock(EncryptAlgorithm.class);
-        when(result.getEncryptors()).thenReturn(Collections.singletonMap("type1", encryptAlgorithm));
+        when(result.getEncryptors()).thenReturn(Collections.singletonMap("aes_encryptor", mock(EncryptAlgorithm.class)));
+        Collection<EncryptColumnRuleConfiguration> columns = Collections.singletonList(new EncryptColumnRuleConfiguration("user_id", "user_cipher", null, "user_plain", "aes_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
         return result;
     }
     
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(expected = IllegalStateException.class)
-    public void assertInvalidCheck() {
-        AlgorithmProvidedEncryptRuleConfiguration config = createInvalidConfiguration();
+    public void assertCheckWhenConfigInvalidCipherColumn() {
+        AlgorithmProvidedEncryptRuleConfiguration config = createInvalidCipherColumnConfig();
         Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
         assertTrue(checker.isPresent());
         assertThat(checker.get(), instanceOf(AlgorithmProvidedEncryptRuleConfigurationChecker.class));
         checker.get().check("test", config);
     }
     
-    private AlgorithmProvidedEncryptRuleConfiguration createInvalidConfiguration() {
+    private AlgorithmProvidedEncryptRuleConfiguration createInvalidCipherColumnConfig() {
         AlgorithmProvidedEncryptRuleConfiguration result = mock(AlgorithmProvidedEncryptRuleConfiguration.class);
         when(result.getEncryptors()).thenReturn(Collections.emptyMap());
+        Collection<EncryptColumnRuleConfiguration> columns = Collections.singletonList(new EncryptColumnRuleConfiguration("user_id", "user_cipher", null, "user_plain", "aes_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
+        return result;
+    }
+    
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    @Test(expected = IllegalStateException.class)
+    public void assertCheckWhenConfigInvalidAssistColumn() {
+        AlgorithmProvidedEncryptRuleConfiguration config = createInvalidAssistColumnConfig();
+        Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
+        assertTrue(checker.isPresent());
+        assertThat(checker.get(), instanceOf(AlgorithmProvidedEncryptRuleConfigurationChecker.class));
+        checker.get().check("test", config);
+    }
+    
+    private AlgorithmProvidedEncryptRuleConfiguration createInvalidAssistColumnConfig() {
+        AlgorithmProvidedEncryptRuleConfiguration result = mock(AlgorithmProvidedEncryptRuleConfiguration.class);
+        when(result.getEncryptors()).thenReturn(Collections.emptyMap());
+        Collection<EncryptColumnRuleConfiguration> columns =
+                Collections.singletonList(new EncryptColumnRuleConfiguration("user_id", "user_cipher", "user_assisted", "user_plain", "aes_encryptor", "aes_assisted_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
         return result;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
index 30fb1f66ce3..306b652542d 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationCheckerTest.java
@@ -18,11 +18,14 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationCheckerFactory;
 import org.junit.Test;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Optional;
 
@@ -36,7 +39,7 @@ public final class EncryptRuleConfigurationCheckerTest {
     
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
-    public void assertValidCheck() {
+    public void assertCheckWhenConfigValidConfiguration() {
         EncryptRuleConfiguration config = createValidConfiguration();
         Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
         assertTrue(checker.isPresent());
@@ -46,23 +49,46 @@ public final class EncryptRuleConfigurationCheckerTest {
     
     private EncryptRuleConfiguration createValidConfiguration() {
         EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
-        when(result.getEncryptors()).thenReturn(Collections.singletonMap("type1", mock(ShardingSphereAlgorithmConfiguration.class)));
+        when(result.getEncryptors()).thenReturn(Collections.singletonMap("aes_encryptor", mock(ShardingSphereAlgorithmConfiguration.class)));
+        Collection<EncryptColumnRuleConfiguration> columns = Collections.singletonList(new EncryptColumnRuleConfiguration("user_id", "user_cipher", null, "user_plain", "aes_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
         return result;
     }
     
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test(expected = IllegalStateException.class)
-    public void assertInvalidCheck() {
-        EncryptRuleConfiguration config = createInvalidConfiguration();
+    public void assertCheckWhenConfigInvalidCipherColumn() {
+        EncryptRuleConfiguration config = createInvalidCipherColumnConfig();
         Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
         assertTrue(checker.isPresent());
         assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
         checker.get().check("test", config);
     }
     
-    private EncryptRuleConfiguration createInvalidConfiguration() {
+    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, "user_plain", "aes_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
+        return result;
+    }
+    
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    @Test(expected = IllegalStateException.class)
+    public void assertCheckWhenConfigInvalidAssistColumn() {
+        EncryptRuleConfiguration config = createInvalidAssistColumnConfig();
+        Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(config);
+        assertTrue(checker.isPresent());
+        assertThat(checker.get(), instanceOf(EncryptRuleConfigurationChecker.class));
+        checker.get().check("test", config);
+    }
+    
+    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", "user_plain", "aes_encryptor", "aes_assisted_encryptor", false));
+        when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("t_encrypt", columns, false)));
         return result;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index 25408e351ee..89143e6a4c0 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -58,24 +58,6 @@ public final class EncryptRuleTest {
         assertTrue(actual.findEncryptTable("t_encrypt").isPresent());
     }
     
-    @Test(expected = IllegalArgumentException.class)
-    public void assertNewInstanceWithInvalidConfiguration() {
-        ShardingSphereAlgorithmConfiguration encryptAlgorithmConfig = new ShardingSphereAlgorithmConfiguration("CORE.FIXTURE", new Properties());
-        EncryptColumnRuleConfiguration encryptColumnConfig = new EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", "test_encryptor", null);
-        EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singletonList(encryptColumnConfig), null);
-        EncryptRuleConfiguration ruleConfig = new EncryptRuleConfiguration(Collections.singleton(tableConfig), Collections.singletonMap("invalid_encryptor", encryptAlgorithmConfig));
-        new EncryptRule(ruleConfig);
-    }
-    
-    @Test(expected = IllegalArgumentException.class)
-    public void assertNewInstanceWithInvalidAlgorithmProvidedEncryptRuleConfiguration() {
-        EncryptColumnRuleConfiguration encryptColumnConfig = new EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", "test_encryptor", null);
-        EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singletonList(encryptColumnConfig), null);
-        AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new AlgorithmProvidedEncryptRuleConfiguration(
-                Collections.singleton(tableConfig), Collections.singletonMap("invalid_encryptor", new CoreEncryptAlgorithmFixture()), true);
-        new EncryptRule(ruleConfig);
-    }
-    
     @Test
     public void assertFindEncryptTable() {
         assertTrue(new EncryptRule(createEncryptRuleConfiguration()).findEncryptTable("t_encrypt").isPresent());
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/AbstractReadwriteSplittingRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/AbstractReadwriteSplittingRuleConfigurationChecker.java
index 9d12d5546e9..32a77180269 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/AbstractReadwriteSplittingRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/AbstractReadwriteSplittingRuleConfigurationChecker.java
@@ -45,15 +45,16 @@ public abstract class AbstractReadwriteSplittingRuleConfigurationChecker<T exten
         for (ReadwriteSplittingDataSourceRuleConfiguration each : dataSources) {
             Preconditions.checkState(null != each.getStaticStrategy() || null != each.getDynamicStrategy(),
                     "No available readwrite-splitting rule configuration in database `%s`.", databaseName);
-            Optional.ofNullable(each.getStaticStrategy()).ifPresent(optional -> checkStaticStrategy(writeDataSourceNames, readDataSourceNames, optional));
+            Optional.ofNullable(each.getStaticStrategy()).ifPresent(optional -> checkStaticStrategy(databaseName, writeDataSourceNames, readDataSourceNames, optional));
         }
     }
     
-    private void checkStaticStrategy(final Collection<String> writeDataSourceNames, final Collection<String> readDataSourceNames, final StaticReadwriteSplittingStrategyConfiguration strategyConfig) {
+    private void checkStaticStrategy(final String databaseName, final Collection<String> writeDataSourceNames,
+                                     final Collection<String> readDataSourceNames, final StaticReadwriteSplittingStrategyConfiguration strategyConfig) {
         Preconditions.checkState(writeDataSourceNames.add(strategyConfig.getWriteDataSourceName()),
-                "Can not config duplicate write dataSource `%s` in multi readwrite-splitting rule configurations.", strategyConfig.getWriteDataSourceName());
+                "Can not config duplicate write dataSource `%s` in database `%s`.", strategyConfig.getWriteDataSourceName(), databaseName);
         Preconditions.checkState(readDataSourceNames.addAll(strategyConfig.getReadDataSourceNames()),
-                "Can not config duplicate read dataSources `%s` in multi readwrite-splitting rule configurations.", strategyConfig.getReadDataSourceNames());
+                "Can not config duplicate read dataSources `%s` in database `%s`.", strategyConfig.getReadDataSourceNames(), databaseName);
     }
     
     protected abstract Collection<ReadwriteSplittingDataSourceRuleConfiguration> getDataSources(T config);
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/AbstractShardingRuleConfigurationChecker.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/AbstractShardingRuleConfigurationChecker.java
index 88d978f53d7..a1fb1d7c7ce 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/AbstractShardingRuleConfigurationChecker.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/AbstractShardingRuleConfigurationChecker.java
@@ -41,31 +41,31 @@ public abstract class AbstractShardingRuleConfigurationChecker<T extends RuleCon
         Collection<String> keyGenerators = getKeyGenerators(config);
         Collection<String> auditors = getAuditors(config);
         Collection<String> shardingAlgorithms = getShardingAlgorithms(config);
-        checkTableConfiguration(getTables(config), getAutoTables(config), keyGenerators, auditors, shardingAlgorithms, databaseName);
-        checkKeyGenerateStrategy(getDefaultKeyGenerateStrategy(config), keyGenerators, databaseName);
-        checkAuditStrategy(getDefaultAuditStrategy(config), auditors, databaseName);
-        checkShardingStrategy(getDefaultDatabaseShardingStrategy(config), shardingAlgorithms, databaseName);
-        checkShardingStrategy(getDefaultTableShardingStrategy(config), shardingAlgorithms, databaseName);
+        checkTableConfiguration(databaseName, getTables(config), getAutoTables(config), keyGenerators, auditors, shardingAlgorithms);
+        checkKeyGenerateStrategy(databaseName, getDefaultKeyGenerateStrategy(config), keyGenerators);
+        checkAuditStrategy(databaseName, getDefaultAuditStrategy(config), auditors);
+        checkShardingStrategy(databaseName, getDefaultDatabaseShardingStrategy(config), shardingAlgorithms);
+        checkShardingStrategy(databaseName, getDefaultTableShardingStrategy(config), shardingAlgorithms);
     }
     
-    private void checkTableConfiguration(final Collection<ShardingTableRuleConfiguration> tables, final Collection<ShardingAutoTableRuleConfiguration> autoTables,
-                                         final Collection<String> keyGenerators, final Collection<String> auditors, final Collection<String> shardingAlgorithms, final String databaseName) {
+    private void checkTableConfiguration(final String databaseName, final Collection<ShardingTableRuleConfiguration> tables, final Collection<ShardingAutoTableRuleConfiguration> autoTables,
+                                         final Collection<String> keyGenerators, final Collection<String> auditors, final Collection<String> shardingAlgorithms) {
         Preconditions.checkState(!tables.isEmpty() || !autoTables.isEmpty(),
                 "No available sharding table or autoTable configurations in database `%s`.", databaseName);
         for (ShardingTableRuleConfiguration each : tables) {
-            checkKeyGenerateStrategy(each.getKeyGenerateStrategy(), keyGenerators, databaseName);
-            checkAuditStrategy(each.getAuditStrategy(), auditors, databaseName);
-            checkShardingStrategy(each.getDatabaseShardingStrategy(), shardingAlgorithms, databaseName);
-            checkShardingStrategy(each.getTableShardingStrategy(), shardingAlgorithms, databaseName);
+            checkKeyGenerateStrategy(databaseName, each.getKeyGenerateStrategy(), keyGenerators);
+            checkAuditStrategy(databaseName, each.getAuditStrategy(), auditors);
+            checkShardingStrategy(databaseName, each.getDatabaseShardingStrategy(), shardingAlgorithms);
+            checkShardingStrategy(databaseName, each.getTableShardingStrategy(), shardingAlgorithms);
         }
         for (ShardingAutoTableRuleConfiguration each : autoTables) {
-            checkKeyGenerateStrategy(each.getKeyGenerateStrategy(), keyGenerators, databaseName);
-            checkAuditStrategy(each.getAuditStrategy(), auditors, databaseName);
-            checkShardingStrategy(each.getShardingStrategy(), shardingAlgorithms, databaseName);
+            checkKeyGenerateStrategy(databaseName, each.getKeyGenerateStrategy(), keyGenerators);
+            checkAuditStrategy(databaseName, each.getAuditStrategy(), auditors);
+            checkShardingStrategy(databaseName, each.getShardingStrategy(), shardingAlgorithms);
         }
     }
     
-    private void checkKeyGenerateStrategy(final KeyGenerateStrategyConfiguration keyGenerateStrategy, final Collection<String> keyGenerators, final String databaseName) {
+    private void checkKeyGenerateStrategy(final String databaseName, final KeyGenerateStrategyConfiguration keyGenerateStrategy, final Collection<String> keyGenerators) {
         if (null == keyGenerateStrategy) {
             return;
         }
@@ -73,7 +73,7 @@ public abstract class AbstractShardingRuleConfigurationChecker<T extends RuleCon
                 "Can not find keyGenerator `%s` in database `%s`.", keyGenerateStrategy.getKeyGeneratorName(), databaseName);
     }
     
-    private void checkAuditStrategy(final ShardingAuditStrategyConfiguration auditStrategy, final Collection<String> auditors, final String databaseName) {
+    private void checkAuditStrategy(final String databaseName, final ShardingAuditStrategyConfiguration auditStrategy, final Collection<String> auditors) {
         if (null == auditStrategy) {
             return;
         }
@@ -81,7 +81,7 @@ public abstract class AbstractShardingRuleConfigurationChecker<T extends RuleCon
                 "Can not find all auditors `%s` in database `%s`.", auditStrategy.getAuditorNames(), databaseName);
     }
     
-    private void checkShardingStrategy(final ShardingStrategyConfiguration shardingStrategy, final Collection<String> shardingAlgorithms, final String databaseName) {
+    private void checkShardingStrategy(final String databaseName, final ShardingStrategyConfiguration shardingStrategy, final Collection<String> shardingAlgorithms) {
         if (null == shardingStrategy || shardingStrategy instanceof NoneShardingStrategyConfiguration) {
             return;
         }