Browse code

Filter audit log string

Thomas Fricker authored on 28/05/2019 13:47:24
Showing 1 changed files
... ...
@@ -18,6 +18,10 @@
18 18
  */
19 19
 package net.bluemind.core.auditlog.appender.slf4j;
20 20
 
21
+import java.util.HashMap;
22
+import java.util.Map;
23
+import java.util.Map.Entry;
24
+
21 25
 import org.slf4j.Logger;
22 26
 import org.slf4j.LoggerFactory;
23 27
 import org.slf4j.MDC;
... ...
@@ -37,21 +41,40 @@ public class Slf4jEventAppender implements IAuditEventAppender {
37 41
 
38 42
 		if (event.isReadOnly()) {
39 43
 			logger.debug("{} {} : (actor:{} meta: {}) -> (action:{}, ro:{}, meta: {}) on (object:{} meta: {}) succeed",
40
-					event.getTimestamp(), event.getId(), event.getActor(), event.getActorMeta(), //
41
-					event.getAction(), event.isReadOnly(), event.getActionMeta(), event.getObject(),
42
-					event.getObjectMeta());
44
+					event.getTimestamp(), event.getId(), filter(event.getActor()), filter(event.getActorMeta()), //
45
+					filter(event.getAction()), event.isReadOnly(), filter(event.getActionMeta()),
46
+					filter(event.getObject()), filter(event.getObjectMeta()));
43 47
 		} else if (event.succeed()) {
44 48
 			logger.info("{} {} : (actor:{} meta: {}) -> (action:{}, ro:{}, meta: {}) on (object:{} meta: {}) succeed",
45
-					event.getTimestamp(), event.getId(), event.getActor(), event.getActorMeta(), //
46
-					event.getAction(), event.isReadOnly(), event.getActionMeta(), event.getObject(),
47
-					event.getObjectMeta());
49
+					event.getTimestamp(), event.getId(), filter(event.getActor()), filter(event.getActorMeta()), //
50
+					filter(event.getAction()), event.isReadOnly(), filter(event.getActionMeta()),
51
+					filter(event.getObject()), filter(event.getObjectMeta()));
48 52
 		} else {
49 53
 			logger.warn("{} {} : (actor:{} meta: {}) -> (action:{}, ro:{}, meta: {}) on (object:{} meta: {}) failed",
50
-					event.getTimestamp(), event.getId(), event.getActor(), event.getActorMeta(), //
51
-					event.getAction(), event.isReadOnly(), event.getActionMeta(), event.getObject(),
52
-					event.getObjectMeta(), event.getFailure());
54
+					event.getTimestamp(), event.getId(), filter(event.getActor()), filter(event.getActorMeta()), //
55
+					filter(event.getAction()), event.isReadOnly(), filter(event.getActionMeta()),
56
+					filter(event.getObject()), filter(event.getObjectMeta()), event.getFailure());
53 57
 		}
54 58
 		MDC.clear();
55 59
 	}
56 60
 
61
+	private Map<String, String> filter(Map<String, String> data) {
62
+		Map<String, String> filtered = new HashMap<>();
63
+		for (Entry<String, String> entry : data.entrySet()) {
64
+			String key = filter(entry.getKey());
65
+			String value = filter(entry.getValue());
66
+			filtered.put(key, value);
67
+		}
68
+		return filtered;
69
+	}
70
+
71
+	private String filter(String data) {
72
+		if (data == null) {
73
+			return null;
74
+		}
75
+		data = data.replace("(", "[");
76
+		data = data.replace(")", "]");
77
+		return data;
78
+	}
79
+
57 80
 }