Search in sources :

Example 1 with MycatVertxMysqlSession

use of io.mycat.mycatmysql.MycatVertxMysqlSession in project Mycat2 by MyCATApache.

the class VertxMySQLAuthHandler method auth.

private void auth(int packetId) {
    String username = authPacket.getUsername();
    String host = SocketAddressUtil.simplySocketAddress(socket.remoteAddress().toString());
    Authenticator authenticator = null;
    if (MetaClusterCurrent.exist(Authenticator.class)) {
        authenticator = MetaClusterCurrent.wrapper(Authenticator.class);
    }
    if (authenticator != null) {
        Authenticator.AuthInfo authInfo = authenticator.getPassword(username, host);
        String rightPassword = (authInfo.getRightPassword());
        if (!checkPassword(rightPassword, authPacket.getPassword())) {
            String message = "Access denied for user '" + username + "'@'" + host + "' (using password: YES)";
            LOGGER.error(message);
            socket.write(Buffer.buffer(MySQLPacketUtil.generateMySQLPacket(packetId + 1, MySQLPacketUtil.generateError(ER_ACCESS_DENIED_ERROR, message, 0))));
            socket.end();
            return;
        }
    }
    buffer = null;
    UserConfig userInfo = null;
    if (authenticator != null) {
        userInfo = authenticator.getUserInfo(username);
    } else {
        userInfo = new UserConfig();
    }
    InetSocketAddress remoteAddress = new InetSocketAddress(socket.remoteAddress().host(), socket.remoteAddress().port());
    mycatDataContext.setUser(new MycatUser(username, null, null, host, remoteAddress, userInfo));
    mycatDataContext.useShcema(Optional.ofNullable(authPacket.getDatabase()).orElse(userInfo.getSchema()));
    mycatDataContext.setServerCapabilities(authPacket.getCapabilities());
    mycatDataContext.setAutoCommit(true);
    mycatDataContext.setIsolation(MySQLIsolation.REPEATED_READ);
    mycatDataContext.setCharsetIndex(authPacket.getCharacterSet());
    MycatVertxMysqlSession vertxSession = new MycatVertxMysqlSession(mycatDataContext, socket);
    socket.handler(new VertxMySQLPacketResolver(socket, new MycatVertxMySQLHandler(vertxSession)));
    vertxSession.setPacketId(packetId);
    mysqlProxyServerVerticle.addSession(vertxSession);
    vertxSession.writeOkEndPacket();
}
Also used : MycatVertxMysqlSession(io.mycat.mycatmysql.MycatVertxMysqlSession) InetSocketAddress(java.net.InetSocketAddress) MycatVertxMySQLHandler(io.mycat.mycatmysql.MycatVertxMySQLHandler) UserConfig(io.mycat.config.UserConfig)

Aggregations

UserConfig (io.mycat.config.UserConfig)1 MycatVertxMySQLHandler (io.mycat.mycatmysql.MycatVertxMySQLHandler)1 MycatVertxMysqlSession (io.mycat.mycatmysql.MycatVertxMysqlSession)1 InetSocketAddress (java.net.InetSocketAddress)1