|
| 1 | +package redis.clients.jedis; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +/** |
| 7 | + * This class holds information about an Access Control Log entry (returned by ACL LOG command) |
| 8 | + * They can be access via getters. |
| 9 | + * For future purpose there is also {@link #getlogEntry} method |
| 10 | + * that returns a generic {@code Map} - in case where more info is returned from a server |
| 11 | + * |
| 12 | + */ |
| 13 | +public class AccessControlLogEntry implements Serializable { |
| 14 | + |
| 15 | + private static final long serialVersionUID = 1L; |
| 16 | + |
| 17 | + public static final String COUNT = "count"; |
| 18 | + public static final String REASON = "reason"; |
| 19 | + public static final String CONTEXT = "context"; |
| 20 | + public static final String OBJECT = "object"; |
| 21 | + public static final String USERNAME = "username"; |
| 22 | + public static final String AGE_SECONDS = "age-seconds"; |
| 23 | + public static final String CLIENT_INFO = "client-info"; |
| 24 | + |
| 25 | + private long count; |
| 26 | + private final String reason; |
| 27 | + private final String context; |
| 28 | + private final String object; |
| 29 | + private final String username; |
| 30 | + private final String ageSeconds; |
| 31 | + private final Map<String,String> clientInfo; |
| 32 | + private final Map<String,Object> logEntry; |
| 33 | + |
| 34 | + |
| 35 | + public AccessControlLogEntry(Map<String, Object> map) { |
| 36 | + count = (long)map.get(COUNT); |
| 37 | + reason = (String)map.get(REASON); |
| 38 | + context = (String)map.get(CONTEXT); |
| 39 | + object = (String)map.get(OBJECT); |
| 40 | + username = (String)map.get(USERNAME); |
| 41 | + ageSeconds = (String)map.get(AGE_SECONDS); |
| 42 | + clientInfo = getMapFromRawClientInfo((String)map.get(CLIENT_INFO)); |
| 43 | + logEntry = map; |
| 44 | + } |
| 45 | + |
| 46 | + public long getCount() { |
| 47 | + return count; |
| 48 | + } |
| 49 | + |
| 50 | + public String getReason() { |
| 51 | + return reason; |
| 52 | + } |
| 53 | + |
| 54 | + public String getContext() { |
| 55 | + return context; |
| 56 | + } |
| 57 | + |
| 58 | + public String getObject() { |
| 59 | + return object; |
| 60 | + } |
| 61 | + |
| 62 | + public String getUsername() { |
| 63 | + return username; |
| 64 | + } |
| 65 | + |
| 66 | + public String getAgeSeconds() { |
| 67 | + return ageSeconds; |
| 68 | + } |
| 69 | + |
| 70 | + public Map<String, String> getClientInfo() { |
| 71 | + return clientInfo; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @return Generic map containing all key-value pairs returned by the server |
| 76 | + */ |
| 77 | + public Map<String,Object> getlogEntry() { |
| 78 | + return logEntry; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Convert the client-info string into a Map of String. |
| 83 | + * When the value is empty, the value in the map is set to an empty string |
| 84 | + * The key order is maintained to reflect the string return by Redis |
| 85 | + * @param clientInfo |
| 86 | + * @return A Map with all client info |
| 87 | + */ |
| 88 | + private Map<String,String> getMapFromRawClientInfo( String clientInfo) { |
| 89 | + String[] entries = clientInfo.split(" "); |
| 90 | + Map<String,String> clientInfoMap = new LinkedHashMap<>(entries.length); |
| 91 | + for (String entry : entries) { |
| 92 | + String[] kvArray = entry.split("="); |
| 93 | + clientInfoMap.put(kvArray[0], (kvArray.length ==2)?kvArray[1]:"" ); |
| 94 | + } |
| 95 | + return clientInfoMap; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public String toString() { |
| 100 | + return "AccessControlLogEntry{" + |
| 101 | + "count=" + count + |
| 102 | + ", reason='" + reason + '\'' + |
| 103 | + ", context='" + context + '\'' + |
| 104 | + ", object='" + object + '\'' + |
| 105 | + ", username='" + username + '\'' + |
| 106 | + ", ageSeconds='" + ageSeconds + '\'' + |
| 107 | + ", clientInfo=" + clientInfo + |
| 108 | + '}'; |
| 109 | + } |
| 110 | +} |
0 commit comments