File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
services-api/src/main/java/io/scalecube/services Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 11package io .scalecube .services ;
22
3+ import java .util .LinkedHashMap ;
34import java .util .Map ;
45import java .util .Map .Entry ;
6+ import java .util .Set ;
57import java .util .UUID ;
68import java .util .stream .Collectors ;
79
@@ -48,4 +50,32 @@ public static String mask(Map<String, String> map) {
4850 .collect (Collectors .toMap (Entry ::getKey , entry -> mask (entry .getValue ())))
4951 .toString ();
5052 }
53+
54+ /**
55+ * Mask sensitive data by replacing part of string with an asterisk symbol.
56+ *
57+ * @param map map sensitive data to be masked
58+ * @return string representation
59+ */
60+ private static String mask (Map <?, ?> map , Set <String > sensitiveKeys ) {
61+ if (map == null || map .isEmpty ()) {
62+ return String .valueOf (map );
63+ }
64+
65+ return map .entrySet ().stream ()
66+ .collect (
67+ Collectors .toMap (
68+ entry -> String .valueOf (entry .getKey ()),
69+ entry -> {
70+ final var key = String .valueOf (entry .getKey ());
71+ final var value = String .valueOf (entry .getValue ());
72+ if (entry .getKey () == null || entry .getValue () == null ) {
73+ return value ;
74+ }
75+ return sensitiveKeys .contains (key ) ? MaskUtil .mask (value ) : value ;
76+ },
77+ (v1 , v2 ) -> v1 ,
78+ LinkedHashMap ::new ))
79+ .toString ();
80+ }
5181}
You can’t perform that action at this time.
0 commit comments