use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class BackendConCreateHandler method writeClientAuth.
public void writeClientAuth(MySQLClientSession mysql) throws IOException {
int serverCapabilities = GlobalConst.getClientCapabilityFlags().value;
mysql.getBackendPacketResolver().setCapabilityFlags(serverCapabilities);
HandshakePacket hs = new HandshakePacket();
MySQLPacket payload = mysql.currentProxyPayload();
if (payload.isErrorPacket()) {
ErrorPacketImpl errorPacket = new ErrorPacketImpl();
errorPacket.readPayload(payload);
String errorMessage = new String(errorPacket.getErrorMessage());
LOGGER.error(" {} {}", this.datasource.getName(), errorMessage);
mysql.setLastMessage(errorMessage);
onException(mysql, new MycatException(errorPacket.getErrorCode(), errorMessage));
return;
}
hs.readPayload(mysql.currentProxyPayload());
mysql.resetCurrentProxyPayload();
this.mysqlVersion = hs.getServerVersion();
this.charsetIndex = hs.getCharacterSet() == -1 ? CharsetUtil.getIndex("UTF-8") : hs.getCharacterSet();
AuthPacket packet = new AuthPacket();
packet.setCapabilities(serverCapabilities);
packet.setMaxPacketSize(32 * 1024 * 1024);
packet.setCharacterSet((byte) charsetIndex);
packet.setUsername(datasource.getUsername());
this.seed = hs.getAuthPluginDataPartOne() + hs.getAuthPluginDataPartTwo();
LOGGER.info("backend mysql authPluginName:{} ", hs.getAuthPluginName());
// 加密密码
// hs.getAuthPluginName();
this.authPluginName = MysqlNativePasswordPluginUtil.PROTOCOL_PLUGIN_NAME;
LOGGER.info("mycat set authPluginName:{} ", authPluginName);
packet.setPassword(generatePassword(authPluginName, seed));
// print(packet.getPassword());
packet.setAuthPluginName(hs.getAuthPluginName());
// packet.setAuthPluginName(CachingSha2PasswordPlugin.PROTOCOL_PLUGIN_NAME);
MySQLPacket mySQLPacket = mysql.newCurrentProxyPacket(1024);
mysql.getBackendPacketResolver().setIsClientLoginRequest(true);
packet.writePayload(mySQLPacket);
this.welcomePkgReceived = true;
mysql.writeCurrentProxyPacket(mySQLPacket, 1);
}
Aggregations