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

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


The following commit(s) were added to refs/heads/master by this push:
     new d152b65f1f4 Refactor AuthorityRegistry (#29613)
d152b65f1f4 is described below

commit d152b65f1f4b977e1060c417399f9b91fa6d5dc0
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 1 15:43:23 2024 +0800

    Refactor AuthorityRegistry (#29613)
---
 .../infra/metadata/user/Grantee.java               | 18 +++++-----
 .../authority/model/AuthorityRegistry.java         | 11 ++++--
 ...DatabasePermittedAuthorityRegistryProvider.java |  6 ++--
 .../DatabasePermittedAuthorityRegistry.java        | 40 ----------------------
 .../AllPermittedAuthorityRegistryProvider.java     |  3 +-
 .../privilege/AllPermittedAuthorityRegistry.java   | 40 ----------------------
 6 files changed, 22 insertions(+), 96 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
index e939e5816d0..cd69911479c 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/user/Grantee.java
@@ -46,15 +46,6 @@ public final class Grantee {
         toString = username + "@" + hostname;
     }
     
-    @Override
-    public boolean equals(final Object obj) {
-        if (obj instanceof Grantee) {
-            Grantee grantee = (Grantee) obj;
-            return grantee.username.equalsIgnoreCase(username) && 
grantee.hostname.equalsIgnoreCase(hostname);
-        }
-        return false;
-    }
-    
     /**
      * Check if the grantee is acceptable.
      *
@@ -69,6 +60,15 @@ public final class Grantee {
         return isUnlimitedHost || grantee.hostname.equalsIgnoreCase(hostname);
     }
     
+    @Override
+    public boolean equals(final Object obj) {
+        if (obj instanceof Grantee) {
+            Grantee grantee = (Grantee) obj;
+            return grantee.username.equalsIgnoreCase(username) && 
grantee.hostname.equalsIgnoreCase(hostname);
+        }
+        return false;
+    }
+    
     @Override
     public int hashCode() {
         return hashCode;
diff --git 
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
 
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
index 8c73f9a77bc..f517a423ca6 100644
--- 
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
+++ 
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
@@ -17,14 +17,19 @@
 
 package org.apache.shardingsphere.authority.model;
 
+import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 
+import java.util.Map;
 import java.util.Optional;
 
 /**
  * Authority registry.
  */
-public interface AuthorityRegistry {
+@RequiredArgsConstructor
+public final class AuthorityRegistry {
+    
+    private final Map<Grantee, ShardingSpherePrivileges> granteePrivileges;
     
     /**
      * Find privileges.
@@ -32,5 +37,7 @@ public interface AuthorityRegistry {
      * @param grantee grantee
      * @return found privileges
      */
-    Optional<ShardingSpherePrivileges> findPrivileges(Grantee grantee);
+    public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee 
grantee) {
+        return granteePrivileges.keySet().stream().filter(each -> 
each.accept(grantee)).findFirst().map(granteePrivileges::get);
+    }
 }
diff --git 
a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
 
b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
index c631d4be6ef..082610fdf1d 100644
--- 
a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
+++ 
b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.authority.provider.database;
 
 import com.google.common.base.Preconditions;
 import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import 
org.apache.shardingsphere.authority.provider.database.privilege.DatabasePermittedAuthorityRegistry;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
 import 
org.apache.shardingsphere.authority.provider.database.privilege.DatabasePermittedPrivileges;
 import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -58,10 +58,10 @@ public final class 
DatabasePermittedAuthorityRegistryProvider implements Authori
     
     @Override
     public AuthorityRegistry build(final Collection<ShardingSphereUser> users) 
{
-        return new DatabasePermittedAuthorityRegistry(buildPrivileges(users, 
convertUserDatabases()));
+        return new AuthorityRegistry(buildPrivileges(users, 
convertUserDatabases()));
     }
     
-    private Map<Grantee, DatabasePermittedPrivileges> buildPrivileges(final 
Collection<ShardingSphereUser> users, final Map<ShardingSphereUser, 
Collection<String>> userDatabaseMappings) {
+    private Map<Grantee, ShardingSpherePrivileges> buildPrivileges(final 
Collection<ShardingSphereUser> users, final Map<ShardingSphereUser, 
Collection<String>> userDatabaseMappings) {
         return 
users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee, each -> 
new DatabasePermittedPrivileges(getUserDatabases(each, userDatabaseMappings))));
     }
     
diff --git 
a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/privilege/DatabasePermittedAuthorityRegistry.java
 
b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/privilege/DatabasePermittedAuthorityRegistry.java
deleted file mode 100644
index fb6df079c9f..00000000000
--- 
a/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/privilege/DatabasePermittedAuthorityRegistry.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.authority.provider.database.privilege;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Database permitted authority registry.
- */
-@RequiredArgsConstructor
-public final class DatabasePermittedAuthorityRegistry implements 
AuthorityRegistry {
-    
-    private final Map<Grantee, DatabasePermittedPrivileges> granteePrivileges;
-    
-    @Override
-    public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee 
grantee) {
-        return granteePrivileges.keySet().stream().filter(each -> 
each.accept(grantee)).findFirst().map(granteePrivileges::get);
-    }
-}
diff --git 
a/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
 
b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
index 5779d551e0c..a7e563401f7 100644
--- 
a/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
+++ 
b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.authority.provider.simple;
 
 import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import 
org.apache.shardingsphere.authority.provider.simple.privilege.AllPermittedAuthorityRegistry;
 import 
org.apache.shardingsphere.authority.provider.simple.privilege.AllPermittedPrivileges;
 import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -34,7 +33,7 @@ public final class AllPermittedAuthorityRegistryProvider 
implements AuthorityReg
     
     @Override
     public AuthorityRegistry build(final Collection<ShardingSphereUser> users) 
{
-        return new 
AllPermittedAuthorityRegistry(users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee,
 each -> new AllPermittedPrivileges())));
+        return new 
AuthorityRegistry(users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee,
 each -> new AllPermittedPrivileges())));
     }
     
     @Override
diff --git 
a/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedAuthorityRegistry.java
 
b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedAuthorityRegistry.java
deleted file mode 100644
index 30c34b630e0..00000000000
--- 
a/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedAuthorityRegistry.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.authority.provider.simple.privilege;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * All permitted authority registry.
- */
-@RequiredArgsConstructor
-public final class AllPermittedAuthorityRegistry implements AuthorityRegistry {
-    
-    private final Map<Grantee, AllPermittedPrivileges> granteePrivileges;
-    
-    @Override
-    public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee 
grantee) {
-        return granteePrivileges.keySet().stream().filter(each -> 
each.accept(grantee)).findFirst().map(granteePrivileges::get);
-    }
-}

Reply via email to