DB credentials can be CLI options + log warning: insecure v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 01 Jan 2014 02:56:08 +0100
branchv_0
changeset 108 d06d90b28217
parent 107 8189a4a28cd8
child 109 aef98fd7c7c9
DB credentials can be CLI options + log warning: insecure
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
java/sql-dk/src/info/globalcode/sql/dk/configuration/Properties.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();
--- 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());