You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/04/03 15:21:49 UTC

[shardingsphere] branch master updated: Create authority module (#9930)

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

wuweijie 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 00b1703  Create authority module (#9930)
00b1703 is described below

commit 00b1703646aa8d144e73d4e56ae8514036bf690c
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Apr 3 23:21:23 2021 +0800

    Create authority module (#9930)
    
    * Add shardingsphere-authority-api module
    
    * Add shardingsphere-authority-common module
    
    * Add todo
---
 shardingsphere-features/pom.xml                    |  1 +
 .../{ => shardingsphere-authority}/pom.xml         | 13 ++--
 .../shardingsphere-authority-api}/pom.xml          | 19 +++---
 .../api/config/AuthorityRuleConfiguration.java     | 35 +++++++++++
 .../authority/spi/PrivilegeLoadAlgorithm.java      | 43 +++++++++++++
 .../shardingsphere-authority-common}/pom.xml       | 19 +++---
 .../authority/constant/AuthorityOrder.java         | 38 +++++++++++
 .../authority/rule/AuthorityRule.java              | 49 +++++++++++++++
 .../rule/builder/AuthorityRuleBuilder.java}        | 23 ++++---
 .../config/YamlAuthorityRuleConfiguration.java}    | 27 +++-----
 .../AuthorityRuleConfigurationYamlSwapper.java     | 73 ++++++++++++++++++++++
 ...re.infra.rule.builder.ShardingSphereRuleBuilder | 18 ++++++
 ...infra.yaml.swapper.YamlRuleConfigurationSwapper | 18 ++++++
 .../AlgorithmProvidedEncryptRuleConfiguration.java | 12 ++--
 .../encrypt/rule/builder/EncryptRuleBuilder.java   |  3 +-
 15 files changed, 324 insertions(+), 67 deletions(-)

diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/pom.xml
index c3e0567..3938036 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/pom.xml
@@ -35,5 +35,6 @@
         <module>shardingsphere-db-discovery</module>
         <module>shardingsphere-encrypt</module>
         <module>shardingsphere-shadow</module>
+        <module>shardingsphere-authority</module>
     </modules>
 </project>
diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/shardingsphere-authority/pom.xml
similarity index 79%
copy from shardingsphere-features/pom.xml
copy to shardingsphere-features/shardingsphere-authority/pom.xml
index c3e0567..d774882 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/shardingsphere-authority/pom.xml
@@ -22,18 +22,15 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere</artifactId>
+        <artifactId>shardingsphere-features</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-features</artifactId>
-    <packaging>pom</packaging>
+    <artifactId>shardingsphere-authority</artifactId>
     <name>${project.artifactId}</name>
+    <packaging>pom</packaging>
     
     <modules>
-        <module>shardingsphere-sharding</module>
-        <module>shardingsphere-read-write-splitting</module>
-        <module>shardingsphere-db-discovery</module>
-        <module>shardingsphere-encrypt</module>
-        <module>shardingsphere-shadow</module>
+        <module>shardingsphere-authority-api</module>
+        <module>shardingsphere-authority-common</module>
     </modules>
 </project>
diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/pom.xml
similarity index 75%
copy from shardingsphere-features/pom.xml
copy to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/pom.xml
index c3e0567..03b74a0 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/pom.xml
@@ -22,18 +22,17 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere</artifactId>
+        <artifactId>shardingsphere-features</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-features</artifactId>
-    <packaging>pom</packaging>
+    <artifactId>shardingsphere-authority-api</artifactId>
     <name>${project.artifactId}</name>
     
-    <modules>
-        <module>shardingsphere-sharding</module>
-        <module>shardingsphere-read-write-splitting</module>
-        <module>shardingsphere-db-discovery</module>
-        <module>shardingsphere-encrypt</module>
-        <module>shardingsphere-shadow</module>
-    </modules>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-infra-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
 </project>
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
new file mode 100644
index 0000000..ae1ac00
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * 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.authority.api.config;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+
+import java.util.Map;
+
+/**
+ * Authority rule configuration.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class AuthorityRuleConfiguration implements RuleConfiguration {
+    
+    private final Map<String, ShardingSphereAlgorithmConfiguration> privilegeLoaders;
+}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
new file mode 100644
index 0000000..b0f2349
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
@@ -0,0 +1,43 @@
+/*
+ * 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.authority.spi;
+
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.auth.model.privilege.ShardingSpherePrivilege;
+import org.apache.shardingsphere.infra.metadata.auth.model.user.ShardingSphereUser;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Privilege load algorithm.
+ */
+public interface PrivilegeLoadAlgorithm extends ShardingSphereAlgorithm {
+    
+    /**
+     * Load privileges.
+     * 
+     * @param metaDataList meta data list
+     * @param users users
+     * @param props configuration properties
+     * @return map of users and privileges
+     */
+    Map<ShardingSphereUser, ShardingSpherePrivilege> load(Collection<ShardingSphereMetaData> metaDataList, Collection<ShardingSphereUser> users, ConfigurationProperties props);
+}
diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/pom.xml
similarity index 75%
copy from shardingsphere-features/pom.xml
copy to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/pom.xml
index c3e0567..17817bd 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/pom.xml
@@ -22,18 +22,17 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere</artifactId>
+        <artifactId>shardingsphere-authority</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-features</artifactId>
-    <packaging>pom</packaging>
+    <artifactId>shardingsphere-authority-common</artifactId>
     <name>${project.artifactId}</name>
     
-    <modules>
-        <module>shardingsphere-sharding</module>
-        <module>shardingsphere-read-write-splitting</module>
-        <module>shardingsphere-db-discovery</module>
-        <module>shardingsphere-encrypt</module>
-        <module>shardingsphere-shadow</module>
-    </modules>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-authority-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
 </project>
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/constant/AuthorityOrder.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/constant/AuthorityOrder.java
new file mode 100644
index 0000000..a84c10d
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/constant/AuthorityOrder.java
@@ -0,0 +1,38 @@
+/*
+ * 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.authority.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Authority order.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class AuthorityOrder {
+    
+    /**
+     * Authority order.
+     */
+    public static final int ORDER = -100;
+    
+    /**
+     * Algorithm provider authority order.
+     */
+    public static final int ALGORITHM_PROVIDER_AUTHORITY_ORDER = -99;
+}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
new file mode 100644
index 0000000..8c68c51
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -0,0 +1,49 @@
+/*
+ * 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.authority.rule;
+
+import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.metadata.auth.Authentication;
+import org.apache.shardingsphere.infra.metadata.auth.AuthenticationContext;
+import org.apache.shardingsphere.infra.metadata.auth.builtin.DefaultAuthentication;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+
+/**
+ * Authority rule.
+ */
+public final class AuthorityRule implements ShardingSphereRule {
+    
+    static {
+        ShardingSphereServiceLoader.register(PrivilegeLoadAlgorithm.class);
+    }
+    
+    private final PrivilegeLoadAlgorithm privilegeLoader;
+    
+    public AuthorityRule(final AuthorityRuleConfiguration config) {
+        Preconditions.checkState(1 == config.getPrivilegeLoaders().size(), "Only support one privilege loader.");
+        privilegeLoader = ShardingSphereAlgorithmFactory.createAlgorithm(config.getPrivilegeLoaders().values().iterator().next(), PrivilegeLoadAlgorithm.class);
+        Authentication authentication = new DefaultAuthentication();
+        // TODO pass correct parameters
+        authentication.init(privilegeLoader.load(null, null, null));
+        AuthenticationContext.getInstance().init(authentication);
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java
similarity index 58%
copy from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
copy to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java
index 5250072..cd86683 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java
@@ -15,11 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.encrypt.rule.builder;
+package org.apache.shardingsphere.authority.rule.builder;
 
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
-import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.authority.constant.AuthorityOrder;
+import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder;
 
@@ -27,23 +27,22 @@ import javax.sql.DataSource;
 import java.util.Map;
 
 /**
- * Encrypt rule builder.
+ * Authority rule builder.
  */
-public final class EncryptRuleBuilder implements ShardingSphereRuleBuilder<EncryptRule, EncryptRuleConfiguration> {
+public final class AuthorityRuleBuilder implements ShardingSphereRuleBuilder<AuthorityRule, AuthorityRuleConfiguration> {
     
     @Override
-    public EncryptRule build(final String schemaName,
-                             final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final EncryptRuleConfiguration ruleConfig) {
-        return new EncryptRule(ruleConfig);
+    public AuthorityRule build(final String schemaName, final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final AuthorityRuleConfiguration ruleConfig) {
+        return new AuthorityRule(ruleConfig);
     }
     
     @Override
     public int getOrder() {
-        return EncryptOrder.ORDER;
+        return AuthorityOrder.ORDER;
     }
     
     @Override
-    public Class<EncryptRuleConfiguration> getTypeClass() {
-        return EncryptRuleConfiguration.class;
+    public Class<AuthorityRuleConfiguration> getTypeClass() {
+        return AuthorityRuleConfiguration.class;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
similarity index 50%
copy from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
copy to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
index e955d18..9d3ca34 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
@@ -15,35 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.encrypt.algorithm.config;
+package org.apache.shardingsphere.authority.yaml.config;
 
 import lombok.Getter;
 import lombok.Setter;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
 
-import java.util.Collection;
 import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.Map;
 
 /**
- * Algorithm provided encrypt rule configuration.
+ * Authority rule configuration for YAML.
  */
 @Getter
 @Setter
-public final class AlgorithmProvidedEncryptRuleConfiguration implements RuleConfiguration {
+public final class YamlAuthorityRuleConfiguration implements YamlRuleConfiguration {
     
-    private Collection<EncryptTableRuleConfiguration> tables = new LinkedList<>();
+    private Map<String, YamlShardingSphereAlgorithmConfiguration> privilegeLoaders = new LinkedHashMap<>();
     
-    private Map<String, EncryptAlgorithm> encryptors = new LinkedHashMap<>();
-    
-    public AlgorithmProvidedEncryptRuleConfiguration() {
-    }
-    
-    public AlgorithmProvidedEncryptRuleConfiguration(final Collection<EncryptTableRuleConfiguration> tables, final Map<String, EncryptAlgorithm> encryptors) {
-        this.tables = tables;
-        this.encryptors = encryptors;
+    @Override
+    public Class<AuthorityRuleConfiguration> getRuleConfigurationType() {
+        return AuthorityRuleConfiguration.class;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
new file mode 100644
index 0000000..7c23f55
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
@@ -0,0 +1,73 @@
+/*
+ * 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.authority.yaml.swapper;
+
+import org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.authority.constant.AuthorityOrder;
+import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.infra.yaml.swapper.algorithm.ShardingSphereAlgorithmConfigurationYamlSwapper;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Authority rule configuration YAML swapper.
+ */
+public final class AuthorityRuleConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlAuthorityRuleConfiguration, AuthorityRuleConfiguration> {
+    
+    private final ShardingSphereAlgorithmConfigurationYamlSwapper algorithmSwapper = new ShardingSphereAlgorithmConfigurationYamlSwapper();
+    
+    @Override
+    public YamlAuthorityRuleConfiguration swapToYamlConfiguration(final AuthorityRuleConfiguration data) {
+        YamlAuthorityRuleConfiguration result = new YamlAuthorityRuleConfiguration();
+        data.getPrivilegeLoaders().forEach((key, value) -> result.getPrivilegeLoaders().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
+        return result;
+    }
+    
+    @Override
+    public AuthorityRuleConfiguration swapToObject(final YamlAuthorityRuleConfiguration yamlConfig) {
+        return new AuthorityRuleConfiguration(swapAuthorityAlgorithm(yamlConfig));
+    }
+    
+    private Map<String, ShardingSphereAlgorithmConfiguration> swapAuthorityAlgorithm(final YamlAuthorityRuleConfiguration yamlConfig) {
+        Map<String, ShardingSphereAlgorithmConfiguration> result = new LinkedHashMap<>(yamlConfig.getPrivilegeLoaders().size(), 1);
+        for (Entry<String, YamlShardingSphereAlgorithmConfiguration> entry : yamlConfig.getPrivilegeLoaders().entrySet()) {
+            result.put(entry.getKey(), algorithmSwapper.swapToObject(entry.getValue()));
+        }
+        return result;
+    }
+    
+    @Override
+    public Class<AuthorityRuleConfiguration> getTypeClass() {
+        return AuthorityRuleConfiguration.class;
+    }
+    
+    @Override
+    public String getRuleTagName() {
+        return "Authority";
+    }
+    
+    @Override
+    public int getOrder() {
+        return AuthorityOrder.ORDER;
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
new file mode 100644
index 0000000..a944ba9
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.ShardingSphereRuleBuilder
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.authority.rule.builder.AuthorityRuleBuilder
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
new file mode 100644
index 0000000..2d0e30b
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.authority.yaml.swapper.AuthorityRuleConfigurationYamlSwapper
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
index e955d18..f4ba462 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.encrypt.algorithm.config;
 
+import lombok.AllArgsConstructor;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
 import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
@@ -31,6 +33,8 @@ import java.util.Map;
 /**
  * Algorithm provided encrypt rule configuration.
  */
+@AllArgsConstructor
+@NoArgsConstructor
 @Getter
 @Setter
 public final class AlgorithmProvidedEncryptRuleConfiguration implements RuleConfiguration {
@@ -38,12 +42,4 @@ public final class AlgorithmProvidedEncryptRuleConfiguration implements RuleConf
     private Collection<EncryptTableRuleConfiguration> tables = new LinkedList<>();
     
     private Map<String, EncryptAlgorithm> encryptors = new LinkedHashMap<>();
-    
-    public AlgorithmProvidedEncryptRuleConfiguration() {
-    }
-    
-    public AlgorithmProvidedEncryptRuleConfiguration(final Collection<EncryptTableRuleConfiguration> tables, final Map<String, EncryptAlgorithm> encryptors) {
-        this.tables = tables;
-        this.encryptors = encryptors;
-    }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
index 5250072..f63e6fa 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilder.java
@@ -32,8 +32,7 @@ import java.util.Map;
 public final class EncryptRuleBuilder implements ShardingSphereRuleBuilder<EncryptRule, EncryptRuleConfiguration> {
     
     @Override
-    public EncryptRule build(final String schemaName,
-                             final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final EncryptRuleConfiguration ruleConfig) {
+    public EncryptRule build(final String schemaName, final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType, final EncryptRuleConfiguration ruleConfig) {
         return new EncryptRule(ruleConfig);
     }