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

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new a1a2545  Remove ShardingSphereAuthority.getAuthority() (#9978)
a1a2545 is described below

commit a1a25457cc7c5c44836e06616af519169666c143
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 7 21:38:06 2021 +0800

    Remove ShardingSphereAuthority.getAuthority() (#9978)
---
 .../authority/engine/ShardingSphereAuthority.java              |  7 -------
 .../shardingsphere/authority/engine/impl/DefaultAuthority.java |  9 +++------
 .../context/authority/GovernanceAuthorityContext.java          |  2 +-
 .../governance/core/registry/RegistryCenterTest.java           | 10 ++++------
 .../text/admin/mysql/executor/ShowDatabasesExecutorTest.java   |  5 ++++-
 .../frontend/mysql/auth/MySQLAuthenticationHandlerTest.java    |  4 +++-
 6 files changed, 15 insertions(+), 22 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
index 70072ad..e701594 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
@@ -37,13 +37,6 @@ public interface ShardingSphereAuthority {
     void init(Map<ShardingSphereUser, ShardingSpherePrivileges> 
loadedPrivileges);
     
     /**
-     * Get authority.
-     *
-     * @return authority
-     */
-    Map<ShardingSphereUser, ShardingSpherePrivileges> getAuthority();
-    
-    /**
      * Find Privileges.
      *
      * @param grantee grantee
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
index 09d7679..385fcc5 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
@@ -17,13 +17,11 @@
 
 package org.apache.shardingsphere.authority.engine.impl;
 
-import lombok.Getter;
 import org.apache.shardingsphere.authority.engine.ShardingSphereAuthority;
 import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 
-import java.util.Collection;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
@@ -31,18 +29,17 @@ import java.util.concurrent.ConcurrentHashMap;
 /**
  * Default authority.
 */
-@Getter
 public final class DefaultAuthority implements ShardingSphereAuthority {
     
-    private final Map<ShardingSphereUser, ShardingSpherePrivileges> authority 
= new ConcurrentHashMap<>();
+    private final Map<ShardingSphereUser, ShardingSpherePrivileges> 
userPrivilegeMap = new ConcurrentHashMap<>();
     
     @Override
     public void init(final Map<ShardingSphereUser, ShardingSpherePrivileges> 
loadedPrivileges) {
-        authority.putAll(loadedPrivileges);
+        userPrivilegeMap.putAll(loadedPrivileges);
     }
     
     @Override
     public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee 
grantee) {
-        return authority.keySet().stream().filter(each -> 
each.getGrantee().equals(grantee)).findFirst().map(authority::get);
+        return userPrivilegeMap.keySet().stream().filter(each -> 
each.getGrantee().equals(grantee)).findFirst().map(userPrivilegeMap::get);
     }
 }
diff --git 
a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
 
b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
index 9542af1..9b32a2d 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
@@ -104,7 +104,7 @@ public final class GovernanceAuthorityContext implements 
MetaDataAwareEventSubsc
         Optional<StoragePrivilegeLoader> loader = 
TypedSPIRegistry.findRegisteredService(StoragePrivilegeLoader.class, 
databaseType.getName(), new Properties());
         if (loader.isPresent()) {
             Map<ShardingSphereUser, ShardingSpherePrivileges> privileges = 
StoragePrivilegeBuilder.build(databaseType, 
metaDataContexts.getMetaDataMap().values(), users);
-            
authority.getAuthority().putAll(getPrivilegesWithPassword(privileges));
+            authority.init(getPrivilegesWithPassword(privileges));
         }
         AuthorityContext.getInstance().init(authority);
     }
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index 524e2a2..be300cf 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -35,14 +35,12 @@ import 
org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
 import 
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import 
org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import 
org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import 
org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
+import 
org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
 import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
index 6dcd742..aa5bfb5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
@@ -40,6 +40,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -69,7 +70,9 @@ public final class ShowDatabasesExecutorTest {
     
     private void initAuthority() {
         ShardingSphereAuthority authority = new DefaultAuthority();
-        authority.getAuthority().put(new ShardingSphereUser("root", "root", 
""), new ShardingSpherePrivileges());
+        Map<ShardingSphereUser, ShardingSpherePrivileges> userPrivilegeMap = 
new HashMap<>(1, 1);
+        userPrivilegeMap.put(new ShardingSphereUser("root", "root", ""), new 
ShardingSpherePrivileges());
+        authority.init(userPrivilegeMap);
         AuthorityContext.getInstance().init(authority);
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
index 17ff97c..cb4f971 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
@@ -125,7 +125,9 @@ public final class MySQLAuthenticationHandlerTest {
         DefaultAuthority authority = new DefaultAuthority();
         ShardingSpherePrivileges privileges = new ShardingSpherePrivileges();
         privileges.setSuperPrivilege();
-        authority.getAuthority().put(user, privileges);
+        Map<ShardingSphereUser, ShardingSpherePrivileges> userPrivilegeMap = 
new HashMap<>(1, 1);
+        userPrivilegeMap.put(user, privileges);
+        authority.init(userPrivilegeMap);
         initProxyContext(user);
     }
     

Reply via email to