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/06/08 13:05:44 UTC

[shardingsphere] branch master updated: add AssistEncryptorName (#18166)

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

zhangliang 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 4352301b504 add AssistEncryptorName (#18166)
4352301b504 is described below

commit 4352301b504b5799797e112ebb6186af9cf8b8fb
Author: cheese8 <yi...@163.com>
AuthorDate: Wed Jun 8 21:05:40 2022 +0800

    add AssistEncryptorName (#18166)
    
    * add AssistEncryptorName
    
    * Update LocalEncryptConfiguration.java
    
    * add assistEncryptorName for EncryptColumn
    
    * refactor assistEncryptorName to assistedQueryEncryptorName
    
    * Update EncryptColumnRuleConfigurationYamlSwapper.java
    
    * Update EncryptColumnRuleConfiguration.java
    
    * revert old constructor
---
 .../encrypt/api/config/rule/EncryptColumnRuleConfiguration.java    | 7 +++++++
 .../java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java | 6 ++++++
 .../java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java  | 2 +-
 .../yaml/config/rule/YamlEncryptColumnRuleConfiguration.java       | 2 ++
 .../swapper/rule/EncryptColumnRuleConfigurationYamlSwapper.java    | 2 +-
 .../org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java    | 6 ++++++
 .../distsql/handler/converter/EncryptRuleStatementConverter.java   | 1 +
 .../spring/namespace/parser/EncryptRuleBeanDefinitionParser.java   | 1 +
 .../encrypt/spring/namespace/tag/EncryptRuleBeanDefinitionTag.java | 2 ++
 .../src/main/resources/META-INF/namespace/encrypt.xsd              | 1 +
 .../test/resources/scenario/encrypt/config/query-with-cipher.yaml  | 7 +++++++
 11 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
index ee60d721edb..e9ff4f2f135 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/api/config/rule/EncryptColumnRuleConfiguration.java
@@ -37,5 +37,12 @@ public final class EncryptColumnRuleConfiguration {
     
     private final String encryptorName;
     
+    private final String assistedQueryEncryptorName;
+    
     private final Boolean queryWithCipherColumn;
+    
+    public EncryptColumnRuleConfiguration(final String logicColumn, final String cipherColumn, final String assistedQueryColumn, final String plainColumn, 
+                                          final String encryptorName, final Boolean queryWithCipherColumn) {
+        this(logicColumn, cipherColumn, assistedQueryColumn, plainColumn, encryptorName, null, queryWithCipherColumn);
+    }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
index 3b1ed08b7c9..ce382462a11 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptColumn.java
@@ -38,8 +38,14 @@ public final class EncryptColumn {
     
     private final String encryptorName;
     
+    private final String assistedQueryEncryptorName;
+    
     private final Boolean queryWithCipherColumn;
     
+    public EncryptColumn(final String cipherColumn, final String assistedQueryColumn, final String plainColumn, final String encryptorName, final Boolean queryWithCipherColumn) {
+        this(cipherColumn, assistedQueryColumn, plainColumn, encryptorName, null, queryWithCipherColumn);
+    }
+    
     /**
      * Get assisted query column.
      * 
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
index 3a53c838154..97ec3f80f3a 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
@@ -42,7 +42,7 @@ public final class EncryptTable {
         columns = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         for (EncryptColumnRuleConfiguration each : config.getColumns()) {
             columns.put(each.getLogicColumn(), new EncryptColumn(each.getCipherColumn(), each.getAssistedQueryColumn(), each.getPlainColumn(), each.getEncryptorName(),
-                    each.getQueryWithCipherColumn()));
+                    each.getAssistedQueryEncryptorName(), each.getQueryWithCipherColumn()));
         }
         queryWithCipherColumn = config.getQueryWithCipherColumn();
     }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
index 111869a3b69..15e73516bf9 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/config/rule/YamlEncryptColumnRuleConfiguration.java
@@ -38,5 +38,7 @@ public final class YamlEncryptColumnRuleConfiguration implements YamlConfigurati
     
     private String encryptorName;
     
+    private String assistedQueryEncryptorName;
+    
     private Boolean queryWithCipherColumn;
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptColumnRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptColumnRuleConfigurationYamlSwapper.java
index b943c90c599..ec0bdaf11c8 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptColumnRuleConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/rule/EncryptColumnRuleConfigurationYamlSwapper.java
@@ -42,6 +42,6 @@ public final class EncryptColumnRuleConfigurationYamlSwapper implements YamlConf
     public EncryptColumnRuleConfiguration swapToObject(final YamlEncryptColumnRuleConfiguration yamlConfig) {
         return new EncryptColumnRuleConfiguration(
                 yamlConfig.getLogicColumn(), yamlConfig.getCipherColumn(), yamlConfig.getAssistedQueryColumn(), yamlConfig.getPlainColumn(), yamlConfig.getEncryptorName(),
-                yamlConfig.getQueryWithCipherColumn());
+                yamlConfig.getAssistedQueryEncryptorName(), yamlConfig.getQueryWithCipherColumn());
     }
 }
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 60e25e510f1..9ff9ede8dd5 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
@@ -210,6 +210,12 @@ public final class EncryptRuleTest {
         return new EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(queryAssistedEncryptConfig, metaDataAwareEncryptConfig));
     }
     
+    @Test
+    public void assertAssistedQueryEncryptorNameSpecified() {
+        EncryptColumnRuleConfiguration pwdColumnConfig = new EncryptColumnRuleConfiguration("pwd", "pwd_cipher", "pwd_assist", "pwd_plain", "test_encryptor", "assisted_query_test_encryptor", null);
+        assertTrue(pwdColumnConfig.getAssistedQueryEncryptorName().equals("assisted_query_test_encryptor"));
+    }
+    
     private EncryptRuleConfiguration createEncryptRuleConfigurationWithUpperCaseLogicTable() {
         ShardingSphereAlgorithmConfiguration queryAssistedEncryptConfig = new ShardingSphereAlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties());
         ShardingSphereAlgorithmConfiguration metaDataAwareEncryptConfig = new ShardingSphereAlgorithmConfiguration("CORE.METADATA_AWARE.FIXTURE", new Properties());
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
index 446d9ac403a..382d5c780fe 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
@@ -59,6 +59,7 @@ public final class EncryptRuleStatementConverter {
         return new EncryptTableRuleConfiguration(ruleSegment.getTableName(), columns, ruleSegment.getQueryWithCipherColumn());
     }
     
+    // FIXME: support assistedEncryptorName on EncryptColumnSegment later
     private static EncryptColumnRuleConfiguration createEncryptColumnRuleConfiguration(final String tableName, final EncryptColumnSegment columnSegment) {
         return new EncryptColumnRuleConfiguration(columnSegment.getName(), columnSegment.getCipherColumn(), columnSegment.getAssistedQueryColumn(),
                 columnSegment.getPlainColumn(), getEncryptorName(tableName, columnSegment.getName()), null);
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
index 578c0ba771a..4f35d76541c 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
@@ -83,6 +83,7 @@ public final class EncryptRuleBeanDefinitionParser extends AbstractBeanDefinitio
         factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.ASSISTED_QUERY_COLUMN_ATTRIBUTE));
         factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.PLAIN_COLUMN_ATTRIBUTE));
         factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.ENCRYPT_ALGORITHM_REF_ATTRIBUTE));
+        factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.ASSISTED_QUERY_ENCRYPT_ALGORITHM_REF_ATTRIBUTE));
         factory.addConstructorArgValue(element.getAttribute(EncryptRuleBeanDefinitionTag.QUERY_WITH_CIPHER_COLUMN));
         return factory.getBeanDefinition();
     }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptRuleBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptRuleBeanDefinitionTag.java
index 9fed72544f2..eb0bf75d4e1 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptRuleBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptRuleBeanDefinitionTag.java
@@ -42,5 +42,7 @@ public final class EncryptRuleBeanDefinitionTag {
     
     public static final String ENCRYPT_ALGORITHM_REF_ATTRIBUTE = "encrypt-algorithm-ref";
     
+    public static final String ASSISTED_QUERY_ENCRYPT_ALGORITHM_REF_ATTRIBUTE = "assisted-query-encrypt-algorithm-ref";
+    
     public static final String QUERY_WITH_CIPHER_COLUMN = "query-with-cipher-column";
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
index 261aa3fdda3..fe6edf80099 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/resources/META-INF/namespace/encrypt.xsd
@@ -49,6 +49,7 @@
             <xsd:attribute name="assisted-query-column" type="xsd:string" />
             <xsd:attribute name="plain-column" type="xsd:string" />
             <xsd:attribute name="encrypt-algorithm-ref" type="xsd:string" use="required" />
+            <xsd:attribute name="assisted-query-encrypt-algorithm-ref" type="xsd:string" />
             <xsd:attribute name="query-with-cipher-column" type="xsd:boolean" />
         </xsd:complexType>
     </xsd:element>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/config/query-with-cipher.yaml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/config/query-with-cipher.yaml
index f0d7f34814e..6d4ccb2985c 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/config/query-with-cipher.yaml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/config/query-with-cipher.yaml
@@ -28,10 +28,12 @@ rules:
           cipherColumn: cipher_certificate_number
           assistedQueryColumn: assisted_query_certificate_number
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         password:
           cipherColumn: cipher_password
           assistedQueryColumn: assisted_query_password
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         amount:
           cipherColumn: cipher_amount
           encryptorName: rewrite_normal_fixture
@@ -45,16 +47,19 @@ rules:
           assistedQueryColumn: assisted_query_certificate_number
           plainColumn: plain_certificate_number
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         password:
           cipherColumn: cipher_password
           assistedQueryColumn: assisted_query_password
           plainColumn: plain_password
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         password_new:
           cipherColumn: password_new_cipher
           assistedQueryColumn: password_new_assisted
           plainColumn: password_new_plain
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         amount:
           cipherColumn: cipher_amount
           plainColumn: plain_amount
@@ -66,11 +71,13 @@ rules:
           assistedQueryColumn: assisted_query_certificate_number
           plainColumn: plain_certificate_number
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         password:
           cipherColumn: cipher_password
           assistedQueryColumn: assisted_query_password
           plainColumn: plain_password
           encryptorName: rewrite_assisted_query_fixture
+          assistedQueryEncryptorName: rewrite_assisted_query_fixture
         amount:
           cipherColumn: cipher_amount
           plainColumn: plain_amount