File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
services-api/src/main/java/io/scalecube/services Expand file tree Collapse file tree 1 file changed +31
-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,33 @@ 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+ * @param sensitiveKeys keys whose corresponding values should be masked
59+ * @return string representation
60+ */
61+ public static String mask (Map <?, ?> map , Set <String > sensitiveKeys ) {
62+ if (map == null || map .isEmpty ()) {
63+ return String .valueOf (map );
64+ }
65+
66+ return map .entrySet ().stream ()
67+ .collect (
68+ Collectors .toMap (
69+ entry -> String .valueOf (entry .getKey ()),
70+ entry -> {
71+ final var key = String .valueOf (entry .getKey ());
72+ final var value = String .valueOf (entry .getValue ());
73+ if (entry .getKey () == null || entry .getValue () == null ) {
74+ return value ;
75+ }
76+ return sensitiveKeys .contains (key ) ? MaskUtil .mask (value ) : value ;
77+ },
78+ (v1 , v2 ) -> v1 ,
79+ LinkedHashMap ::new ))
80+ .toString ();
81+ }
5182}
You can’t perform that action at this time.
0 commit comments