This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 819a3466ae8 authority type DATABASE_PERMITTED not apply correctly for
some account when there are multi accounts #21615 (#21722)
819a3466ae8 is described below
commit 819a3466ae8f23e9d589fe7989a42cddf7c1de84
Author: wallacezhou <[email protected]>
AuthorDate: Mon Oct 31 06:46:57 2022 +0800
authority type DATABASE_PERMITTED not apply correctly for some account when
there are multi accounts #21615 (#21722)
* authority type DATABASE_PERMITTED not apply correctly for some account
when there are multi accounts (#21615)
* authority type DATABASE_PERMITTED not apply correctly for some account
when there are multi accounts (#21615)
* authority type DATABASE_PERMITTED not apply correctly for some account
when there are multi accounts (#21615)
Co-authored-by: wallacezhou <[email protected]>
---
.../handler/data/impl/UnicastDatabaseBackendHandler.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
index 5f471a38d7d..170d9acc1f7 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
@@ -18,7 +18,10 @@
package org.apache.shardingsphere.proxy.backend.handler.data.impl;
import io.vertx.core.Future;
+import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.binder.QueryContext;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
@@ -84,7 +87,12 @@ public final class UnicastDatabaseBackendHandler implements
DatabaseBackendHandl
if (databaseNames.isEmpty()) {
throw new NoDatabaseSelectedException();
}
- Optional<String> result = databaseNames.stream().filter(each ->
ProxyContext.getInstance().getDatabase(each).containsDataSource()).findFirst();
+ AuthorityRule authorityRule =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(
+ AuthorityRule.class);
+ Optional<ShardingSpherePrivileges> privileges =
authorityRule.findPrivileges(connectionSession.getGrantee());
+ Stream<String> databaseStream = databaseNames.stream().filter(each ->
ProxyContext.getInstance().getDatabase(each).containsDataSource());
+ Optional<String> result = privileges.isPresent() ?
databaseStream.filter(each -> privileges.get().hasPrivileges(each)).findFirst()
+ : databaseStream.findFirst();
if (!result.isPresent()) {
throw new RuleNotExistedException();
}