Added redis authentication with username (#3201)

This commit is contained in:
Eduard Wayland authored and GitHub committed 2021-11-12 22:49:46 +00:00
1 parent f896ed723d
commit 848fc353d4
9 files changed
+22 -3

No files matched your search

+1
View File
@@ -262,6 +262,7 @@ broadcast-received-log-entries: true
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.
+1
View File
@@ -260,6 +260,7 @@ broadcast-received-log-entries: false
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.
@@ -632,6 +632,11 @@ public final class ConfigKeys {
*/
public static final ConfigKey<String> REDIS_ADDRESS = notReloadable(stringKey("redis.address", null));
/**
* The username to connect with, or an empty string if it should use default
*/
public static final ConfigKey<String> REDIS_USERNAME = notReloadable(stringKey("redis.username", ""));
/**
* The password in use by the redis server, or an empty string if there is no password
*/
@@ -140,13 +140,17 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
LuckPermsConfiguration config = getPlugin().getConfiguration();
String address = config.get(ConfigKeys.REDIS_ADDRESS);
String username = config.get(ConfigKeys.REDIS_USERNAME);
String password = config.get(ConfigKeys.REDIS_PASSWORD);
if (password.isEmpty()) {
password = null;
}
if (username.isEmpty()) {
username = null;
}
boolean ssl = config.get(ConfigKeys.REDIS_SSL);
redis.init(address, password, ssl);
redis.init(address, username, password, ssl);
return redis;
}
}
@@ -56,12 +56,16 @@ public class RedisMessenger implements Messenger {
this.consumer = consumer;
}
public void init(String address, String password, boolean ssl) {
public void init(String address, String username, String password, boolean ssl) {
String[] addressSplit = address.split(":");
String host = addressSplit[0];
int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : Protocol.DEFAULT_PORT;
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, ssl);
if (username == null) {
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, ssl);
} else {
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, username, password, ssl);
}
this.sub = new Subscription();
this.plugin.getBootstrap().getScheduler().executeAsync(this.sub);
+1
View File
@@ -265,6 +265,7 @@ broadcast-received-log-entries = true
redis {
enabled = false
address = "localhost"
username = ""
password = ""
}
+1
View File
@@ -257,6 +257,7 @@ broadcast-received-log-entries: true
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.
+1
View File
@@ -265,6 +265,7 @@ broadcast-received-log-entries = true
redis {
enabled = false
address = "localhost"
username = ""
password = ""
}
+1
View File
@@ -251,6 +251,7 @@ broadcast-received-log-entries: false
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.