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

sunnianjun 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 5d64c5343d3 Refactor AuthorityChecker (#31840)
5d64c5343d3 is described below

commit 5d64c5343d38a605c43077ddeda6f741b48527a6
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 25 19:44:53 2024 +0800

    Refactor AuthorityChecker (#31840)
    
    * Refactor AuthorityChecker
    
    * Refactor AuthorityChecker
    
    * Refactor AuthorityChecker
    
    * Refactor AuthorityChecker
---
 .../route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java    | 3 +--
 .../org/apache/shardingsphere/authority/checker/AuthorityChecker.java  | 3 +--
 .../handler/database/DatabaseOperateBackendHandlerFactoryTest.java     | 1 +
 .../shardingsphere/proxy/backend/session/ConnectionSessionTest.java    | 2 +-
 .../backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java  | 1 +
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
index 077a43219bc..edb3a260902 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngineTest.java
@@ -22,7 +22,6 @@ import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
 import 
org.apache.shardingsphere.infra.binder.context.statement.ddl.CursorStatementContext;
 import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -95,7 +94,7 @@ class ShardingUnicastRoutingEngineTest {
     
     @Test
     void assertRoutingForBroadcastTableWithPreferredDataSource() {
-        ConnectionContext connectionContext = new ConnectionContext(() -> 
Collections.singleton("ds_1"), new Grantee("", ""));
+        ConnectionContext connectionContext = new ConnectionContext(() -> 
Collections.singleton("ds_1"));
         RouteContext actual = new 
ShardingUnicastRoutingEngine(mock(SelectStatementContext.class), 
Collections.singleton("t_config"), connectionContext).route(shardingRule);
         assertThat(actual.getRouteUnits().size(), is(1));
         
assertThat(actual.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(),
 is("ds_1"));
diff --git 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
index 51d2d13a1e4..7e1bd6abd6c 100644
--- 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
+++ 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.authority.checker;
 
-import com.google.common.base.Strings;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
@@ -42,7 +41,7 @@ public final class AuthorityChecker {
      */
     @HighFrequencyInvocation
     public boolean isAuthorized(final String database) {
-        return null == grantee || Strings.isNullOrEmpty(grantee.getUsername()) 
|| rule.findUser(grantee).map(ShardingSphereUser::isAdmin).orElse(false)
+        return null == grantee || 
rule.findUser(grantee).map(ShardingSphereUser::isAdmin).orElse(false)
                 || rule.findPrivileges(grantee).map(optional -> 
optional.hasPrivileges(database)).orElse(false);
     }
 }
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java
index f05c74f8e80..3a9ccc62d66 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/database/DatabaseOperateBackendHandlerFactoryTest.java
@@ -79,6 +79,7 @@ class DatabaseOperateBackendHandlerFactoryTest {
     
     @BeforeEach
     void setUp() {
+        
when(connectionSession.getConnectionContext().getGrantee()).thenReturn(null);
         MetaDataContexts metaDataContexts = 
MetaDataContextsFactory.create(mock(MetaDataPersistService.class),
                 new ShardingSphereMetaData(getDatabases(), 
mock(ResourceMetaData.class), mock(RuleMetaData.class), new 
ConfigurationProperties(new Properties())));
         
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
index 6f48236847b..17073bbf0a0 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -60,7 +60,7 @@ class ConnectionSessionTest {
     @BeforeEach
     void setup() {
         connectionSession = new 
ConnectionSession(mock(MySQLDatabaseType.class), null);
-        connectionSession.setGrantee(new Grantee("", ""));
+        connectionSession.setGrantee(mock(Grantee.class));
         
when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
     }
     
diff --git 
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java
 
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java
index aae943a75ff..80a0630609e 100644
--- 
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java
+++ 
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UseDatabaseExecutorTest.java
@@ -67,6 +67,7 @@ class UseDatabaseExecutorTest {
         
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
         
when(ProxyContext.getInstance().databaseExists("db_0")).thenReturn(true);
         UseDatabaseExecutor executor = new UseDatabaseExecutor(useStatement);
+        
when(connectionSession.getConnectionContext().getGrantee()).thenReturn(null);
         executor.execute(connectionSession);
         verify(connectionSession).setCurrentDatabase(anyString());
     }

Reply via email to