@Test public void shouldAnonymizeIPs() throws Exception { String toAnonymize = "192.168.0.1 127.0.0.1 2001:db8:3:4:: 64:ff9b:: 2001:db8:a0b:12f0::1 2001:0db8:0a0b:12f0:0000:0000:0000:0001"; String anonymized = testee.getAnonymizedLog(toAnonymize); Arrays.stream(toAnonymize.split(" ")).skip(2).forEach(x -> { Assertions.assertThat(anonymized).doesNotContain(x); }); Assertions.assertThat(anonymized).contains("192.168.0.1"); Assertions.assertThat(anonymized).contains("<localhost>"); }
public String getAnonymizedLog(String log) { for (UserAuthConfig userAuthConfig : configProvider.getBaseConfig().getAuth().getUsers()) { logger.debug("Removing username from log"); log = log.replaceAll("(?i)(user|username)([=:])" + userAuthConfig.getUsername(), "$1$2<USERNAME>"); } for (IndexerConfig indexerConfig : configProvider.getBaseConfig().getIndexers()) { if (Strings.isNullOrEmpty(indexerConfig.getApiKey()) || indexerConfig.getApiKey().length() < 5) { continue; } logger.debug("Removing API key for indexer {} from log", indexerConfig.getName()); log = log.replace(indexerConfig.getApiKey(), "<APIKEY>"); } logger.debug("Removing URL username/password from log"); log = log.replaceAll("(https?):\\/\\/((.+?)(:(.+?)|)@)", "$1: logger.debug("Removing cookies from log"); log = log.replaceAll("Set-Cookie: (\\w+)=(\\w)+;?", "Set-Cookie: $1:<HIDDEN>"); log = log.replaceAll("remember-me=(\\w)+;?", "remember-me=$1:<HIDDEN>"); log = log.replaceAll("Auth-Token=(\\w)+;?", "Auth-Token=$1:<HIDDEN>"); log = log.replaceAll("HYDRA-XSRF-TOKEN=([\\w\\-])+;?", "HYDRA-XSRF-TOKEN=$1:<HIDDEN>"); logger.debug("Removing base path from log"); log = log.replace(new File("").getAbsolutePath(), "<BASEPATH>"); log = removeIpsFromLog(log); return log; }
LogAnonymizer { public String getAnonymizedLog(String log) { for (UserAuthConfig userAuthConfig : configProvider.getBaseConfig().getAuth().getUsers()) { logger.debug("Removing username from log"); log = log.replaceAll("(?i)(user|username)([=:])" + userAuthConfig.getUsername(), "$1$2<USERNAME>"); } for (IndexerConfig indexerConfig : configProvider.getBaseConfig().getIndexers()) { if (Strings.isNullOrEmpty(indexerConfig.getApiKey()) || indexerConfig.getApiKey().length() < 5) { continue; } logger.debug("Removing API key for indexer {} from log", indexerConfig.getName()); log = log.replace(indexerConfig.getApiKey(), "<APIKEY>"); } logger.debug("Removing URL username/password from log"); log = log.replaceAll("(https?):\\/\\/((.+?)(:(.+?)|)@)", "$1: logger.debug("Removing cookies from log"); log = log.replaceAll("Set-Cookie: (\\w+)=(\\w)+;?", "Set-Cookie: $1:<HIDDEN>"); log = log.replaceAll("remember-me=(\\w)+;?", "remember-me=$1:<HIDDEN>"); log = log.replaceAll("Auth-Token=(\\w)+;?", "Auth-Token=$1:<HIDDEN>"); log = log.replaceAll("HYDRA-XSRF-TOKEN=([\\w\\-])+;?", "HYDRA-XSRF-TOKEN=$1:<HIDDEN>"); logger.debug("Removing base path from log"); log = log.replace(new File("").getAbsolutePath(), "<BASEPATH>"); log = removeIpsFromLog(log); return log; } }
LogAnonymizer { public String getAnonymizedLog(String log) { for (UserAuthConfig userAuthConfig : configProvider.getBaseConfig().getAuth().getUsers()) { logger.debug("Removing username from log"); log = log.replaceAll("(?i)(user|username)([=:])" + userAuthConfig.getUsername(), "$1$2<USERNAME>"); } for (IndexerConfig indexerConfig : configProvider.getBaseConfig().getIndexers()) { if (Strings.isNullOrEmpty(indexerConfig.getApiKey()) || indexerConfig.getApiKey().length() < 5) { continue; } logger.debug("Removing API key for indexer {} from log", indexerConfig.getName()); log = log.replace(indexerConfig.getApiKey(), "<APIKEY>"); } logger.debug("Removing URL username/password from log"); log = log.replaceAll("(https?):\\/\\/((.+?)(:(.+?)|)@)", "$1: logger.debug("Removing cookies from log"); log = log.replaceAll("Set-Cookie: (\\w+)=(\\w)+;?", "Set-Cookie: $1:<HIDDEN>"); log = log.replaceAll("remember-me=(\\w)+;?", "remember-me=$1:<HIDDEN>"); log = log.replaceAll("Auth-Token=(\\w)+;?", "Auth-Token=$1:<HIDDEN>"); log = log.replaceAll("HYDRA-XSRF-TOKEN=([\\w\\-])+;?", "HYDRA-XSRF-TOKEN=$1:<HIDDEN>"); logger.debug("Removing base path from log"); log = log.replace(new File("").getAbsolutePath(), "<BASEPATH>"); log = removeIpsFromLog(log); return log; }  }
LogAnonymizer { public String getAnonymizedLog(String log) { for (UserAuthConfig userAuthConfig : configProvider.getBaseConfig().getAuth().getUsers()) { logger.debug("Removing username from log"); log = log.replaceAll("(?i)(user|username)([=:])" + userAuthConfig.getUsername(), "$1$2<USERNAME>"); } for (IndexerConfig indexerConfig : configProvider.getBaseConfig().getIndexers()) { if (Strings.isNullOrEmpty(indexerConfig.getApiKey()) || indexerConfig.getApiKey().length() < 5) { continue; } logger.debug("Removing API key for indexer {} from log", indexerConfig.getName()); log = log.replace(indexerConfig.getApiKey(), "<APIKEY>"); } logger.debug("Removing URL username/password from log"); log = log.replaceAll("(https?):\\/\\/((.+?)(:(.+?)|)@)", "$1: logger.debug("Removing cookies from log"); log = log.replaceAll("Set-Cookie: (\\w+)=(\\w)+;?", "Set-Cookie: $1:<HIDDEN>"); log = log.replaceAll("remember-me=(\\w)+;?", "remember-me=$1:<HIDDEN>"); log = log.replaceAll("Auth-Token=(\\w)+;?", "Auth-Token=$1:<HIDDEN>"); log = log.replaceAll("HYDRA-XSRF-TOKEN=([\\w\\-])+;?", "HYDRA-XSRF-TOKEN=$1:<HIDDEN>"); logger.debug("Removing base path from log"); log = log.replace(new File("").getAbsolutePath(), "<BASEPATH>"); log = removeIpsFromLog(log); return log; }  String getAnonymizedLog(String log); }
LogAnonymizer { public String getAnonymizedLog(String log) { for (UserAuthConfig userAuthConfig : configProvider.getBaseConfig().getAuth().getUsers()) { logger.debug("Removing username from log"); log = log.replaceAll("(?i)(user|username)([=:])" + userAuthConfig.getUsername(), "$1$2<USERNAME>"); } for (IndexerConfig indexerConfig : configProvider.getBaseConfig().getIndexers()) { if (Strings.isNullOrEmpty(indexerConfig.getApiKey()) || indexerConfig.getApiKey().length() < 5) { continue; } logger.debug("Removing API key for indexer {} from log", indexerConfig.getName()); log = log.replace(indexerConfig.getApiKey(), "<APIKEY>"); } logger.debug("Removing URL username/password from log"); log = log.replaceAll("(https?):\\/\\/((.+?)(:(.+?)|)@)", "$1: logger.debug("Removing cookies from log"); log = log.replaceAll("Set-Cookie: (\\w+)=(\\w)+;?", "Set-Cookie: $1:<HIDDEN>"); log = log.replaceAll("remember-me=(\\w)+;?", "remember-me=$1:<HIDDEN>"); log = log.replaceAll("Auth-Token=(\\w)+;?", "Auth-Token=$1:<HIDDEN>"); log = log.replaceAll("HYDRA-XSRF-TOKEN=([\\w\\-])+;?", "HYDRA-XSRF-TOKEN=$1:<HIDDEN>"); logger.debug("Removing base path from log"); log = log.replace(new File("").getAbsolutePath(), "<BASEPATH>"); log = removeIpsFromLog(log); return log; }  String getAnonymizedLog(String log);  }