Added redis authentication with username (#3201)

This commit is contained in:
Eduard Wayland 2021-11-12 23:49:46 +01:00 committed by GitHub
parent f896ed723d
commit 848fc353d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 3 deletions

View File

@ -262,6 +262,7 @@ broadcast-received-log-entries: true
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.

View File

@ -260,6 +260,7 @@ broadcast-received-log-entries: false
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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);

View File

@ -265,6 +265,7 @@ broadcast-received-log-entries = true
redis {
enabled = false
address = "localhost"
username = ""
password = ""
}

View File

@ -257,6 +257,7 @@ broadcast-received-log-entries: true
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.

View File

@ -265,6 +265,7 @@ broadcast-received-log-entries = true
redis {
enabled = false
address = "localhost"
username = ""
password = ""
}

View File

@ -251,6 +251,7 @@ broadcast-received-log-entries: false
redis:
enabled: false
address: localhost
username: ''
password: ''
# Settings for RabbitMQ.