You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/08/18 03:32:19 UTC

[shardingsphere] branch master updated: empty authorizedSchemas means all databases permitted (#6900)

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

zhangyonglun 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 65602e4  empty authorizedSchemas means all databases permitted (#6900)
65602e4 is described below

commit 65602e44588c6fe690b72ea942e191929a1329e5
Author: sandynz <42...@users.noreply.github.com>
AuthorDate: Tue Aug 18 11:31:55 2020 +0800

    empty authorizedSchemas means all databases permitted (#6900)
---
 .../postgresql/auth/PostgreSQLAuthenticationHandler.java       | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
index f95e015..fc6c7ad 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
@@ -17,10 +17,13 @@
 
 package org.apache.shardingsphere.proxy.frontend.postgresql.auth;
 
+import com.google.common.base.Strings;
 import java.security.MessageDigest;
+import java.util.Collection;
 import java.util.Map;
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLErrorCode;
 import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
 import org.apache.shardingsphere.infra.auth.ProxyUser;
@@ -58,8 +61,8 @@ public class PostgreSQLAuthenticationHandler {
             return new PostgreSQLLoginResult(PostgreSQLErrorCode.INVALID_PASSWORD, "password authentication failed for user \"" + userName + "\"");
         }
         
-        if (!proxyUser.getAuthorizedSchemas().contains(databaseName)) {
-            return new PostgreSQLLoginResult(PostgreSQLErrorCode.PRIVILEGE_NOT_GRANTED, String.format("%s has no configured %s in authorizedSchemas", userName, databaseName));
+        if (!isAuthorizedSchema(proxyUser.getAuthorizedSchemas(), databaseName)) {
+            return new PostgreSQLLoginResult(PostgreSQLErrorCode.PRIVILEGE_NOT_GRANTED, String.format("Access denied for user '%s' to database '%s'", userName, databaseName));
         }
         
         return new PostgreSQLLoginResult(PostgreSQLErrorCode.SUCCESSFUL_COMPLETION, null);
@@ -73,4 +76,7 @@ public class PostgreSQLAuthenticationHandler {
         return "md5" + new String(Hex.encodeHex(messageDigest.digest(), true));
     }
     
+    private static boolean isAuthorizedSchema(final Collection<String> authorizedSchemas, final String schema) {
+        return Strings.isNullOrEmpty(schema) || CollectionUtils.isEmpty(authorizedSchemas) || authorizedSchemas.contains(schema);
+    }
 }