Search in sources :

Example 31 with MycatException

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);
}
Also used : MycatException(io.mycat.MycatException)

Aggregations

MycatException (io.mycat.MycatException)31 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLName (com.alibaba.druid.sql.ast.SQLName)3 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)3 MySQLClientSession (io.mycat.proxy.session.MySQLClientSession)3 SQLException (java.sql.SQLException)3 CalciteSqlBasicCall (com.alibaba.druid.support.calcite.CalciteSqlBasicCall)2 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)2 DatasourceConfig (io.mycat.config.DatasourceConfig)2 ProxyBufferImpl (io.mycat.proxy.buffer.ProxyBufferImpl)2 ReactorEnvThread (io.mycat.proxy.reactor.ReactorEnvThread)2 Future (io.vertx.core.Future)2 PromiseInternal (io.vertx.core.impl.future.PromiseInternal)2 Statement (java.sql.Statement)2 DateString (org.apache.calcite.util.DateString)2 TimeString (org.apache.calcite.util.TimeString)2 TimestampString (org.apache.calcite.util.TimestampString)2 SQLBooleanExpr (com.alibaba.druid.sql.ast.expr.SQLBooleanExpr)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLShowTablesStatement (com.alibaba.druid.sql.ast.statement.SQLShowTablesStatement)1