From 73879640e5ed5e0632dfa05b4789e4fbd34ecf73 Mon Sep 17 00:00:00 2001 From: mohammed Alteniji <34905970+ham1255@users.noreply.github.com> Date: Wed, 12 Apr 2023 22:40:01 +0400 Subject: [PATCH] add ability to use redisbungee with acl username (#69) --- .../redisbungee/api/config/ConfigLoader.java | 13 +++++++++---- RedisBungee-API/src/main/resources/config.yml | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java index 9ba2b9a..e6cdc19 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java @@ -12,7 +12,6 @@ package com.imaginarycode.minecraft.redisbungee.api.config; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; import com.google.common.reflect.TypeToken; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; @@ -54,6 +53,7 @@ public interface ConfigLoader { final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false); final boolean restoreOldKickBehavior = node.getNode("disable-kick-when-online").getBoolean(false); String redisPassword = node.getNode("redis-password").getString(""); + String redisUsername = node.getNode("redis-username").getString(""); String proxyId = node.getNode("proxy-id").getString("test-1"); final int maxConnections = node.getNode("max-redis-connections").getInt(10); List exemptAddresses; @@ -68,6 +68,11 @@ public interface ConfigLoader { redisPassword = null; plugin.logWarn("password is empty"); } + if ((redisUsername.isEmpty() || redisUsername.equals("none"))) { + redisUsername = null; + plugin.logWarn("password is empty"); + } + if (useSSL) { plugin.logInfo("Using ssl"); } @@ -101,7 +106,7 @@ public interface ConfigLoader { if (hostAndPortSet.isEmpty()) { throw new RuntimeException("No redis cluster servers specified"); } - summoner = new JedisClusterSummoner(new ClusterConnectionProvider(hostAndPortSet, DefaultJedisClientConfig.builder().password(redisPassword).ssl(useSSL).socketTimeoutMillis(5000).timeoutMillis(10000).build(), poolConfig)); + summoner = new JedisClusterSummoner(new ClusterConnectionProvider(hostAndPortSet, DefaultJedisClientConfig.builder().user(redisUsername).password(redisPassword).ssl(useSSL).socketTimeoutMillis(5000).timeoutMillis(10000).build(), poolConfig)); redisBungeeMode = RedisBungeeMode.CLUSTER; } else { plugin.logInfo("RedisBungee MODE: SINGLE"); @@ -115,13 +120,13 @@ public interface ConfigLoader { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(node.getNode("compatibility-max-connections").getInt(3)); config.setBlockWhenExhausted(true); - jedisPool = new JedisPool(config, redisServer, redisPort, 5000, redisPassword, useSSL); + jedisPool = new JedisPool(config, redisServer, redisPort, 5000, redisUsername, redisPassword, useSSL); plugin.logInfo("Compatibility JedisPool was created"); } GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxTotal(maxConnections); poolConfig.setBlockWhenExhausted(true); - summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().timeoutMillis(5000).ssl(useSSL).password(redisPassword).build()), poolConfig), jedisPool); + summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().user(redisUsername).timeoutMillis(5000).ssl(useSSL).password(redisPassword).build()), poolConfig), jedisPool); redisBungeeMode = RedisBungeeMode.SINGLE; } plugin.logInfo("Successfully connected to Redis."); diff --git a/RedisBungee-API/src/main/resources/config.yml b/RedisBungee-API/src/main/resources/config.yml index ede06e1..dedb69d 100644 --- a/RedisBungee-API/src/main/resources/config.yml +++ b/RedisBungee-API/src/main/resources/config.yml @@ -1,4 +1,5 @@ # RedisBungee configuration file. +# Get Redis from http://redis.io/ # Cluster Mode # enabling this option will enable cluster mode. @@ -19,14 +20,18 @@ redis-cluster-servers: - host: 127.0.0.1 port: 6379 -# Get Redis from http://redis.io/ # The Redis server you use. # these settings are ignored when cluster mode is enabled. redis-server: 127.0.0.1 redis-port: 6379 +# THIS FEATURE IS REDIS V6+ +# OPTIONAL: if your redis uses acl usernames set the username here. leave empty for no username. +redis-username: "" + # OPTIONAL but recommended: If your Redis server uses AUTH, set the password required. redis-password: "" + # Maximum connections that will be maintained to the Redis server. # The default is 10. This setting should be left as-is unless you have some wildly # inefficient plugins or a lot of players.