From 5a0ba813af6c98e8a50b324adcdefbae34eefbdf Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Thu, 21 Oct 2021 23:39:19 +0200 Subject: [PATCH] Add Redis 6 Support for Username (#104) Closes #104 --- .../io/dropwizard/redis/uri/RedisModeURIFactory.java | 4 +++- .../java/io/dropwizard/redis/uri/RedisURIFactory.java | 11 +++++++++++ .../dropwizard/redis/uri/SentinelModeURIFactory.java | 7 ++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/dropwizard/redis/uri/RedisModeURIFactory.java b/src/main/java/io/dropwizard/redis/uri/RedisModeURIFactory.java index bb01df9..4eff86b 100644 --- a/src/main/java/io/dropwizard/redis/uri/RedisModeURIFactory.java +++ b/src/main/java/io/dropwizard/redis/uri/RedisModeURIFactory.java @@ -70,7 +70,9 @@ public RedisURI build() { builder.withClientName(clientName); } - if (password != null) { + if (username != null && password != null) { + builder.withAuthentication(username, password); + } else if (password != null) { builder.withPassword(password); } diff --git a/src/main/java/io/dropwizard/redis/uri/RedisURIFactory.java b/src/main/java/io/dropwizard/redis/uri/RedisURIFactory.java index 10a74da..b9846a5 100644 --- a/src/main/java/io/dropwizard/redis/uri/RedisURIFactory.java +++ b/src/main/java/io/dropwizard/redis/uri/RedisURIFactory.java @@ -17,6 +17,9 @@ public abstract class RedisURIFactory implements Discoverable { @JsonProperty protected String clientName; + @JsonProperty + protected String username; + @JsonProperty protected String password; @@ -36,6 +39,14 @@ public void setClientName(final String clientName) { this.clientName = clientName; } + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + public String getPassword() { return password; } diff --git a/src/main/java/io/dropwizard/redis/uri/SentinelModeURIFactory.java b/src/main/java/io/dropwizard/redis/uri/SentinelModeURIFactory.java index d758a8f..ecf5867 100644 --- a/src/main/java/io/dropwizard/redis/uri/SentinelModeURIFactory.java +++ b/src/main/java/io/dropwizard/redis/uri/SentinelModeURIFactory.java @@ -6,11 +6,10 @@ import io.lettuce.core.RedisURI; import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.Valid; import java.util.Collections; import java.util.Set; -import javax.validation.Valid; - @JsonTypeName("sentinel") public class SentinelModeURIFactory extends RedisURIFactory { @Valid @@ -48,7 +47,9 @@ public RedisURI build() { builder.withClientName(clientName); } - if (password != null) { + if (username != null && password != null) { + builder.withAuthentication(username, password); + } else if (password != null) { builder.withPassword(password); }