Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import com.github.shyiko.mysql.binlog.network.protocol.ErrorPacket;
import com.github.shyiko.mysql.binlog.network.protocol.GreetingPacket;
import com.github.shyiko.mysql.binlog.network.protocol.PacketChannel;
import com.github.shyiko.mysql.binlog.network.protocol.command.AuthenticateNativePasswordCommand;
import com.github.shyiko.mysql.binlog.network.protocol.command.AuthenticateSHA2Command;
import com.github.shyiko.mysql.binlog.network.protocol.command.AuthenticateSHA2RSAPasswordCommand;
import com.github.shyiko.mysql.binlog.network.protocol.command.AuthenticateSecurityPasswordCommand;
import com.github.shyiko.mysql.binlog.network.protocol.command.ByteArrayCommand;
import com.github.shyiko.mysql.binlog.network.protocol.command.Command;
import com.github.shyiko.mysql.binlog.network.protocol.command.SSLRequestCommand;
import com.github.shyiko.mysql.binlog.network.protocol.command.*;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -21,7 +15,8 @@
public class Authenticator {
private enum AuthMethod {
NATIVE,
CACHING_SHA2
CACHING_SHA2,
CLEAR_PASSWORD
};

private final GreetingPacket greetingPacket;
Expand All @@ -35,6 +30,7 @@ private enum AuthMethod {

private final String SHA2_PASSWORD = "caching_sha2_password";
private final String MYSQL_NATIVE = "mysql_native_password";
private final String MYSQL_CLEAR_PASSWORD = "mysql_clear_password";

private AuthMethod authMethod = AuthMethod.NATIVE;

Expand Down Expand Up @@ -170,6 +166,12 @@ private void switchAuthentication(byte[] authenticationResult) throws IOExceptio
this.scramble = buffer.readZeroTerminatedString();
Command authCommand = new AuthenticateSHA2Command(scramble, password);
channel.write(authCommand);
} else if (MYSQL_CLEAR_PASSWORD.equals(authName)) {
authMethod = AuthMethod.CLEAR_PASSWORD;

Command swithCommand = new AuthenticateClearPasswordCommand(password);
channel.write(swithCommand);

} else {
throw new AuthenticationException("unsupported authentication method: " + authName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.shyiko.mysql.binlog.network.protocol.command;

import com.github.shyiko.mysql.binlog.io.ByteArrayOutputStream;

import java.io.IOException;

public class AuthenticateClearPasswordCommand implements Command {
private String password;

public AuthenticateClearPasswordCommand(String password) {
this.password = password;
}

@Override
public byte[] toByteArray() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
buffer.writeZeroTerminatedString(password);
return buffer.toByteArray();
}
}
Loading