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 ce1c5c8d07a Remove useless codes on AuthorityChecker (#29601)
ce1c5c8d07a is described below

commit ce1c5c8d07ae94846503517218f24f1774d79e5d
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Dec 30 11:47:27 2023 +0800

    Remove useless codes on AuthorityChecker (#29601)
---
 .../authority/checker/AuthorityChecker.java        | 25 ----------------------
 .../authority/checker/AuthorityCheckerTest.java    | 14 ------------
 .../handler/ProxyBackendHandlerFactory.java        |  3 ++-
 3 files changed, 2 insertions(+), 40 deletions(-)

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 3d8c1cac0d8..9666425f3b7 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
@@ -18,16 +18,8 @@
 package org.apache.shardingsphere.authority.checker;
 
 import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.authority.exception.UnauthorizedOperationException;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
-import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import 
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-import java.util.Optional;
 
 /**
  * Authority checker.
@@ -48,21 +40,4 @@ public final class AuthorityChecker {
     public boolean isAuthorized(final String databaseName) {
         return null == grantee || rule.findPrivileges(grantee).map(optional -> 
optional.hasPrivileges(databaseName)).orElse(false);
     }
-    
-    /**
-     * Check privileges.
-     *
-     * @param databaseName database name
-     * @param sqlStatement SQL statement
-     */
-    public void checkPrivileges(final String databaseName, final SQLStatement 
sqlStatement) {
-        if (null == grantee) {
-            return;
-        }
-        Optional<ShardingSpherePrivileges> privileges = 
rule.findPrivileges(grantee);
-        ShardingSpherePreconditions.checkState(null == databaseName || 
privileges.filter(optional -> optional.hasPrivileges(databaseName)).isPresent(),
-                () -> new UnknownDatabaseException(databaseName));
-        PrivilegeType privilegeType = 
PrivilegeTypeMapper.getPrivilegeType(sqlStatement);
-        ShardingSpherePreconditions.checkState(privileges.isPresent(), () -> 
new UnauthorizedOperationException(null == privilegeType ? "" : 
privilegeType.name()));
-    }
 }
diff --git 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
index fa7131afaa8..fb95a1bcc02 100644
--- 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
+++ 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
@@ -22,9 +22,6 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collection;
@@ -32,7 +29,6 @@ import java.util.Collections;
 import java.util.Properties;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
 
 class AuthorityCheckerTest {
     
@@ -42,14 +38,4 @@ class AuthorityCheckerTest {
         AuthorityRuleConfiguration ruleConfig = new 
AuthorityRuleConfiguration(users, new AlgorithmConfiguration("FIXTURE", new 
Properties()), Collections.emptyMap(), null);
         assertTrue(new AuthorityChecker(new AuthorityRule(ruleConfig), new 
Grantee("root", "localhost")).isAuthorized("db0"));
     }
-    
-    @Test
-    void assertCheckPrivileges() {
-        Collection<ShardingSphereUser> users = Collections.singleton(new 
ShardingSphereUser("root", "", "localhost"));
-        AuthorityRule rule = new AuthorityRule(new 
AuthorityRuleConfiguration(users, new AlgorithmConfiguration("FIXTURE", new 
Properties()), Collections.emptyMap(), null));
-        AuthorityChecker authorityChecker = new AuthorityChecker(rule, new 
Grantee("root", "localhost"));
-        authorityChecker.checkPrivileges(null, mock(SelectStatement.class));
-        authorityChecker.checkPrivileges(null, mock(InsertStatement.class));
-        authorityChecker.checkPrivileges(null, 
mock(CreateTableStatement.class));
-    }
 }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
index 1496e67df96..4c35fb515e5 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
@@ -32,6 +32,7 @@ import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
+import 
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException;
 import org.apache.shardingsphere.infra.executor.audit.SQLAuditEngine;
 import org.apache.shardingsphere.infra.hint.HintValueContext;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -167,7 +168,7 @@ public final class ProxyBackendHandlerFactory {
         }
         AuthorityRule authorityRule = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(AuthorityRule.class);
         ShardingSphereDatabase database = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName);
-        new AuthorityChecker(authorityRule, 
connectionSession.getGrantee()).checkPrivileges(databaseName, 
sqlStatementContext.getSqlStatement());
+        ShardingSpherePreconditions.checkState(new 
AuthorityChecker(authorityRule, 
connectionSession.getGrantee()).isAuthorized(databaseName), () -> new 
UnknownDatabaseException(databaseName));
         SQLAuditEngine.audit(sqlStatementContext, 
queryContext.getParameters(), 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(),
                 database, connectionSession.getGrantee(), 
queryContext.getHintValueContext());
         backendHandler = 
DatabaseAdminBackendHandlerFactory.newInstance(databaseType, 
sqlStatementContext, connectionSession);

Reply via email to