@Test public void assertFilterContentWithSensitiveIp() { List<String> actual = Arrays.asList("/simpleElasticDemoJob/servers/127.0.0.1", "/simpleElasticDemoJob/servers/192.168.0.1/hostName | 192.168.0.1", "/simpleElasticDemoJob/servers/192.168.0.11", "/simpleElasticDemoJob/servers/192.168.0.111"); List<String> expected = Arrays.asList("/simpleElasticDemoJob/servers/ip1", "/simpleElasticDemoJob/servers/ip2/hostName | ip2", "/simpleElasticDemoJob/servers/ip3", "/simpleElasticDemoJob/servers/ip4"); assertThat(SensitiveInfoUtils.filterSensitiveIps(actual), is(expected)); }
public static List<String> filterSensitiveIps(final List<String> target) { final Map<String, String> fakeIpMap = new HashMap<>(); final AtomicInteger step = new AtomicInteger(); return target.stream().map(input -> { Matcher matcher = IP_PATTERN.matcher(input); String result = input; while (matcher.find()) { String realIp = matcher.group(); String fakeIp; if (fakeIpMap.containsKey(realIp)) { fakeIp = fakeIpMap.get(realIp); } else { fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet(); fakeIpMap.put(realIp, fakeIp); } result = result.replace(realIp, fakeIp); } return result; }).collect(Collectors.toList()); }
SensitiveInfoUtils { public static List<String> filterSensitiveIps(final List<String> target) { final Map<String, String> fakeIpMap = new HashMap<>(); final AtomicInteger step = new AtomicInteger(); return target.stream().map(input -> { Matcher matcher = IP_PATTERN.matcher(input); String result = input; while (matcher.find()) { String realIp = matcher.group(); String fakeIp; if (fakeIpMap.containsKey(realIp)) { fakeIp = fakeIpMap.get(realIp); } else { fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet(); fakeIpMap.put(realIp, fakeIp); } result = result.replace(realIp, fakeIp); } return result; }).collect(Collectors.toList()); } }
SensitiveInfoUtils { public static List<String> filterSensitiveIps(final List<String> target) { final Map<String, String> fakeIpMap = new HashMap<>(); final AtomicInteger step = new AtomicInteger(); return target.stream().map(input -> { Matcher matcher = IP_PATTERN.matcher(input); String result = input; while (matcher.find()) { String realIp = matcher.group(); String fakeIp; if (fakeIpMap.containsKey(realIp)) { fakeIp = fakeIpMap.get(realIp); } else { fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet(); fakeIpMap.put(realIp, fakeIp); } result = result.replace(realIp, fakeIp); } return result; }).collect(Collectors.toList()); }  }
SensitiveInfoUtils { public static List<String> filterSensitiveIps(final List<String> target) { final Map<String, String> fakeIpMap = new HashMap<>(); final AtomicInteger step = new AtomicInteger(); return target.stream().map(input -> { Matcher matcher = IP_PATTERN.matcher(input); String result = input; while (matcher.find()) { String realIp = matcher.group(); String fakeIp; if (fakeIpMap.containsKey(realIp)) { fakeIp = fakeIpMap.get(realIp); } else { fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet(); fakeIpMap.put(realIp, fakeIp); } result = result.replace(realIp, fakeIp); } return result; }).collect(Collectors.toList()); }  static List<String> filterSensitiveIps(final List<String> target); }
SensitiveInfoUtils { public static List<String> filterSensitiveIps(final List<String> target) { final Map<String, String> fakeIpMap = new HashMap<>(); final AtomicInteger step = new AtomicInteger(); return target.stream().map(input -> { Matcher matcher = IP_PATTERN.matcher(input); String result = input; while (matcher.find()) { String realIp = matcher.group(); String fakeIp; if (fakeIpMap.containsKey(realIp)) { fakeIp = fakeIpMap.get(realIp); } else { fakeIp = FAKE_IP_SAMPLE + step.incrementAndGet(); fakeIpMap.put(realIp, fakeIp); } result = result.replace(realIp, fakeIp); } return result; }).collect(Collectors.toList()); }  static List<String> filterSensitiveIps(final List<String> target);  }