Mask password in logging wherever it occurs.

pull/113/head
Brett Wooldridge 11 years ago
parent ec16e5e12e
commit 5c5b9d009b

@ -687,7 +687,9 @@ public class HikariConfig implements HikariConfigMBean
poolName = "HikariPool-" + poolNumber++;
}
logConfiguration();
if (LOGGER.isDebugEnabled()) {
logConfiguration();
}
}
private void validateNumerics()
@ -733,15 +735,17 @@ public class HikariConfig implements HikariConfigMBean
private void logConfiguration()
{
LOGGER.debug("HikariCP pool {} configuration:", poolName);
Set<String> propertyNames = new TreeSet<String>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
final Set<String> propertyNames = new TreeSet<String>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
for (String prop : propertyNames) {
try {
Object value = PropertyBeanSetter.getProperty(prop, this);
prop = (prop + "................................................").substring(0, 32);
if (!prop.contains("password"))
{
LOGGER.debug(prop + (value != null ? value : ""));
if ("dataSourceProperties".equals(prop)) {
Properties dsProps = PropertyBeanSetter.copyProperties(dataSourceProperties);
dsProps.setProperty("password", "<masked>");
value = dsProps;
}
value = (prop.contains("password") ? "<masked>" : value);
LOGGER.debug((prop + "................................................").substring(0, 32) + (value != null ? value : ""));
}
catch (Exception e) {
continue;

@ -103,6 +103,15 @@ public final class PropertyBeanSetter
}
}
public static Properties copyProperties(Properties props)
{
Properties copy = new Properties();
for (Object key : props.keySet()) {
copy.setProperty(key.toString(), props.get(key).toString());
}
return copy;
}
private static void setProperty(Object target, String propName, Object propValue)
{
String capitalized = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);

@ -17,6 +17,10 @@ public class ConnectionStateTest
ds.setMaximumPoolSize(1);
ds.setConnectionTestQuery("VALUES 1");
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
ds.addDataSourceProperty("user", "bar");
ds.addDataSourceProperty("password", "secret");
ds.addDataSourceProperty("url", "baf");
ds.addDataSourceProperty("loginTimeout", "10");
try
{

@ -687,7 +687,9 @@ public class HikariConfig implements HikariConfigMBean
poolName = "HikariPool-" + poolNumber++;
}
logConfiguration();
if (LOGGER.isDebugEnabled()) {
logConfiguration();
}
}
private void validateNumerics()
@ -733,15 +735,17 @@ public class HikariConfig implements HikariConfigMBean
private void logConfiguration()
{
LOGGER.debug("HikariCP pool {} configuration:", poolName);
Set<String> propertyNames = new TreeSet<String>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
final Set<String> propertyNames = new TreeSet<String>(PropertyBeanSetter.getPropertyNames(HikariConfig.class));
for (String prop : propertyNames) {
try {
Object value = PropertyBeanSetter.getProperty(prop, this);
prop = (prop + "................................................").substring(0, 32);
if (!prop.contains("password"))
{
LOGGER.debug(prop + (value != null ? value : ""));
if ("dataSourceProperties".equals(prop)) {
Properties dsProps = PropertyBeanSetter.copyProperties(dataSourceProperties);
dsProps.setProperty("password", "<masked>");
value = dsProps;
}
value = (prop.contains("password") ? "<masked>" : value);
LOGGER.debug((prop + "................................................").substring(0, 32) + (value != null ? value : ""));
}
catch (Exception e) {
continue;

@ -103,6 +103,15 @@ public final class PropertyBeanSetter
}
}
public static Properties copyProperties(Properties props)
{
Properties copy = new Properties();
for (Object key : props.keySet()) {
copy.setProperty(key.toString(), props.get(key).toString());
}
return copy;
}
private static void setProperty(Object target, String propName, Object propValue)
{
String capitalized = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);

Loading…
Cancel
Save