Skip to content

Commit 83c1af2

Browse files
ACL LOG support entry-id (#3366)
fixes #3346
1 parent 50cf71e commit 83c1af2

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/main/java/redis/clients/jedis/BuilderFactory.java

+3
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,9 @@ private Map<String, Builder> createDecoderMap() {
925925
tempMappingFunctions.put(AccessControlLogEntry.USERNAME, STRING);
926926
tempMappingFunctions.put(AccessControlLogEntry.AGE_SECONDS, STRING);
927927
tempMappingFunctions.put(AccessControlLogEntry.CLIENT_INFO, STRING);
928+
tempMappingFunctions.put(AccessControlLogEntry.ENTRY_ID, LONG);
929+
tempMappingFunctions.put(AccessControlLogEntry.TIMESTAMP_CREATED, LONG);
930+
tempMappingFunctions.put(AccessControlLogEntry.TIMESTAMP_LAST_UPDATED, LONG);
928931

929932
return tempMappingFunctions;
930933
}

src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public class AccessControlLogEntry implements Serializable {
1919
public static final String USERNAME = "username";
2020
public static final String AGE_SECONDS = "age-seconds";
2121
public static final String CLIENT_INFO = "client-info";
22+
// Redis 7.2
23+
public static final String ENTRY_ID = "entry-id";
24+
public static final String TIMESTAMP_CREATED = "timestamp-created";
25+
public static final String TIMESTAMP_LAST_UPDATED = "timestamp-last-updated";
2226

2327
private long count;
2428
private final String reason;
@@ -28,6 +32,9 @@ public class AccessControlLogEntry implements Serializable {
2832
private final String ageSeconds;
2933
private final Map<String, String> clientInfo;
3034
private final Map<String, Object> logEntry;
35+
private final long entryId;
36+
private final long timestampCreated;
37+
private final long timestampLastUpdated;
3138

3239
public AccessControlLogEntry(Map<String, Object> map) {
3340
count = (long) map.get(COUNT);
@@ -38,6 +45,9 @@ public AccessControlLogEntry(Map<String, Object> map) {
3845
ageSeconds = (String) map.get(AGE_SECONDS);
3946
clientInfo = getMapFromRawClientInfo((String) map.get(CLIENT_INFO));
4047
logEntry = map;
48+
entryId = (long) map.get(ENTRY_ID);
49+
timestampCreated = (long) map.get(TIMESTAMP_CREATED);
50+
timestampLastUpdated = (long) map.get(TIMESTAMP_LAST_UPDATED);
4151
}
4252

4353
public long getCount() {
@@ -75,6 +85,18 @@ public Map<String, Object> getlogEntry() {
7585
return logEntry;
7686
}
7787

88+
public long getEntryId() {
89+
return entryId;
90+
}
91+
92+
public long getTimestampCreated() {
93+
return timestampCreated;
94+
}
95+
96+
public long getTimestampLastUpdated() {
97+
return timestampLastUpdated;
98+
}
99+
78100
/**
79101
* Convert the client-info string into a Map of String. When the value is empty, the value in the
80102
* map is set to an empty string The key order is maintained to reflect the string return by Redis
@@ -95,6 +117,8 @@ private Map<String, String> getMapFromRawClientInfo(String clientInfo) {
95117
public String toString() {
96118
return "AccessControlLogEntry{" + "count=" + count + ", reason='" + reason + '\''
97119
+ ", context='" + context + '\'' + ", object='" + object + '\'' + ", username='" + username
98-
+ '\'' + ", ageSeconds='" + ageSeconds + '\'' + ", clientInfo=" + clientInfo + '}';
120+
+ '\'' + ", ageSeconds='" + ageSeconds + '\'' + ", clientInfo=" + clientInfo
121+
+ ", entryId=" + entryId + ", timestampCreated=" + timestampCreated
122+
+ ", timestampLastUpdated=" + timestampLastUpdated + '}';
99123
}
100124
}

src/test/java/redis/clients/jedis/commands/jedis/AccessControlListCommandsTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import redis.clients.jedis.Transaction;
2626
import redis.clients.jedis.exceptions.JedisAccessControlException;
2727
import redis.clients.jedis.exceptions.JedisDataException;
28+
import redis.clients.jedis.resps.AccessControlLogEntry;
2829
import redis.clients.jedis.resps.AccessControlUser;
2930
import redis.clients.jedis.util.RedisVersionUtil;
3031
import redis.clients.jedis.util.SafeEncoder;
@@ -444,6 +445,30 @@ public void aclLogTest() {
444445
jedis.aclDelUser("antirez");
445446
}
446447

448+
@Test
449+
public void aclLogWithEntryID() {
450+
try {
451+
jedis.auth("wronguser", "wrongpass");
452+
fail("wrong user should not passed");
453+
} catch (JedisAccessControlException e) {
454+
}
455+
456+
List<AccessControlLogEntry> aclEntries = jedis.aclLog();
457+
assertEquals("Number of log messages ", 1, aclEntries.size());
458+
assertEquals(1, aclEntries.get(0).getCount());
459+
assertEquals("wronguser", aclEntries.get(0).getUsername());
460+
assertEquals("toplevel", aclEntries.get(0).getContext());
461+
assertEquals("auth", aclEntries.get(0).getReason());
462+
assertEquals("AUTH", aclEntries.get(0).getObject());
463+
assertTrue(aclEntries.get(0).getEntryId() >= 0);
464+
assertTrue(aclEntries.get(0).getTimestampCreated() > 0);
465+
assertEquals(aclEntries.get(0).getTimestampCreated(), aclEntries.get(0).getTimestampLastUpdated());
466+
467+
// RESET
468+
String status = jedis.aclLogReset();
469+
assertEquals(status, "OK");
470+
}
471+
447472
@Test
448473
public void aclGenPass() {
449474
assertNotNull(jedis.aclGenPass());

0 commit comments

Comments
 (0)