@Test public void shouldAnonymizeCookiesFromConfig() throws Exception { String anonymized = testee.getAnonymizedLog("Cookies: Parsing b[]: remember-me=MTAI4MjHY0MjcXxMTpjM2U0Zjk3OWQwMjk0; Auth-Type=http; Auth-Token=C8wSA1AXvpFVjXCRGKryWtIIZS2TRqf69aZb; HYDRA-XSRF-TOKEN=1a0f551f-2178-4ad7-a0b5-3af8f77675e2"); assertThat(anonymized, is("Cookies: Parsing b[]: remember-me=0:<HIDDEN> Auth-Type=http; Auth-Token=b:<HIDDEN> HYDRA-XSRF-TOKEN=2:<HIDDEN>")); }
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);  }