From b05e5555f229781a649d42861e530e33768809cb Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 19 Sep 2017 20:23:23 +0200 Subject: [PATCH 1/3] qserv logging --- hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java | 5 +++++ hsarback/src/de/hsadmin/core/util/Config.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java index 0842bce..3a7da87 100644 --- a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java @@ -6,12 +6,15 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; import de.hsadmin.core.util.Config; public class JDBCProcessor extends AbstractProcessor { private static final long serialVersionUID = 1L; + + private static final Logger LOG = Logger.getLogger(JDBCProcessor.class.getName()); final private String driver; final private String url; @@ -28,6 +31,7 @@ public class JDBCProcessor extends AbstractProcessor { this.password = password; this.errorMsg = ""; this.sql = new ArrayList(); + LOG.info("Constructor 1 - DB-User: " + user + " Password: " + password); } public JDBCProcessor(final String driver, final String url) throws ProcessorException { @@ -45,6 +49,7 @@ public class JDBCProcessor extends AbstractProcessor { throw new ProcessorException("database admin-user configuration failed"); } } + LOG.info("Constructor 2 - DB-User: " + user + " Password: " + password); this.errorMsg = ""; this.sql = new ArrayList(); } diff --git a/hsarback/src/de/hsadmin/core/util/Config.java b/hsarback/src/de/hsadmin/core/util/Config.java index cbc3e75..2d713a4 100644 --- a/hsarback/src/de/hsadmin/core/util/Config.java +++ b/hsarback/src/de/hsadmin/core/util/Config.java @@ -3,10 +3,13 @@ package de.hsadmin.core.util; import java.io.File; import java.io.FileReader; import java.util.Properties; +import java.util.logging.Logger; public class Config { private static Config instance; + + private static Logger LOG = Logger.getLogger(Config.class.getName()); private Properties props; @@ -27,6 +30,7 @@ public class Config { } if (file.canRead()) { try { + LOG.info("Constructor - Properties-File: " + file.getAbsolutePath()); props.load(new FileReader(file)); } catch (Exception e) { // should not happen From a696ddfc3104fd18654689847e30d32de3dcd89e Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 19 Sep 2017 20:50:14 +0200 Subject: [PATCH 2/3] load config on queue-server --- .../de/hsadmin/core/qserv/JDBCProcessor.java | 35 +++++++------------ .../db/MySqlDatabaseProcessorFactory.java | 11 +++--- .../db/PgSqlDatabaseProcessorFactory.java | 6 ++-- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java index 3a7da87..8ec1b94 100644 --- a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java @@ -18,25 +18,24 @@ public class JDBCProcessor extends AbstractProcessor { final private String driver; final private String url; - final private String user; - final private String password; final private List sql; private String errorMsg; - public JDBCProcessor(final String driver, final String url, final String user, final String password) { - this.driver = driver; - this.url = url; - this.user = user; - this.password = password; - this.errorMsg = ""; - this.sql = new ArrayList(); - LOG.info("Constructor 1 - DB-User: " + user + " Password: " + password); - } - public JDBCProcessor(final String driver, final String url) throws ProcessorException { this.driver = driver; this.url = url; + this.errorMsg = ""; + this.sql = new ArrayList(); + } + + public void addSQL(String sqlStatement) { + sql.add(sqlStatement); + } + + public Object process() throws ProcessorException { + Connection c = null; + String user, password; final Config config = Config.getInstance(); if ("com.mysql.jdbc.Driver".equals(driver)) { user = config.getProperty("mysqladmin.user", "root"); @@ -49,17 +48,7 @@ public class JDBCProcessor extends AbstractProcessor { throw new ProcessorException("database admin-user configuration failed"); } } - LOG.info("Constructor 2 - DB-User: " + user + " Password: " + password); - this.errorMsg = ""; - this.sql = new ArrayList(); - } - - public void addSQL(String sqlStatement) { - sql.add(sqlStatement); - } - - public Object process() throws ProcessorException { - Connection c = null; + LOG.info("process() - DB-User: " + user + " Password: " + password); try { Class.forName(driver); c = DriverManager.getConnection(url, user, password); diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseProcessorFactory.java b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseProcessorFactory.java index 4e267cb..1162139 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseProcessorFactory.java @@ -15,11 +15,12 @@ import de.hsadmin.core.qserv.ProcessorException; * @author mi */ public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory { - public static JDBCProcessor createMySqlProcessor(String database, - String user, String password) { - return new JDBCProcessor("com.mysql.jdbc.Driver", - "jdbc:mysql://localhost/" + database, user, password); - } + +// public static JDBCProcessor createMySqlProcessor(String database, +// String user, String password) { +// return new JDBCProcessor("com.mysql.jdbc.Driver", +// "jdbc:mysql://localhost/" + database, user, password); +// } public static JDBCProcessor createMySqlAdminProcessor() throws ProcessorException { return new JDBCProcessor("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/"); diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseProcessorFactory.java b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseProcessorFactory.java index 4460c8b..609dfe4 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabaseProcessorFactory.java @@ -10,9 +10,9 @@ import de.hsadmin.core.qserv.ProcessorException; public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory { - public static JDBCProcessor createPostgreSqlProcessor(String user, String password) { - return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password); - } +// public static JDBCProcessor createPostgreSqlProcessor(String user, String password) { +// return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password); +// } public static JDBCProcessor createPostgreSqlAdminProcessor() throws ProcessorException { return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1"); From b353e00b6cb494bd3dee9c4c55a0939a217153dc Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 19 Sep 2017 21:16:53 +0200 Subject: [PATCH 3/3] do not log full password --- hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java | 3 ++- hsarback/src/de/hsadmin/core/util/TextUtil.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java index 8ec1b94..a570d14 100644 --- a/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/JDBCProcessor.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.logging.Logger; import de.hsadmin.core.util.Config; +import de.hsadmin.core.util.TextUtil; public class JDBCProcessor extends AbstractProcessor { @@ -48,7 +49,7 @@ public class JDBCProcessor extends AbstractProcessor { throw new ProcessorException("database admin-user configuration failed"); } } - LOG.info("process() - DB-User: " + user + " Password: " + password); + LOG.info("process() - DB-User: " + user + " Password: " + TextUtil.hidePassword(password)); try { Class.forName(driver); c = DriverManager.getConnection(url, user, password); diff --git a/hsarback/src/de/hsadmin/core/util/TextUtil.java b/hsarback/src/de/hsadmin/core/util/TextUtil.java index 3f65d8f..55b953f 100644 --- a/hsarback/src/de/hsadmin/core/util/TextUtil.java +++ b/hsarback/src/de/hsadmin/core/util/TextUtil.java @@ -76,4 +76,12 @@ public class TextUtil { return parsedValue; } + public static synchronized String hidePassword(String passwd) { + StringBuffer val = new StringBuffer(passwd.substring(0, 2)); + for (int i = 2; i < passwd.length(); i++) { + val.append('*'); + } + return val.toString(); + } + }