This is an automated email from the ASF dual-hosted git repository.
yx9o 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 29be45c1d60 Rename MySQLErrorCode (#20137)
29be45c1d60 is described below
commit 29be45c1d60356ba7759104d265d31a1e4a7b359
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 13 12:14:33 2022 +0800
Rename MySQLErrorCode (#20137)
---
.../mysql/packet/generic/MySQLErrPacketTest.java | 24 +++++++++++-----------
...SQLServerErrorCode.java => MySQLErrorCode.java} | 2 +-
.../error/mysql/mapper/MySQLExceptionMapper.java | 22 ++++++++++----------
...rErrorCodeTest.java => MySQLErrorCodeTest.java} | 20 +++++++++---------
.../client/netty/MySQLNegotiateHandlerTest.java | 4 ++--
.../authentication/MySQLAuthenticationEngine.java | 14 ++++++-------
.../authentication/MySQLAuthenticationHandler.java | 8 ++++----
.../frontend/mysql/err/MySQLErrPacketFactory.java | 8 ++++----
.../MySQLAuthenticationEngineTest.java | 6 ++++--
.../MySQLAuthenticationHandlerTest.java | 8 ++++----
10 files changed, 59 insertions(+), 57 deletions(-)
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
index 3fd720a92a5..1474eda78c9 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.db.protocol.mysql.packet.generic;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,30 +37,30 @@ public final class MySQLErrPacketTest {
@Test
public void assertNewErrPacketWithServerErrorCode() {
- MySQLErrPacket actual = new MySQLErrPacket(1,
MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR, "root", "localhost", "root");
+ MySQLErrPacket actual = new MySQLErrPacket(1,
MySQLErrorCode.ER_ACCESS_DENIED_ERROR, "root", "localhost", "root");
assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(),
is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode()));
- assertThat(actual.getSqlState(),
is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
- assertThat(actual.getErrorMessage(),
is(String.format(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root")));
+ assertThat(actual.getErrorCode(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode()));
+ assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
+ assertThat(actual.getErrorMessage(),
is(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root")));
}
@Test
public void assertNewErrPacketWithPayload() {
when(payload.readInt1()).thenReturn(1, MySQLErrPacket.HEADER);
-
when(payload.readInt2()).thenReturn(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode());
+
when(payload.readInt2()).thenReturn(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode());
when(payload.readStringFix(1)).thenReturn("#");
-
when(payload.readStringFix(5)).thenReturn(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState());
-
when(payload.readStringEOF()).thenReturn(String.format(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root"));
+
when(payload.readStringFix(5)).thenReturn(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState());
+
when(payload.readStringEOF()).thenReturn(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root"));
MySQLErrPacket actual = new MySQLErrPacket(payload);
assertThat(actual.getSequenceId(), is(1));
- assertThat(actual.getErrorCode(),
is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode()));
- assertThat(actual.getSqlState(),
is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
- assertThat(actual.getErrorMessage(),
is(String.format(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root")));
+ assertThat(actual.getErrorCode(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode()));
+ assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
+ assertThat(actual.getErrorMessage(),
is(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
"root", "localhost", "root")));
}
@Test
public void assertWrite() {
- new MySQLErrPacket(1,
MySQLServerErrorCode.ER_NO_DB_ERROR).write(payload);
+ new MySQLErrPacket(1, MySQLErrorCode.ER_NO_DB_ERROR).write(payload);
verify(payload).writeInt1(MySQLErrPacket.HEADER);
verify(payload).writeInt2(1046);
verify(payload).writeStringFix("#");
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCode.java
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
similarity index 98%
rename from
shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCode.java
rename to
shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
index 7adde3c8a40..8e59dbf38f4 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCode.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.error.code.SQLErrorCode;
*/
@RequiredArgsConstructor
@Getter
-public enum MySQLServerErrorCode implements SQLErrorCode {
+public enum MySQLErrorCode implements SQLErrorCode {
ER_DBACCESS_DENIED_ERROR(1044, "42000", "Access denied for user '%s'@'%s'
to database '%s'"),
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
index 72c366ae4f4..aa10b528ec9 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.error.mysql.mapper;
import org.apache.shardingsphere.error.code.SQLErrorCode;
import org.apache.shardingsphere.error.code.StandardSQLErrorCode;
import org.apache.shardingsphere.error.mapper.DialectSQLExceptionMapper;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.infra.exception.dialect.DBCreateExistsException;
import
org.apache.shardingsphere.infra.exception.dialect.DBDropNotExistsException;
import
org.apache.shardingsphere.infra.exception.dialect.InsertColumnsAndValuesMismatchedException;
@@ -42,33 +42,33 @@ public final class MySQLExceptionMapper implements
DialectSQLExceptionMapper {
@Override
public SQLException convert(final InsideDialectSQLException
dialectSQLException) {
if (dialectSQLException instanceof TableModifyInTransactionException) {
- return
toSQLException(MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE,
((TableModifyInTransactionException) dialectSQLException).getTableName());
+ return
toSQLException(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE,
((TableModifyInTransactionException) dialectSQLException).getTableName());
}
if (dialectSQLException instanceof
InsertColumnsAndValuesMismatchedException) {
- return
toSQLException(MySQLServerErrorCode.ER_WRONG_VALUE_COUNT_ON_ROW,
((InsertColumnsAndValuesMismatchedException)
dialectSQLException).getMismatchedRowNumber());
+ return toSQLException(MySQLErrorCode.ER_WRONG_VALUE_COUNT_ON_ROW,
((InsertColumnsAndValuesMismatchedException)
dialectSQLException).getMismatchedRowNumber());
}
if (dialectSQLException instanceof UnknownDatabaseException) {
return null != ((UnknownDatabaseException)
dialectSQLException).getDatabaseName()
- ? toSQLException(MySQLServerErrorCode.ER_BAD_DB_ERROR,
((UnknownDatabaseException) dialectSQLException).getDatabaseName())
- : toSQLException(MySQLServerErrorCode.ER_NO_DB_ERROR);
+ ? toSQLException(MySQLErrorCode.ER_BAD_DB_ERROR,
((UnknownDatabaseException) dialectSQLException).getDatabaseName())
+ : toSQLException(MySQLErrorCode.ER_NO_DB_ERROR);
}
if (dialectSQLException instanceof NoDatabaseSelectedException) {
- return toSQLException(MySQLServerErrorCode.ER_NO_DB_ERROR);
+ return toSQLException(MySQLErrorCode.ER_NO_DB_ERROR);
}
if (dialectSQLException instanceof DBCreateExistsException) {
- return
toSQLException(MySQLServerErrorCode.ER_DB_CREATE_EXISTS_ERROR,
((DBCreateExistsException) dialectSQLException).getDatabaseName());
+ return toSQLException(MySQLErrorCode.ER_DB_CREATE_EXISTS_ERROR,
((DBCreateExistsException) dialectSQLException).getDatabaseName());
}
if (dialectSQLException instanceof DBDropNotExistsException) {
- return
toSQLException(MySQLServerErrorCode.ER_DB_DROP_NOT_EXISTS_ERROR,
((DBDropNotExistsException) dialectSQLException).getDatabaseName());
+ return toSQLException(MySQLErrorCode.ER_DB_DROP_NOT_EXISTS_ERROR,
((DBDropNotExistsException) dialectSQLException).getDatabaseName());
}
if (dialectSQLException instanceof TableExistsException) {
- return toSQLException(MySQLServerErrorCode.ER_TABLE_EXISTS_ERROR,
((TableExistsException) dialectSQLException).getTableName());
+ return toSQLException(MySQLErrorCode.ER_TABLE_EXISTS_ERROR,
((TableExistsException) dialectSQLException).getTableName());
}
if (dialectSQLException instanceof NoSuchTableException) {
- return toSQLException(MySQLServerErrorCode.ER_NO_SUCH_TABLE,
((NoSuchTableException) dialectSQLException).getTableName());
+ return toSQLException(MySQLErrorCode.ER_NO_SUCH_TABLE,
((NoSuchTableException) dialectSQLException).getTableName());
}
if (dialectSQLException instanceof TooManyConnectionsException) {
- return toSQLException(MySQLServerErrorCode.ER_CON_COUNT_ERROR);
+ return toSQLException(MySQLErrorCode.ER_CON_COUNT_ERROR);
}
return toSQLException(StandardSQLErrorCode.UNKNOWN_EXCEPTION,
dialectSQLException.getMessage());
}
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCodeTest.java
b/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
similarity index 57%
rename from
shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCodeTest.java
rename to
shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
index 8eac61062e1..64a52671c1f 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLServerErrorCodeTest.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
@@ -22,27 +22,27 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public final class MySQLServerErrorCodeTest {
+public final class MySQLErrorCodeTest {
@Test
public void assertAccessDeniedError() {
- assertThat(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode(),
is(1045));
- assertThat(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState(),
is("28000"));
-
assertThat(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
is("Access denied for user '%s'@'%s' (using password: %s)"));
+ assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorCode(),
is(1045));
+ assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState(),
is("28000"));
+ assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getErrorMessage(),
is("Access denied for user '%s'@'%s' (using password: %s)"));
}
@Test
public void assertBadDbError() {
- assertThat(MySQLServerErrorCode.ER_BAD_DB_ERROR.getErrorCode(),
is(1049));
- assertThat(MySQLServerErrorCode.ER_BAD_DB_ERROR.getSqlState(),
is("42000"));
- assertThat(MySQLServerErrorCode.ER_BAD_DB_ERROR.getErrorMessage(),
is("Unknown database '%s'"));
+ assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getErrorCode(), is(1049));
+ assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getSqlState(), is("42000"));
+ assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getErrorMessage(),
is("Unknown database '%s'"));
}
@Test
public void assertErrorOnModifyingGtidExecutedTable() {
-
assertThat(MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getErrorCode(),
is(3176));
-
assertThat(MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getSqlState(),
is("HY000"));
-
assertThat(MySQLServerErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getErrorMessage(),
is("Please do not modify the %s table with an XA transaction. "
+
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getErrorCode(),
is(3176));
+
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getSqlState(),
is("HY000"));
+
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getErrorMessage(),
is("Please do not modify the %s table with an XA transaction. "
+ "This is an internal system table used to store GTIDs for
committed transactions. "
+ "Although modifying it can lead to an inconsistent GTID
state, if necessary you can modify it with a non-XA transaction."));
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
index 8cd21f0a8dc..d2d390226e6 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
@@ -24,7 +24,7 @@ import io.netty.util.concurrent.Promise;
import org.apache.shardingsphere.data.pipeline.core.util.ReflectionUtil;
import org.apache.shardingsphere.data.pipeline.mysql.ingest.client.ServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLAuthenticationMethod;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
@@ -96,7 +96,7 @@ public final class MySQLNegotiateHandlerTest {
@Test(expected = RuntimeException.class)
public void assertChannelReadErrorPacket() {
- MySQLErrPacket errorPacket = new MySQLErrPacket(0,
MySQLServerErrorCode.ER_NO_DB_ERROR);
+ MySQLErrPacket errorPacket = new MySQLErrPacket(0,
MySQLErrorCode.ER_NO_DB_ERROR);
mysqlNegotiateHandler.channelRead(channelHandlerContext, errorPacket);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
index 551b0e7663e..43a3e31dd8f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
@@ -24,7 +24,7 @@ import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCharacterSet;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConnectionPhase;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLStatusFlag;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.MySQLStatementIDGenerator;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
@@ -82,7 +82,7 @@ public final class MySQLAuthenticationEngine implements
AuthenticationEngine {
} else if (MySQLConnectionPhase.AUTHENTICATION_METHOD_MISMATCH ==
connectionPhase) {
authenticationMethodMismatch((MySQLPacketPayload) payload);
}
- Optional<MySQLServerErrorCode> errorCode =
authenticationHandler.login(currentAuthResult.getUsername(),
getHostAddress(context), authResponse, currentAuthResult.getDatabase());
+ Optional<MySQLErrorCode> errorCode =
authenticationHandler.login(currentAuthResult.getUsername(),
getHostAddress(context), authResponse, currentAuthResult.getDatabase());
context.writeAndFlush(errorCode.isPresent() ?
createErrorPacket(errorCode.get(), context) : new MySQLOKPacket(++sequenceId,
DEFAULT_STATUS_FLAG));
return
AuthenticationResultBuilder.finished(currentAuthResult.getUsername(),
getHostAddress(context), currentAuthResult.getDatabase());
}
@@ -95,7 +95,7 @@ public final class MySQLAuthenticationEngine implements
AuthenticationEngine {
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(mySQLCharacterSet.getCharset());
context.channel().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).set(mySQLCharacterSet);
if (!Strings.isNullOrEmpty(packet.getDatabase()) &&
!ProxyContext.getInstance().databaseExists(packet.getDatabase())) {
- context.writeAndFlush(new MySQLErrPacket(++sequenceId,
MySQLServerErrorCode.ER_BAD_DB_ERROR, packet.getDatabase()));
+ context.writeAndFlush(new MySQLErrPacket(++sequenceId,
MySQLErrorCode.ER_BAD_DB_ERROR, packet.getDatabase()));
return AuthenticationResultBuilder.continued();
}
MySQLAuthenticator authenticator =
authenticationHandler.getAuthenticator(packet.getUsername(),
getHostAddress(context));
@@ -117,10 +117,10 @@ public final class MySQLAuthenticationEngine implements
AuthenticationEngine {
authResponse = packet.getAuthPluginResponse();
}
- private MySQLErrPacket createErrorPacket(final MySQLServerErrorCode
errorCode, final ChannelHandlerContext context) {
- return MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR == errorCode
- ? new MySQLErrPacket(++sequenceId,
MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR, currentAuthResult.getUsername(),
getHostAddress(context), currentAuthResult.getDatabase())
- : new MySQLErrPacket(++sequenceId,
MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR, currentAuthResult.getUsername(),
getHostAddress(context), getErrorMessage());
+ private MySQLErrPacket createErrorPacket(final MySQLErrorCode errorCode,
final ChannelHandlerContext context) {
+ return MySQLErrorCode.ER_DBACCESS_DENIED_ERROR == errorCode
+ ? new MySQLErrPacket(++sequenceId,
MySQLErrorCode.ER_DBACCESS_DENIED_ERROR, currentAuthResult.getUsername(),
getHostAddress(context), currentAuthResult.getDatabase())
+ : new MySQLErrPacket(++sequenceId,
MySQLErrorCode.ER_ACCESS_DENIED_ERROR, currentAuthResult.getUsername(),
getHostAddress(context), getErrorMessage());
}
private String getErrorMessage() {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
index 9529217cd00..31c1ccacdeb 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandler.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.mysql.authentication;
import lombok.Getter;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
import org.apache.shardingsphere.infra.executor.check.SQLCheckEngine;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -48,14 +48,14 @@ public final class MySQLAuthenticationHandler {
* @param databaseName database name
* @return login success or failure
*/
- public Optional<MySQLServerErrorCode> login(final String username, final
String hostname, final byte[] authenticationResponse, final String
databaseName) {
+ public Optional<MySQLErrorCode> login(final String username, final String
hostname, final byte[] authenticationResponse, final String databaseName) {
Grantee grantee = new Grantee(username, hostname);
Collection<ShardingSphereRule> rules =
ProxyContext.getInstance().getRules(databaseName);
MySQLAuthenticator authenticator = getAuthenticator(username,
hostname);
if (!SQLCheckEngine.check(grantee, (a, b) ->
authenticator.authenticate((ShardingSphereUser) a, (byte[]) b),
authenticationResponse, rules)) {
- return Optional.of(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR);
+ return Optional.of(MySQLErrorCode.ER_ACCESS_DENIED_ERROR);
}
- return null == databaseName || SQLCheckEngine.check(databaseName,
rules, grantee) ? Optional.empty() :
Optional.of(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR);
+ return null == databaseName || SQLCheckEngine.check(databaseName,
rules, grantee) ? Optional.empty() :
Optional.of(MySQLErrorCode.ER_DBACCESS_DENIED_ERROR);
}
/**
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index aaaedf9a2d4..aaafeb315cc 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -24,7 +24,7 @@ import
org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobNotFoun
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
import org.apache.shardingsphere.error.SQLExceptionHandler;
import org.apache.shardingsphere.error.code.StandardSQLErrorCode;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.infra.util.exception.inside.ShardingSphereInsideException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLErrorCode;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLException;
@@ -48,7 +48,7 @@ public final class MySQLErrPacketFactory {
public static MySQLErrPacket newInstance(final Exception cause) {
if (cause instanceof SQLException) {
SQLException sqlException = (SQLException) cause;
- return null == sqlException.getSQLState() ? new MySQLErrPacket(1,
MySQLServerErrorCode.ER_INTERNAL_ERROR, getErrorMessage(sqlException))
+ return null == sqlException.getSQLState() ? new MySQLErrPacket(1,
MySQLErrorCode.ER_INTERNAL_ERROR, getErrorMessage(sqlException))
: new MySQLErrPacket(1, sqlException.getErrorCode(),
sqlException.getSQLState(), sqlException.getMessage());
}
if (cause instanceof ShardingSphereInsideException) {
@@ -60,13 +60,13 @@ public final class MySQLErrPacketFactory {
return new MySQLErrPacket(1,
DistSQLErrorCode.valueOf(distSQLException), distSQLException.getVariable());
}
if (cause instanceof UnsupportedPreparedStatementException) {
- return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_UNSUPPORTED_PS);
+ return new MySQLErrPacket(1, MySQLErrorCode.ER_UNSUPPORTED_PS);
}
if (cause instanceof PipelineJobNotFoundException) {
return new MySQLErrPacket(1,
StandardSQLErrorCode.SCALING_JOB_NOT_EXIST, ((PipelineJobNotFoundException)
cause).getJobId());
}
if (cause instanceof UnsupportedCharsetException) {
- return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
+ return new MySQLErrPacket(1,
MySQLErrorCode.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
}
return new MySQLErrPacket(1, StandardSQLErrorCode.UNKNOWN_EXCEPTION,
cause.getMessage());
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
index d1c572f6916..1920b82e5ed 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.db.protocol.CommonConstants;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConnectionPhase;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
@@ -90,6 +90,7 @@ public final class MySQLAuthenticationEngineTest extends
ProxyContextRestorer {
verify(context).writeAndFlush(any(MySQLHandshakePacket.class));
}
+ @SuppressWarnings("unchecked")
@Test
public void assertAuthenticationMethodMismatch() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
@@ -134,7 +135,7 @@ public final class MySQLAuthenticationEngineTest extends
ProxyContextRestorer {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
ChannelHandlerContext context = getContext();
setMetaDataContexts();
- when(authenticationHandler.login(anyString(), any(), any(),
anyString())).thenReturn(Optional.of(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR));
+ when(authenticationHandler.login(anyString(), any(), any(),
anyString())).thenReturn(Optional.of(MySQLErrorCode.ER_ACCESS_DENIED_ERROR));
authenticationEngine.authenticate(context, getPayload("root",
"sharding_db", authResponse));
verify(context).writeAndFlush(any(MySQLErrPacket.class));
}
@@ -183,6 +184,7 @@ public final class MySQLAuthenticationEngineTest extends
ProxyContextRestorer {
return result;
}
+ @SuppressWarnings("unchecked")
private Channel getChannel() {
Channel result = mock(Channel.class);
doReturn(getRemoteAddress()).when(result).remoteAddress();
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
index cb004eacabf..611d82a8075 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
@@ -24,7 +24,7 @@ import
org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.authority.rule.builder.AuthorityRuleBuilder;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLAuthenticationMethod;
-import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
+import org.apache.shardingsphere.error.mysql.code.MySQLErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -92,14 +92,14 @@ public final class MySQLAuthenticationHandlerTest extends
ProxyContextRestorer {
public void assertLoginWithAbsentUser() {
initProxyContext(new ShardingSphereUser("root", "root", ""), true);
byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86,
-100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
- assertThat(authenticationHandler.login("root1", "", authResponse,
"db1").orElse(null), is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR));
+ assertThat(authenticationHandler.login("root1", "", authResponse,
"db1").orElse(null), is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR));
}
@Test
public void assertLoginWithIncorrectPassword() {
initProxyContext(new ShardingSphereUser("root", "root", ""), true);
byte[] authResponse = {0, 89, -20, -27, 65, -120, -64, -101, 86, -100,
-108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
- assertThat(authenticationHandler.login("root", "", authResponse,
"db1").orElse(null), is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR));
+ assertThat(authenticationHandler.login("root", "", authResponse,
"db1").orElse(null), is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR));
}
@Test
@@ -113,7 +113,7 @@ public final class MySQLAuthenticationHandlerTest extends
ProxyContextRestorer {
public void assertLoginWithUnauthorizedSchema() {
initProxyContext(new ShardingSphereUser("root", "root", ""), false);
byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86,
-100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
- assertThat(authenticationHandler.login("root", "", authResponse,
"db11").orElse(null), is(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR));
+ assertThat(authenticationHandler.login("root", "", authResponse,
"db11").orElse(null), is(MySQLErrorCode.ER_DBACCESS_DENIED_ERROR));
}
@Test