From 11723144870c40ef586bf5093dca383b938149e3 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 25 Jan 2022 20:57:29 +0600 Subject: [PATCH] Address ACL V2 changes (approach 2) --- .../redis/clients/jedis/BuilderFactory.java | 4 +- .../jedis/resps/AccessControlUser.java | 68 +++++-------------- .../jedis/AccessControlListCommandsTest.java | 6 +- 3 files changed, 21 insertions(+), 57 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 54b785e2d7..afa6032a19 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -744,10 +744,10 @@ public AccessControlUser build(Object data) { // TODO: Proper implementation of ACL V2. // keys - accessControlUser.setKeys(SafeEncoder.encode((byte[]) objectList.get(7))); + accessControlUser.addKeys(SafeEncoder.encode((byte[]) objectList.get(7))); // channels - accessControlUser.setChannels(SafeEncoder.encode((byte[]) objectList.get(9))); + accessControlUser.addChannels(SafeEncoder.encode((byte[]) objectList.get(9))); } // selectors diff --git a/src/main/java/redis/clients/jedis/resps/AccessControlUser.java b/src/main/java/redis/clients/jedis/resps/AccessControlUser.java index 73b97a5667..6013a8f760 100644 --- a/src/main/java/redis/clients/jedis/resps/AccessControlUser.java +++ b/src/main/java/redis/clients/jedis/resps/AccessControlUser.java @@ -1,16 +1,15 @@ package redis.clients.jedis.resps; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class AccessControlUser { private final List flags = new ArrayList<>(); - private final List keysList = new ArrayList<>(); - private String keysString; + private final List keys = new ArrayList<>(); private final List passwords = new ArrayList<>(); - private final List channelsList = new ArrayList<>(); - private String channelsString; + private final List channels = new ArrayList<>(); private String commands; public AccessControlUser() { @@ -25,33 +24,17 @@ public List getFlags() { } public void addKey(String key) { - keysList.add(key); + keys.add(key); } - /** - * @deprecated Use {@link AccessControlUser#getKeysList()}. - */ - @Deprecated public List getKeys() { - return keysList; + return keys; } - /** - * For Redis version below 7. - */ - public List getKeysList() { - return keysList; - } - - /** - * For Redis version from 7. - */ - public String getKeysString() { - return keysString; - } - - public void setKeys(String keys) { - this.keysString = keys; + public void addKeys(String keys) { + if (!keys.isEmpty()) { + this.keys.addAll(Arrays.asList(keys.split(" "))); + } } public void addPassword(String password) { @@ -63,33 +46,17 @@ public List getPassword() { } public void addChannel(String channel) { - channelsList.add(channel); + channels.add(channel); } - /** - * @deprecated Use {@link AccessControlUser#getChannelsList()}. - */ - @Deprecated public List getChannels() { - return channelsList; - } - - /** - * For Redis version below 7. - */ - public List getChannelsList() { - return channelsList; - } - - /** - * For Redis version from 7. - */ - public String getChannelsString() { - return channelsString; + return channels; } - public void setChannels(String channels) { - this.channelsString = channels; + public void addChannels(String channels) { + if (!channels.isEmpty()) { + this.channels.addAll(Arrays.asList(channels.split(" "))); + } } public String getCommands() { @@ -102,8 +69,7 @@ public void setCommands(String commands) { @Override public String toString() { - return "AccessControlUser{" + "flags=" + flags + ", passwords=" + passwords + ", commands='" + commands - + "', keys='" + (keysString != null ? keysString : keysList) - + "', channels='" + (channelsString != null ? channelsString : channelsList) + "'}"; + return "AccessControlUser{" + "flags=" + flags + ", passwords=" + passwords + + ", commands='" + commands + "', keys='" + keys + "', channels='" + channels + "'}"; } } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java index 566f917225..cd4dd1197e 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java @@ -78,8 +78,7 @@ public void aclGetUser() { assertEquals(1, userInfo.getFlags().size()); assertEquals(1, userInfo.getPassword().size()); assertEquals("+@all", userInfo.getCommands()); -// assertEquals("*", userInfo.getKeys().get(0)); - assertEquals("~*", userInfo.getKeysString()); + assertEquals("~*", userInfo.getKeys().get(0)); // create new user jedis.aclDelUser(USER_ZZZ); @@ -463,8 +462,7 @@ public void aclBinaryCommandsTest() { assertThat(userInfo.getCommands(), containsString("+@all")); assertThat(userInfo.getCommands(), containsString("-@string")); assertThat(userInfo.getCommands(), containsString("+debug|digest")); -// assertEquals("testchannel:*", userInfo.getChannels().get(0)); - assertEquals("&testchannel:*", userInfo.getChannelsString()); + assertEquals("&testchannel:*", userInfo.getChannels().get(0)); jedis.aclDelUser(USER_ZZZ.getBytes());