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 611be7b138b Use exception to instead of return logic in 
OpenGaussAuthenticationHandler and PostgreSQLAuthenticationHandler (#20654)
611be7b138b is described below

commit 611be7b138b8948089664eb0f87bacc0423a391f
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Aug 30 20:52:18 2022 +0800

    Use exception to instead of return logic in OpenGaussAuthenticationHandler 
and PostgreSQLAuthenticationHandler (#20654)
---
 .../exception/InvalidPasswordException.java        | 18 ++++++-------
 .../exception/PrivilegeNotGrantedException.java    | 18 ++++++-------
 .../exception/UnknownUsernameException.java        | 18 ++++++-------
 .../mapper/PostgreSQLDialectExceptionMapper.java   | 21 ++++++++++++---
 .../postgresql/vendor/PostgreSQLVendorError.java   |  2 +-
 .../resultset/ShardingSphereResultSetTest.java     |  2 +-
 .../OpenGaussAuthenticationEngine.java             | 14 +++-------
 .../OpenGaussAuthenticationHandler.java            | 21 ++++++++-------
 .../OpenGaussAuthenticationEngineTest.java         |  8 +++---
 .../OpenGaussAuthenticationHandlerTest.java        | 27 ++++++++-----------
 .../PostgreSQLAuthenticationEngine.java            | 13 +++------
 .../PostgreSQLAuthenticationHandler.java           | 20 +++++++-------
 .../PostgreSQLAuthenticationEngineTest.java        |  8 +++---
 .../PostgreSQLAuthenticationHandlerTest.java       | 31 +++++++---------------
 14 files changed, 102 insertions(+), 119 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidPasswordException.java
similarity index 64%
copy from 
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
copy to 
shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidPasswordException.java
index 07128a2f49f..60f177dc993 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidPasswordException.java
@@ -15,20 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.frontend.postgresql.authentication;
+package org.apache.shardingsphere.dialect.postgresql.exception;
 
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
 
 /**
- * PostgreSQL login result.
+ * Invalid password exception.
  */
-@RequiredArgsConstructor
-@Getter
-public final class PostgreSQLLoginResult {
+public final class InvalidPasswordException extends SQLDialectException {
     
-    private final PostgreSQLVendorError vendorError;
+    private static final long serialVersionUID = -2266893048070563644L;
     
-    private final String errorMessage;
+    public InvalidPasswordException(final String username) {
+        super("password authentication failed for user \"%s\"", username);
+    }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/PrivilegeNotGrantedException.java
similarity index 61%
copy from 
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
copy to 
shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/PrivilegeNotGrantedException.java
index 07128a2f49f..6db8c041ac8 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/PrivilegeNotGrantedException.java
@@ -15,20 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.frontend.postgresql.authentication;
+package org.apache.shardingsphere.dialect.postgresql.exception;
 
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
 
 /**
- * PostgreSQL login result.
+ * Privilege not granted exception.
  */
-@RequiredArgsConstructor
-@Getter
-public final class PostgreSQLLoginResult {
+public final class PrivilegeNotGrantedException extends SQLDialectException {
     
-    private final PostgreSQLVendorError vendorError;
+    private static final long serialVersionUID = 8410672833723209253L;
     
-    private final String errorMessage;
+    public PrivilegeNotGrantedException(final String username, final String 
databaseName) {
+        super("Access denied for user '%s' to database '%s'", username, 
databaseName);
+    }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/UnknownUsernameException.java
similarity index 65%
rename from 
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
rename to 
shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/UnknownUsernameException.java
index 07128a2f49f..53c35c0a3c5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLLoginResult.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/UnknownUsernameException.java
@@ -15,20 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.frontend.postgresql.authentication;
+package org.apache.shardingsphere.dialect.postgresql.exception;
 
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
 
 /**
- * PostgreSQL login result.
+ * Unknown username exception.
  */
-@RequiredArgsConstructor
-@Getter
-public final class PostgreSQLLoginResult {
+public final class UnknownUsernameException extends SQLDialectException {
     
-    private final PostgreSQLVendorError vendorError;
+    private static final long serialVersionUID = -2895258747747089622L;
     
-    private final String errorMessage;
+    public UnknownUsernameException(final String username) {
+        super("unknown username: %s", username);
+    }
 }
diff --git 
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
index bc842cbefc1..d93431a73d0 100644
--- 
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
@@ -22,11 +22,14 @@ import 
org.apache.shardingsphere.dialect.exception.connection.TooManyConnections
 import 
org.apache.shardingsphere.dialect.exception.data.InsertColumnsAndValuesMismatchedException;
 import 
org.apache.shardingsphere.dialect.exception.data.InvalidParameterValueException;
 import 
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException;
+import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
 import 
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
 import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
 import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLAuthenticationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
 import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PrivilegeNotGrantedException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.UnknownUsernameException;
 import 
org.apache.shardingsphere.dialect.postgresql.message.ServerErrorMessageBuilder;
 import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import org.postgresql.util.PSQLException;
@@ -41,6 +44,19 @@ public final class PostgreSQLDialectExceptionMapper 
implements SQLDialectExcepti
     
     @Override
     public SQLException convert(final SQLDialectException sqlDialectException) 
{
+        if (sqlDialectException instanceof UnknownDatabaseException) {
+            return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.INVALID_CATALOG_NAME,
+                    
String.format(PostgreSQLVendorError.INVALID_CATALOG_NAME.getReason(), 
((UnknownDatabaseException) sqlDialectException).getDatabaseName())));
+        }
+        if (sqlDialectException instanceof UnknownUsernameException) {
+            return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION, 
sqlDialectException.getMessage()));
+        }
+        if (sqlDialectException instanceof InvalidPasswordException) {
+            return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.INVALID_PASSWORD, sqlDialectException.getMessage()));
+        }
+        if (sqlDialectException instanceof PrivilegeNotGrantedException) {
+            return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.PRIVILEGE_NOT_GRANTED, sqlDialectException.getMessage()));
+        }
         if (sqlDialectException instanceof DatabaseCreateExistsException) {
             return new 
PSQLException(PostgreSQLVendorError.DUPLICATE_DATABASE.getReason(), null);
         }
@@ -64,9 +80,6 @@ public final class PostgreSQLDialectExceptionMapper 
implements SQLDialectExcepti
         if (sqlDialectException instanceof 
PostgreSQLProtocolViolationException) {
             return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.PROTOCOL_VIOLATION, sqlDialectException.getMessage()));
         }
-        if (sqlDialectException instanceof PostgreSQLAuthenticationException) {
-            return new PSQLException(ServerErrorMessageBuilder.build("FATAL", 
PostgreSQLVendorError.PROTOCOL_VIOLATION, sqlDialectException.getMessage()));
-        }
         return new PSQLException(sqlDialectException.getMessage(), 
PSQLState.UNEXPECTED_ERROR);
     }
     
diff --git 
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLVendorError.java
 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLVendorError.java
index f3d1b932433..6d360c711fc 100644
--- 
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLVendorError.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLVendorError.java
@@ -47,7 +47,7 @@ public enum PostgreSQLVendorError implements VendorError {
     
     INVALID_PASSWORD(PostgreSQLState.INVALID_PASSWORD, "invalid_password"),
     
-    INVALID_CATALOG_NAME(XOpenSQLState.INVALID_CATALOG_NAME, 
"invalid_catalog_name"),
+    INVALID_CATALOG_NAME(XOpenSQLState.INVALID_CATALOG_NAME, "database \"%s\" 
does not exist"),
     
     UNDEFINED_COLUMN(PostgreSQLState.UNDEFINED_COLUMN, "undefined_column"),
     
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
index 99203db3b01..34405e21c26 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
@@ -594,7 +594,7 @@ public final class ShardingSphereResultSetTest {
         when(mergeResultSet.getValue(1, 
Timestamp.class)).thenReturn(Timestamp.valueOf(result));
         assertThat(shardingSphereResultSet.getObject(1, LocalDateTime.class), 
is(result));
     }
-
+    
     @Test
     public void assertGetObjectWithOffsetDateTime() throws SQLException {
         OffsetDateTime result = OffsetDateTime.now();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
index bc88f83df07..c25a5422424 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
@@ -22,8 +22,6 @@ import io.netty.channel.ChannelHandlerContext;
 import org.apache.shardingsphere.db.protocol.CommonConstants;
 import 
org.apache.shardingsphere.db.protocol.opengauss.packet.authentication.OpenGaussAuthenticationSCRAMSha256Packet;
 import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
-import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLCharacterSets;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLAuthenticationOKPacket;
@@ -33,14 +31,13 @@ import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.Postgre
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLSSLNegativePacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLMessagePacketType;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
+import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLCharacterSets;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationEngine;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;
 import 
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator;
-import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.PostgreSQLLoginResult;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLAuthenticationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 
 import java.util.concurrent.ThreadLocalRandom;
 
@@ -115,11 +112,8 @@ public final class OpenGaussAuthenticationEngine 
implements AuthenticationEngine
             throw new PostgreSQLProtocolViolationException("password", 
Character.toString(messageType));
         }
         PostgreSQLPasswordMessagePacket passwordMessagePacket = new 
PostgreSQLPasswordMessagePacket(payload);
-        PostgreSQLLoginResult loginResult = 
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(currentAuthResult.getUsername(),
 currentAuthResult.getDatabase(),
+        
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(currentAuthResult.getUsername(),
 currentAuthResult.getDatabase(),
                 saltHexString, nonceHexString, serverIteration, 
passwordMessagePacket);
-        if (PostgreSQLVendorError.SUCCESSFUL_COMPLETION != 
loginResult.getVendorError()) {
-            throw new 
PostgreSQLAuthenticationException(loginResult.getVendorError(), 
loginResult.getErrorMessage());
-        }
         context.write(new PostgreSQLAuthenticationOKPacket());
         context.write(new PostgreSQLParameterStatusPacket("server_version", 
PostgreSQLServerInfo.getServerVersion()));
         context.write(new PostgreSQLParameterStatusPacket("client_encoding", 
clientEncoding));
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
index 6e6782d671b..1429439901f 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
@@ -21,14 +21,16 @@ import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
+import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PrivilegeNotGrantedException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.UnknownUsernameException;
 import org.apache.shardingsphere.infra.executor.check.SQLCheckEngine;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.PostgreSQLLoginResult;
 
 import javax.crypto.Mac;
 import javax.crypto.SecretKeyFactory;
@@ -68,24 +70,23 @@ public final class OpenGaussAuthenticationHandler {
      * @param nonce nonce in hex string
      * @param serverIteration server iteration
      * @param passwordMessagePacket password message packet
-     * @return openGauss(PostgreSQL) login result
      */
-    public static PostgreSQLLoginResult loginWithSCRAMSha256Password(final 
String username, final String databaseName, final String salt, final String 
nonce, final int serverIteration,
+    public static void loginWithSCRAMSha256Password(final String username, 
final String databaseName, final String salt, final String nonce, final int 
serverIteration,
                                                                      final 
PostgreSQLPasswordMessagePacket passwordMessagePacket) {
         String clientDigest = passwordMessagePacket.getDigest();
         Grantee grantee = new Grantee(username, "%");
         if (!Strings.isNullOrEmpty(databaseName) && 
!ProxyContext.getInstance().databaseExists(databaseName)) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_CATALOG_NAME, 
String.format("database \"%s\" does not exist", databaseName));
+            throw new UnknownDatabaseException(databaseName);
         }
         if (!SQLCheckEngine.check(grantee, getRules(databaseName))) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION,
 String.format("unknown username: %s", username));
+            throw new UnknownUsernameException(username);
         }
         if (!SQLCheckEngine.check(grantee, (a, b) -> 
isPasswordRight((ShardingSphereUser) a, (Object[]) b), new 
Object[]{clientDigest, salt, nonce, serverIteration}, getRules(databaseName))) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_PASSWORD, 
String.format("password authentication failed for user \"%s\"", username));
+            throw new InvalidPasswordException(username);
+        }
+        if (null != databaseName && !SQLCheckEngine.check(databaseName, 
getRules(databaseName), grantee)) {
+            throw new PrivilegeNotGrantedException(username, databaseName);
         }
-        return null == databaseName || SQLCheckEngine.check(databaseName, 
getRules(databaseName), grantee)
-                ? new 
PostgreSQLLoginResult(PostgreSQLVendorError.SUCCESSFUL_COMPLETION, null)
-                : new 
PostgreSQLLoginResult(PostgreSQLVendorError.PRIVILEGE_NOT_GRANTED, 
String.format("Access denied for user '%s' to database '%s'", username, 
databaseName));
     }
     
     private static Collection<ShardingSphereRule> getRules(final String 
databaseName) {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
index 1d9f042f427..8884db05d2e 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
@@ -30,6 +30,9 @@ import org.apache.shardingsphere.db.protocol.CommonConstants;
 import 
org.apache.shardingsphere.db.protocol.opengauss.packet.authentication.OpenGaussAuthenticationSCRAMSha256Packet;
 import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -43,9 +46,6 @@ import 
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
 import org.apache.shardingsphere.proxy.frontend.opengauss.ProxyContextRestorer;
 import 
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.fixture.OpenGaussAuthenticationAlgorithm;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLAuthenticationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -127,7 +127,7 @@ public final class OpenGaussAuthenticationEngineTest 
extends ProxyContextRestore
         assertLogin(password);
     }
     
-    @Test(expected = PostgreSQLAuthenticationException.class)
+    @Test(expected = InvalidPasswordException.class)
     public void assertLoginFailed() {
         assertLogin("wrong" + password);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
index b1243c5b41b..4e833ae2e3e 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
@@ -24,9 +24,11 @@ import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.authority.rule.builder.AuthorityRuleBuilder;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.UnknownUsernameException;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.DefaultDatabase;
@@ -43,7 +45,6 @@ import 
org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.frontend.opengauss.ProxyContextRestorer;
 import 
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.fixture.OpenGaussAuthenticationAlgorithm;
-import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.PostgreSQLLoginResult;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -53,8 +54,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -87,32 +86,28 @@ public final class OpenGaussAuthenticationHandlerTest 
extends ProxyContextRestor
     }
     
     @Test
-    public void assertLoginWithPassword() {
+    public void assertLoginSuccess() {
         initProxyContext(new ShardingSphereUser(username, password, "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = 
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, database, 
random64Code, token, serverIteration, passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.SUCCESSFUL_COMPLETION));
+        OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, 
database, random64Code, token, serverIteration, passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = UnknownUsernameException.class)
     public void assertLoginWithAbsentUser() {
         initProxyContext(new ShardingSphereUser("username", password, "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = 
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, database, 
random64Code, token, serverIteration, passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION));
+        OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, 
database, random64Code, token, serverIteration, passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = InvalidPasswordException.class)
     public void assertLoginWithIncorrectPassword() {
         initProxyContext(new ShardingSphereUser(username, "password", "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = 
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, database, 
random64Code, token, serverIteration, passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_PASSWORD));
+        OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, 
database, random64Code, token, serverIteration, passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = UnknownDatabaseException.class)
     public void assertLoginWithNonExistDatabase() {
         initProxyContext(new ShardingSphereUser(username, password, "%"));
         String database = "non_exist_database";
-        PostgreSQLLoginResult postgreSQLLoginResult = 
OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, database, 
random64Code, token, serverIteration, passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_CATALOG_NAME));
+        OpenGaussAuthenticationHandler.loginWithSCRAMSha256Password(username, 
database, random64Code, token, serverIteration, passwordMessagePacket);
     }
     
     private void initProxyContext(final ShardingSphereUser user) {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
index 40bab2c5893..3130b738858 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
@@ -22,8 +22,6 @@ import io.netty.channel.ChannelHandlerContext;
 import org.apache.shardingsphere.db.protocol.CommonConstants;
 import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
 import 
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLAuthenticationMethod;
-import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLCharacterSets;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLAuthenticationOKPacket;
@@ -37,14 +35,14 @@ import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.authent
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierPacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLMessagePacketType;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
+import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLCharacterSets;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationEngine;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;
 import 
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator;
 import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLAuthenticator;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLAuthenticationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 
 /**
  * Authentication engine for PostgreSQL.
@@ -100,10 +98,7 @@ public final class PostgreSQLAuthenticationEngine 
implements AuthenticationEngin
             throw new PostgreSQLProtocolViolationException("password", 
Character.toString(messageType));
         }
         PostgreSQLPasswordMessagePacket passwordMessagePacket = new 
PostgreSQLPasswordMessagePacket(payload);
-        PostgreSQLLoginResult loginResult = 
authenticationHandler.login(currentAuthResult.getUsername(), 
currentAuthResult.getDatabase(), md5Salt, passwordMessagePacket);
-        if (PostgreSQLVendorError.SUCCESSFUL_COMPLETION != 
loginResult.getVendorError()) {
-            throw new 
PostgreSQLAuthenticationException(loginResult.getVendorError(), 
loginResult.getErrorMessage());
-        }
+        authenticationHandler.login(currentAuthResult.getUsername(), 
currentAuthResult.getDatabase(), md5Salt, passwordMessagePacket);
         // TODO implement PostgreSQLServerInfo like MySQLServerInfo
         context.write(new PostgreSQLAuthenticationOKPacket());
         context.write(new PostgreSQLParameterStatusPacket("server_version", 
PostgreSQLServerInfo.getServerVersion()));
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
index baeb4f1934a..042d8b68303 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
@@ -18,8 +18,11 @@
 package org.apache.shardingsphere.proxy.frontend.postgresql.authentication;
 
 import com.google.common.base.Strings;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
+import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PrivilegeNotGrantedException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.UnknownUsernameException;
 import org.apache.shardingsphere.infra.executor.check.SQLCheckEngine;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -43,24 +46,23 @@ public final class PostgreSQLAuthenticationHandler {
      * @param databaseName database name
      * @param md5Salt MD5 salt
      * @param passwordMessagePacket password message packet
-     * @return PostgreSQL login result
      */
-    public PostgreSQLLoginResult login(final String username, final String 
databaseName, final byte[] md5Salt, final PostgreSQLPasswordMessagePacket 
passwordMessagePacket) {
+    public void login(final String username, final String databaseName, final 
byte[] md5Salt, final PostgreSQLPasswordMessagePacket passwordMessagePacket) {
         String digest = passwordMessagePacket.getDigest();
         Grantee grantee = new Grantee(username, "%");
         if (!Strings.isNullOrEmpty(databaseName) && 
!ProxyContext.getInstance().databaseExists(databaseName)) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_CATALOG_NAME, 
String.format("database \"%s\" does not exist", databaseName));
+            throw new UnknownDatabaseException(databaseName);
         }
         if (!SQLCheckEngine.check(grantee, getRules(databaseName))) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION,
 String.format("unknown username: %s", username));
+            throw new UnknownUsernameException(username);
         }
         PostgreSQLAuthenticator authenticator = getAuthenticator(username, 
grantee.getHostname());
         if (!SQLCheckEngine.check(grantee, (a, b) -> 
authenticator.authenticate((ShardingSphereUser) a, (Object[]) b), new 
Object[]{digest, md5Salt}, getRules(databaseName))) {
-            return new 
PostgreSQLLoginResult(PostgreSQLVendorError.INVALID_PASSWORD, 
String.format("password authentication failed for user \"%s\"", username));
+            throw new InvalidPasswordException(username);
+        }
+        if (null != databaseName && !SQLCheckEngine.check(databaseName, 
getRules(databaseName), grantee)) {
+            throw new PrivilegeNotGrantedException(username, databaseName);
         }
-        return null == databaseName || SQLCheckEngine.check(databaseName, 
getRules(databaseName), grantee)
-                ? new 
PostgreSQLLoginResult(PostgreSQLVendorError.SUCCESSFUL_COMPLETION, null)
-                : new 
PostgreSQLLoginResult(PostgreSQLVendorError.PRIVILEGE_NOT_GRANTED, 
String.format("Access denied for user '%s' to database '%s'", username, 
databaseName));
     }
     
     private Collection<ShardingSphereRule> getRules(final String databaseName) 
{
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
index 4fc7349414d..23c14117b00 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
@@ -31,6 +31,9 @@ import 
org.apache.shardingsphere.db.protocol.payload.PacketPayload;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.authentication.PostgreSQLMD5PasswordAuthenticationPacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierPacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -44,9 +47,6 @@ import 
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
 import 
org.apache.shardingsphere.proxy.frontend.postgresql.ProxyContextRestorer;
 import 
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLMD5PasswordAuthenticator;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLAuthenticationException;
-import 
org.apache.shardingsphere.dialect.postgresql.exception.PostgreSQLProtocolViolationException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -130,7 +130,7 @@ public final class PostgreSQLAuthenticationEngineTest 
extends ProxyContextRestor
         assertLogin(password);
     }
     
-    @Test(expected = PostgreSQLAuthenticationException.class)
+    @Test(expected = InvalidPasswordException.class)
     public void assertLoginFailed() {
         assertLogin("wrong" + password);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
index 86ef9630b04..16c949f113a 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
@@ -25,9 +25,10 @@ import 
org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
 import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.authority.rule.builder.AuthorityRuleBuilder;
 import 
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLAuthenticationMethod;
-import 
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
 import 
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket;
 import 
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.InvalidPasswordException;
+import 
org.apache.shardingsphere.dialect.postgresql.exception.UnknownUsernameException;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.DefaultDatabase;
@@ -86,39 +87,27 @@ public final class PostgreSQLAuthenticationHandlerTest 
extends ProxyContextResto
     }
     
     @Test
-    public void assertLoginWithPassword() {
+    public void assertLoginSuccess() {
         initProxyContext(new ShardingSphereUser(username, password, "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = new 
PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.SUCCESSFUL_COMPLETION));
+        new PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = UnknownUsernameException.class)
     public void assertLoginWithAbsentUser() {
         initProxyContext(new ShardingSphereUser("username", password, "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = new 
PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION));
+        new PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = InvalidPasswordException.class)
     public void assertLoginWithIncorrectPassword() {
         initProxyContext(new ShardingSphereUser(username, "password", "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = new 
PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_PASSWORD));
+        new PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
     }
     
-    @Test
+    @Test(expected = InvalidPasswordException.class)
     public void assertLoginWithoutPassword() {
         initProxyContext(new ShardingSphereUser(username, null, "%"));
-        PostgreSQLLoginResult postgreSQLLoginResult = new 
PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_PASSWORD));
-    }
-    
-    @Test
-    public void assertLoginWithNonExistDatabase() {
-        initProxyContext(new ShardingSphereUser(username, password, "%"));
-        String database = "non_exist_database";
-        PostgreSQLLoginResult postgreSQLLoginResult = new 
PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
-        assertThat(postgreSQLLoginResult.getVendorError(), 
is(PostgreSQLVendorError.INVALID_CATALOG_NAME));
+        new PostgreSQLAuthenticationHandler().login(username, database, 
md5Salt.getBytes(StandardCharsets.UTF_8), passwordMessagePacket);
     }
     
     @Test

Reply via email to