# HG changeset patch # User František Kučera # Date 1388541368 -3600 # Node ID d06d90b282179b99457074e5539d258fffaaf011 # Parent 8189a4a28cd86e2fb460c79bed8b22997de400b6 DB credentials can be CLI options + log warning: insecure diff -r 8189a4a28cd8 -r d06d90b28217 java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Wed Jan 01 02:44:29 2014 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Wed Jan 01 02:56:08 2014 +0100 @@ -39,6 +39,8 @@ public class DatabaseConnection implements AutoCloseable { private static final Logger log = Logger.getLogger(DatabaseConnection.class.getName()); + private static final String JDBC_PROPERTY_USER = "user"; + public static final String JDBC_PROPERTY_PASSWORD = "password"; private DatabaseDefinition databaseDefinition; private Connection connection; private Properties properties; @@ -47,9 +49,13 @@ this.databaseDefinition = databaseDefinition; this.properties = properties; + if (properties.hasProperty(JDBC_PROPERTY_PASSWORD)) { + log.log(Level.WARNING, "Passing DB password as CLI parameter is insecure!"); + } + Properties credentials = new Properties(); - credentials.add(new Property("user", databaseDefinition.getUserName())); - credentials.add(new Property("password", databaseDefinition.getPassword())); + credentials.add(new Property(JDBC_PROPERTY_USER, databaseDefinition.getUserName())); + credentials.add(new Property(JDBC_PROPERTY_PASSWORD, databaseDefinition.getPassword())); credentials.setDefaults(databaseDefinition.getProperties()); properties.setDefaults(credentials); java.util.Properties javaProperties = properties.getJavaProperties(); diff -r 8189a4a28cd8 -r d06d90b28217 java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java --- a/java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java Wed Jan 01 02:44:29 2014 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.java Wed Jan 01 02:56:08 2014 +0100 @@ -82,6 +82,10 @@ return p == null ? defaultValue : Integer.valueOf(p.getValue()); } + public boolean hasProperty(String name) { + return findByName(this, name) != null; + } + @Override public Properties clone() { Properties clone = new Properties(size());