Skip to content

Commit

Permalink
Add support for MIGRATE AUTH2 option #1633
Browse files Browse the repository at this point in the history
Original pull request: #1637.
  • Loading branch information
dengliming authored and mp911de committed Mar 4, 2021
1 parent 40dc25f commit 59bf89e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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

0 comments on commit 59bf89e

Please sign in to comment.