Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MIGRATE AUTH2 option #1637

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 43 additions & 1 deletion src/main/java/io/lettuce/core/MigrateArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* {@link MigrateArgs} is a mutable object and instances should be used only once to avoid shared mutable state.
*
* @author Mark Paluch
* @author dengliming
*/
public class MigrateArgs<K> implements CompositeArgument {

Expand All @@ -42,6 +43,8 @@ public class MigrateArgs<K> implements CompositeArgument {

private char[] password;

private char[] username;

/**
* Builder entry points for {@link MigrateArgs}.
*/
Expand Down Expand Up @@ -119,6 +122,17 @@ public static <K> MigrateArgs<K> auth(CharSequence password) {
return new MigrateArgs<K>().auth(password);
}

/**
* Creates new {@link MigrateArgs} with {@code AUTH2} (target authentication) enabled.
*
* @return new {@link MigrateArgs} with {@code AUTH2} (target authentication) enabled.
* @since 6.1
* @see MigrateArgs#auth2(CharSequence, CharSequence)
*/
public static <K> MigrateArgs<K> auth2(CharSequence username, CharSequence password) {
return new MigrateArgs<K>().auth2(username, password);
}

/**
* Creates new {@link MigrateArgs} with {@code AUTH} (target authentication) enabled.
*
Expand Down Expand Up @@ -216,6 +230,29 @@ public MigrateArgs<K> auth(CharSequence password) {
return this;
}

/**
* Set {@literal AUTH2} {@code username} and {@code password} option.
*
* @param username must not be {@code null}.
* @param password must not be {@code null}.
* @return {@code this} {@link MigrateArgs}.
* @since 6.1
*/
public MigrateArgs<K> auth2(CharSequence username, CharSequence password) {

LettuceAssert.notNull(username, "UserName must not be null");
LettuceAssert.notNull(password, "Password must not be null");

char[] chars = new char[username.length()];

for (int i = 0; i < username.length(); i++) {
chars[i] = username.charAt(i);
}

this.username = chars;
return auth(password);
}

/**
* Set {@literal AUTH} {@code password} option.
*
Expand Down Expand Up @@ -243,7 +280,12 @@ public <K, V> void build(CommandArgs<K, V> args) {
}

if (password != null) {
args.add(CommandType.AUTH).add(password);
if (username != null) {
args.add(CommandType.AUTH2).add(username);
} else {
args.add(CommandType.AUTH);
}
args.add(password);
}

if (keys.size() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum CommandType implements ProtocolKeyword {

// Authentication

ACL, AUTH,
ACL, AUTH, AUTH2,

// Connection

Expand Down