From 045c10048d7e52f24adfaabea3b2effb0b368e91 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 5 May 2020 17:38:24 +0100 Subject: [PATCH] RedisMessenger support for SSL (#2263) --- common/build.gradle | 2 +- .../me/lucko/luckperms/common/config/ConfigKeys.java | 7 ++++++- .../luckperms/common/dependencies/Dependency.java | 4 ++-- .../luckperms/common/messaging/MessagingFactory.java | 12 +++++++++++- .../common/messaging/redis/RedisMessenger.java | 11 ++++------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 1e75c0244..68e7a7642 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -36,7 +36,7 @@ dependencies { exclude(module: 'toml4j') } compile 'com.zaxxer:HikariCP:3.4.2' - compile 'redis.clients:jedis:3.2.0' + compile 'redis.clients:jedis:3.3.0' compile 'org.mongodb:mongo-java-driver:3.12.2' compile 'org.yaml:snakeyaml:1.23' } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 14c9fda23..334bc0112 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -540,10 +540,15 @@ public final class ConfigKeys { public static final ConfigKey REDIS_ADDRESS = enduringKey(stringKey("redis.address", null)); /** - * The password in use by the redis server, or an empty string if there is no passworld + * The password in use by the redis server, or an empty string if there is no password */ public static final ConfigKey REDIS_PASSWORD = enduringKey(stringKey("redis.password", "")); + /** + * If the redis connection should use SSL + */ + public static final ConfigKey REDIS_SSL = enduringKey(booleanKey("redis.ssl", false)); + /** * The URL of the bytebin instance used to upload data */ diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java index e42daae36..38e8554cc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -210,8 +210,8 @@ public enum Dependency { JEDIS( "redis.clients", "jedis", - "3.2.0", - "+S7KUSPPUC9xDj10tANcMLC3EtPxqxv8JJiaDClgQwc=", + "3.3.0", + "HuTfz9xW/mi1fwVQ3xgPmd6qwTRMF/3fyMzw2LmOgy4=", Relocation.of("jedis", "redis{}clients{}jedis"), Relocation.of("commonspool2", "org{}apache{}commons{}pool2") ), diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java index 3745aa28c..4c55d138d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.messaging; import me.lucko.luckperms.common.config.ConfigKeys; +import me.lucko.luckperms.common.config.LuckPermsConfiguration; import me.lucko.luckperms.common.messaging.redis.RedisMessenger; import me.lucko.luckperms.common.messaging.sql.SqlMessenger; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -121,7 +122,16 @@ public class MessagingFactory

{ @Override public @NonNull Messenger obtain(@NonNull IncomingMessageConsumer incomingMessageConsumer) { RedisMessenger redis = new RedisMessenger(getPlugin(), incomingMessageConsumer); - redis.init(getPlugin().getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getPlugin().getConfiguration().get(ConfigKeys.REDIS_PASSWORD)); + + LuckPermsConfiguration config = getPlugin().getConfiguration(); + String address = config.get(ConfigKeys.REDIS_ADDRESS); + String password = config.get(ConfigKeys.REDIS_PASSWORD); + if (password.isEmpty()) { + password = null; + } + boolean ssl = config.get(ConfigKeys.REDIS_SSL); + + redis.init(address, password, ssl); return redis; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/redis/RedisMessenger.java b/common/src/main/java/me/lucko/luckperms/common/messaging/redis/RedisMessenger.java index 4506a8499..4a1579c31 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/redis/RedisMessenger.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/redis/RedisMessenger.java @@ -37,6 +37,7 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.Protocol; /** * An implementation of {@link Messenger} using Redis. @@ -55,16 +56,12 @@ public class RedisMessenger implements Messenger { this.consumer = consumer; } - public void init(String address, String password) { + public void init(String address, String password, boolean ssl) { String[] addressSplit = address.split(":"); String host = addressSplit[0]; - int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : 6379; + int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : Protocol.DEFAULT_PORT; - if (password.equals("")) { - this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port); - } else { - this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, 0, password); - } + this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, ssl); this.plugin.getBootstrap().getScheduler().executeAsync(() -> { this.sub = new Subscription(this);