diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 2ef8d4f88..e973efdff 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -22,8 +22,11 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.util.Enumeration; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,6 +38,8 @@ import java.util.logging.Logger; */ public final class Settings { + private static final Logger LOGGER = Logger.getLogger(Settings.class.getName()); + /** * The collection of keys used within the properties file. */ @@ -204,6 +209,43 @@ public final class Settings { } } } + logProperties("Properties loaded", props); + } + + /** + * Logs the properties. This will not log any properties that contain 'password' in the key. + * + * @param header the header to print with the log message + * @param properties the properties to log + */ + private static void logProperties(String header, Properties properties) { + if (LOGGER.isLoggable(Level.FINE)) { + final StringWriter sw = new StringWriter(); + PrintWriter pw = null; + try { + pw = new PrintWriter(sw); + pw.format("%s:%n%n", header); + final Enumeration e = properties.propertyNames(); + while (e.hasMoreElements()) { + final String key = (String) e.nextElement(); + if (key.contains("password")) { + pw.format("%s='*****'%n", key); + } else { + final String value = properties.getProperty(key); + if (value != null) { + pw.format("%s='%s'%n", key, value); + } + } + } + pw.flush(); + LOGGER.fine(sw.toString()); + } finally { + if (pw != null) { + pw.close(); + } + } + + } } /** @@ -214,6 +256,9 @@ public final class Settings { */ public static void setString(String key, String value) { INSTANCE.props.setProperty(key, value); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine(String.format("Setting: %s='%s'", key, value)); + } } /** @@ -228,6 +273,9 @@ public final class Settings { } else { INSTANCE.props.setProperty(key, Boolean.FALSE.toString()); } + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine(String.format("Setting: %s='%b'", key, value)); + } } /** @@ -268,6 +316,7 @@ public final class Settings { */ public static void mergeProperties(InputStream stream) throws IOException { INSTANCE.props.load(stream); + logProperties("Properties updated via merge", INSTANCE.props); } /**