GeezerVison is showing github.com — ACL patterns for Pub/Sub channels (#2750) · redis/jedis@dc6a891
File treeExpand file treeCollapse file tree Open diff view settings main/java/redis/clients/jedis test/java/redis/clients/jedis/commands/jedis
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/redis/clients/jedis/BuilderFactory.java +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -692,6 +692,7 @@ public String toString() { | 692 | 692 | * Create a AccessControlUser object from the ACL GETUSER < > result | 693 | 693 | */ | 694 | 694 | public static final Builder<AccessControlUser> ACCESS_CONTROL_USER = new Builder<AccessControlUser>() { | | 695 | + @SuppressWarnings("unchecked") | 695 | 696 | @Override | 696 | 697 | public AccessControlUser build(Object data) { | 697 | 698 | if (data == null) { | @@ -726,6 +727,14 @@ public AccessControlUser build(Object data) { | 726 | 727 | accessControlUser.addKey(SafeEncoder.encode((byte[]) k)); | 727 | 728 | } | 728 | 729 |
| | 730 | + // before redis 6.2, no channels info | | 731 | + if (objectList.size() > 9) { | | 732 | + List<Object> channels = objectList.get(9); | | 733 | + for (Object channel : channels) { | | 734 | + accessControlUser.addChannel(SafeEncoder.encode((byte[]) channel)); | | 735 | + } | | 736 | + } | | 737 | + | 729 | 738 | return accessControlUser; | 730 | 739 | } | 731 | 740 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/redis/clients/jedis/commands/AccessControlLogBinaryCommands.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,6 +53,11 @@ public interface AccessControlLogBinaryCommands { | 53 | 53 | */ | 54 | 54 | List<byte[]> aclUsersBinary(); | 55 | 55 |
| | 56 | + /** | | 57 | + * The command returns all the rules defined for an existing ACL user. | | 58 | + * @param name username | | 59 | + * @return a list of ACL rule definitions for the user. | | 60 | + */ | 56 | 61 | AccessControlUser aclGetUser(byte[] name); | 57 | 62 |
| 58 | 63 | /** | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/redis/clients/jedis/commands/AccessControlLogCommands.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,11 @@ public interface AccessControlLogCommands { | 55 | 55 | */ | 56 | 56 | List<String> aclUsers(); | 57 | 57 |
| | 58 | + /** | | 59 | + * The command returns all the rules defined for an existing ACL user. | | 60 | + * @param name username | | 61 | + * @return a list of ACL rule definitions for the user. | | 62 | + */ | 58 | 63 | AccessControlUser aclGetUser(String name); | 59 | 64 |
| 60 | 65 | /** | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/redis/clients/jedis/resps/AccessControlUser.java +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ public class AccessControlUser { | 8 | 8 | private final List<String> flags = new ArrayList<>(); | 9 | 9 | private final List<String> keys = new ArrayList<>(); | 10 | 10 | private final List<String> passwords = new ArrayList<>(); | | 11 | + private final List<String> channels = new ArrayList<>(); | 11 | 12 | private String commands; | 12 | 13 |
| 13 | 14 | public AccessControlUser() { | @@ -37,6 +38,14 @@ public List<String> getPassword() { | 37 | 38 | return passwords; | 38 | 39 | } | 39 | 40 |
| | 41 | + public void addChannel(String channel) { | | 42 | + channels.add(channel); | | 43 | + } | | 44 | + | | 45 | + public List<String> getChannels() { | | 46 | + return channels; | | 47 | + } | | 48 | + | 40 | 49 | public String getCommands() { | 41 | 50 | return commands; | 42 | 51 | } | @@ -48,6 +57,6 @@ public void setCommands(String commands) { | 48 | 57 | @Override | 49 | 58 | public String toString() { | 50 | 59 | return "AccessControlUser{" + "flags=" + flags + ", keys=" + keys + ", passwords=" + passwords | 51 | | - + ", commands='" + commands + '\'' + '}'; | | 60 | + + ", commands='" + commands + ", channels='" + channels + '\'' + '}'; | 52 | 61 | } | 53 | 62 | } |
Collapse file Copy file name to clipboardExpand all lines: src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -454,13 +454,15 @@ public void aclBinaryCommandsTest() { | 454 | 454 | assertEquals(1L, jedis.aclDelUser(USER_ZZZ.getBytes())); | 455 | 455 |
| 456 | 456 | jedis.aclSetUser(USER_ZZZ.getBytes(), "reset".getBytes(), "+@all".getBytes(), "~*".getBytes(), | 457 | | - "-@string".getBytes(), "+incr".getBytes(), "-debug".getBytes(), "+debug|digest".getBytes()); | | 457 | + "-@string".getBytes(), "+incr".getBytes(), "-debug".getBytes(), "+debug|digest".getBytes(), | | 458 | + "resetchannels".getBytes(), "&testchannel:*".getBytes()); | 458 | 459 |
| 459 | 460 | AccessControlUser userInfo = jedis.aclGetUser(USER_ZZZ.getBytes()); | 460 | 461 |
| 461 | 462 | assertThat(userInfo.getCommands(), containsString("+@all")); | 462 | 463 | assertThat(userInfo.getCommands(), containsString("-@string")); | 463 | 464 | assertThat(userInfo.getCommands(), containsString("+debug|digest")); | | 465 | + assertEquals("testchannel:*", userInfo.getChannels().get(0)); | 464 | 466 |
| 465 | 467 | jedis.aclDelUser(USER_ZZZ.getBytes()); | 466 | 468 |
| |
|