IDEMPIERE-472 Allow postgresql connection via SSL / Peer review
This commit is contained in:
parent
e99ca7f076
commit
e2c0220862
|
@ -51,7 +51,7 @@ public class BaseActivator implements BundleActivator {
|
||||||
@Override
|
@Override
|
||||||
public void start(BundleContext context) throws Exception {
|
public void start(BundleContext context) throws Exception {
|
||||||
//Load SSL
|
//Load SSL
|
||||||
loadSSLDBProperties(Adempiere.getAdempiereHome());
|
loadInitProperties(Adempiere.getAdempiereHome());
|
||||||
bundleContext = context;
|
bundleContext = context;
|
||||||
context.registerService(CommandProvider.class.getName(), new StackTraceCommand(), null);
|
context.registerService(CommandProvider.class.getName(), new StackTraceCommand(), null);
|
||||||
}
|
}
|
||||||
|
@ -59,19 +59,19 @@ public class BaseActivator implements BundleActivator {
|
||||||
/*
|
/*
|
||||||
* Load idempiereInit.properties into the system.
|
* Load idempiereInit.properties into the system.
|
||||||
*/
|
*/
|
||||||
private void loadSSLDBProperties(String filePath) {
|
private void loadInitProperties(String filePath) {
|
||||||
|
|
||||||
Properties s_prop = new Properties();
|
Properties props = new Properties();
|
||||||
String fileName = filePath+ File.separator+"idempiereInit.properties";
|
String fileName = filePath+ File.separator+"idempiereInit.properties";
|
||||||
File env = new File (fileName);
|
File env = new File (fileName);
|
||||||
boolean loadOk = true;
|
boolean loadOk = true;
|
||||||
if (env.exists())
|
if (env.exists() && env.isFile() && env.canRead())
|
||||||
{
|
{
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fis = new FileInputStream(env);
|
fis = new FileInputStream(env);
|
||||||
s_prop.load(fis);
|
props.load(fis);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
loadOk = false;
|
loadOk = false;
|
||||||
System.err.println("Exception while loading idempiereInit.properties: "+ e.toString());
|
System.err.println("Exception while loading idempiereInit.properties: "+ e.toString());
|
||||||
|
@ -85,10 +85,10 @@ public class BaseActivator implements BundleActivator {
|
||||||
if (loadOk) {
|
if (loadOk) {
|
||||||
String key = null;
|
String key = null;
|
||||||
String value =null;
|
String value =null;
|
||||||
Enumeration<?> enumeration = s_prop.propertyNames();
|
Enumeration<?> enumeration = props.propertyNames();
|
||||||
while (enumeration.hasMoreElements()) {
|
while (enumeration.hasMoreElements()) {
|
||||||
key = (String) enumeration.nextElement();
|
key = (String) enumeration.nextElement();
|
||||||
value = s_prop.getProperty(key);
|
value = props.getProperty(key);
|
||||||
System.setProperty(key,value) ;
|
System.setProperty(key,value) ;
|
||||||
//System.out.println("Loaded Key: "+ key + "- Value :"+value);
|
//System.out.println("Loaded Key: "+ key + "- Value :"+value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1392,13 +1392,13 @@ public class ConfigurationData
|
||||||
/**
|
/**
|
||||||
* @param ADEMPIERE_DB_EXISTS
|
* @param ADEMPIERE_DB_EXISTS
|
||||||
*/
|
*/
|
||||||
public void setDatabaseExists(String pass)
|
public void setDatabaseExists(String dbExists)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (p_panel != null)
|
if (p_panel != null)
|
||||||
p_panel.okdbExists.setSelected("Yes".equalsIgnoreCase(pass));
|
p_panel.okdbExists.setSelected("Y".equalsIgnoreCase(dbExists));
|
||||||
else
|
else
|
||||||
updateProperty(ADEMPIERE_DB_EXISTS, pass);
|
updateProperty(ADEMPIERE_DB_EXISTS, dbExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1406,9 +1406,14 @@ public class ConfigurationData
|
||||||
*/
|
*/
|
||||||
public boolean getDatabaseExists()
|
public boolean getDatabaseExists()
|
||||||
{
|
{
|
||||||
|
Object dbExists = p_properties.get(ADEMPIERE_DB_EXISTS);
|
||||||
|
if (dbExists == null)
|
||||||
|
dbExists = "N";
|
||||||
|
else
|
||||||
|
dbExists = dbExists.toString();
|
||||||
return p_panel != null
|
return p_panel != null
|
||||||
? p_panel.okdbExists.isSelected()
|
? p_panel.okdbExists.isSelected()
|
||||||
: "Yes".equalsIgnoreCase(p_properties.get(ADEMPIERE_DB_EXISTS).toString());
|
: "Y".equalsIgnoreCase( (String) dbExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class ConfigurationPanel extends JPanel implements ActionListener, IDBCon
|
||||||
private JLabel lDatabaseType = new JLabel();
|
private JLabel lDatabaseType = new JLabel();
|
||||||
JComboBox fDatabaseType = new JComboBox(ConfigurationData.DBTYPE);
|
JComboBox fDatabaseType = new JComboBox(ConfigurationData.DBTYPE);
|
||||||
//
|
//
|
||||||
JLabel lDatabaseServer = new JLabel("Base de Datos Existe");
|
JLabel lDatabaseServer = new JLabel();
|
||||||
JLabel ldbExists = new JLabel();
|
JLabel ldbExists = new JLabel();
|
||||||
JTextField fDatabaseServer = new JTextField(FIELDLENGTH);
|
JTextField fDatabaseServer = new JTextField(FIELDLENGTH);
|
||||||
private JLabel lDatabaseName = new JLabel();
|
private JLabel lDatabaseName = new JLabel();
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class SetupRes extends ListResourceBundle
|
||||||
{ "MailServer", "Mail Server" },
|
{ "MailServer", "Mail Server" },
|
||||||
{ "AdminEMailInfo", "iDempiere Administrator EMail" },
|
{ "AdminEMailInfo", "iDempiere Administrator EMail" },
|
||||||
{ "AdminEMail", "Admin EMail" },
|
{ "AdminEMail", "Admin EMail" },
|
||||||
|
{ "DbExists", "DB Already Exists" },
|
||||||
{ "DatabaseServerInfo", "Database Server Name" },
|
{ "DatabaseServerInfo", "Database Server Name" },
|
||||||
{ "DatabaseServer", "Database Server" },
|
{ "DatabaseServer", "Database Server" },
|
||||||
{ "JavaHomeInfo", "Java Home Folder" },
|
{ "JavaHomeInfo", "Java Home Folder" },
|
||||||
|
@ -72,7 +73,6 @@ public class SetupRes extends ListResourceBundle
|
||||||
{ "MailPassword", "Mail Password" },
|
{ "MailPassword", "Mail Password" },
|
||||||
{ "KeyStorePassword", "KeyStore Password" },
|
{ "KeyStorePassword", "KeyStore Password" },
|
||||||
{ "KeyStorePasswordInfo", "Password for SSL Key Store" },
|
{ "KeyStorePasswordInfo", "Password for SSL Key Store" },
|
||||||
{ "DbExists" , "DB Already Exists" },
|
|
||||||
//
|
//
|
||||||
{ "JavaType", "Java VM"},
|
{ "JavaType", "Java VM"},
|
||||||
{ "JavaTypeInfo", "Java VM Vendor"},
|
{ "JavaTypeInfo", "Java VM Vendor"},
|
||||||
|
|
|
@ -61,6 +61,7 @@ public class SetupRes_es extends ListResourceBundle
|
||||||
{ "MailServer", "Servidor Correo" },
|
{ "MailServer", "Servidor Correo" },
|
||||||
{ "AdminEMailInfo", "Email Administrador iDempiere" },
|
{ "AdminEMailInfo", "Email Administrador iDempiere" },
|
||||||
{ "AdminEMail", "Email Admin" },
|
{ "AdminEMail", "Email Admin" },
|
||||||
|
{ "DbExists", "Base de Datos Existe" }, // ?? OJO!!!
|
||||||
{ "DatabaseServerInfo", "Nombre Servidor Base de Datos" },
|
{ "DatabaseServerInfo", "Nombre Servidor Base de Datos" },
|
||||||
{ "DatabaseServer", "Servidor Base de Datos" },
|
{ "DatabaseServer", "Servidor Base de Datos" },
|
||||||
{ "JavaHomeInfo", "Carpeta Java Home" },
|
{ "JavaHomeInfo", "Carpeta Java Home" },
|
||||||
|
@ -73,7 +74,6 @@ public class SetupRes_es extends ListResourceBundle
|
||||||
{ "MailPassword", "Contrase\u00f1a Correo" },
|
{ "MailPassword", "Contrase\u00f1a Correo" },
|
||||||
{ "KeyStorePassword", "Contrase\u00f1a Key Store" },
|
{ "KeyStorePassword", "Contrase\u00f1a Key Store" },
|
||||||
{ "KeyStorePasswordInfo", "Contrase\u00f1a para SSL Key Store" },
|
{ "KeyStorePasswordInfo", "Contrase\u00f1a para SSL Key Store" },
|
||||||
{ "DbExists" , "Base de Datos Existe" },
|
|
||||||
//
|
//
|
||||||
{ "JavaType", "Java VM"},
|
{ "JavaType", "Java VM"},
|
||||||
{ "JavaTypeInfo", "Proveedor Java VM"},
|
{ "JavaTypeInfo", "Proveedor Java VM"},
|
||||||
|
|
|
@ -425,16 +425,19 @@ public class ConfigurationConsole {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dbExists(BufferedReader reader, PrintWriter writer) throws IOException {
|
private void dbExists(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||||
|
String dbExists = data.getDatabaseExists() ? "Y" : "N";
|
||||||
|
|
||||||
writer.println("DB Already Exists?(Y/N) [N]: ");
|
writer.println("DB Already Exists?(Y/N) [" + dbExists + "]: ");
|
||||||
String yesNo = reader.readLine();
|
String yesNo = reader.readLine();
|
||||||
if ((yesNo == null || yesNo.trim().length() == 0) || "n".equalsIgnoreCase(yesNo))
|
if (yesNo == null || yesNo.trim().length() == 0)
|
||||||
|
yesNo = dbExists;
|
||||||
|
if ("n".equalsIgnoreCase(yesNo))
|
||||||
{
|
{
|
||||||
data.setDatabaseExists("No");
|
data.setDatabaseExists("N");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data.setDatabaseExists("Yes");
|
data.setDatabaseExists("Y");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,8 +334,13 @@ public class ConfigOracle implements IDatabaseConfig
|
||||||
if (monitor != null)
|
if (monitor != null)
|
||||||
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SYSTEM_PASSWORD, "ErrorJDBC",
|
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SYSTEM_PASSWORD, "ErrorJDBC",
|
||||||
pass, true, error));
|
pass, true, error));
|
||||||
if (!pass && !isDBExists)
|
if (!pass) {
|
||||||
|
if (isDBExists) {
|
||||||
|
log.warning(error);
|
||||||
|
} else {
|
||||||
return error;
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1
|
// URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1
|
||||||
String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName()
|
String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName()
|
||||||
|
@ -372,20 +377,23 @@ public class ConfigOracle implements IDatabaseConfig
|
||||||
if (monitor != null)
|
if (monitor != null)
|
||||||
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_USER, "ErrorJDBC",
|
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_USER, "ErrorJDBC",
|
||||||
pass, true, error));
|
pass, true, error));
|
||||||
if (pass){
|
if (pass)
|
||||||
|
{
|
||||||
log.info("OK: Database User = " + databaseUser);
|
log.info("OK: Database User = " + databaseUser);
|
||||||
if (m_con != null)
|
if (m_con != null)
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, data.getWebStores(m_con));
|
data.setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, data.getWebStores(m_con));
|
||||||
}else{
|
}
|
||||||
if (isDBExists){
|
else
|
||||||
|
{
|
||||||
|
if (isDBExists) {
|
||||||
return error;
|
return error;
|
||||||
}else {
|
} else {
|
||||||
log.warning(error);
|
log.warning(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_EXISTS,(isDBExists==true ?"Yes":"No"));
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_EXISTS, (isDBExists ? "Y" : "N"));
|
||||||
String ospath;
|
String ospath;
|
||||||
if (System.getProperty("os.name").startsWith("Windows"))
|
if (System.getProperty("os.name").startsWith("Windows"))
|
||||||
ospath = "windows";
|
ospath = "windows";
|
||||||
|
|
|
@ -122,6 +122,7 @@ public class ConfigPostgreSQL implements IDatabaseConfig
|
||||||
// JDBC Database Info
|
// JDBC Database Info
|
||||||
String databaseName = data.getDatabaseName(); // Service Name
|
String databaseName = data.getDatabaseName(); // Service Name
|
||||||
String systemPassword = data.getDatabaseSystemPassword();
|
String systemPassword = data.getDatabaseSystemPassword();
|
||||||
|
|
||||||
// URL (derived)
|
// URL (derived)
|
||||||
String urlSystem = p_db.getConnectionURL(databaseServer.getHostName(), databasePort,
|
String urlSystem = p_db.getConnectionURL(databaseServer.getHostName(), databasePort,
|
||||||
p_db.getSystemDatabase(databaseName), p_db.getSystemUser());
|
p_db.getSystemDatabase(databaseName), p_db.getSystemUser());
|
||||||
|
@ -131,9 +132,13 @@ public class ConfigPostgreSQL implements IDatabaseConfig
|
||||||
if (monitor != null)
|
if (monitor != null)
|
||||||
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SYSTEM_PASSWORD, "ErrorJDBC",
|
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SYSTEM_PASSWORD, "ErrorJDBC",
|
||||||
pass, true, error));
|
pass, true, error));
|
||||||
if (!pass && !isDBExists)
|
if (!pass) {
|
||||||
|
if (isDBExists) {
|
||||||
|
log.warning(error);
|
||||||
|
} else {
|
||||||
return error;
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
log.info("OK: System Connection = " + urlSystem);
|
log.info("OK: System Connection = " + urlSystem);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword);
|
||||||
|
|
||||||
|
@ -141,13 +146,6 @@ public class ConfigPostgreSQL implements IDatabaseConfig
|
||||||
// Database User Info
|
// Database User Info
|
||||||
String databaseUser = data.getDatabaseUser(); // UID
|
String databaseUser = data.getDatabaseUser(); // UID
|
||||||
String databasePassword = data.getDatabasePassword(); // PWD
|
String databasePassword = data.getDatabasePassword(); // PWD
|
||||||
pass = databasePassword != null && databasePassword.length() > 0;
|
|
||||||
error = "Invalid Database User Password";
|
|
||||||
if (monitor != null)
|
|
||||||
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_USER, "ErrorJDBC",
|
|
||||||
pass, true, error));
|
|
||||||
if (!pass)
|
|
||||||
return error;
|
|
||||||
//
|
//
|
||||||
String url= p_db.getConnectionURL(databaseServer.getHostName(), databasePort,
|
String url= p_db.getConnectionURL(databaseServer.getHostName(), databasePort,
|
||||||
databaseName, databaseUser);
|
databaseName, databaseUser);
|
||||||
|
@ -157,12 +155,15 @@ public class ConfigPostgreSQL implements IDatabaseConfig
|
||||||
if (monitor != null)
|
if (monitor != null)
|
||||||
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_USER, "ErrorJDBC",
|
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_USER, "ErrorJDBC",
|
||||||
pass, true, error));
|
pass, true, error));
|
||||||
if (pass){
|
if (pass)
|
||||||
|
{
|
||||||
log.info("OK: Database User = " + databaseUser);
|
log.info("OK: Database User = " + databaseUser);
|
||||||
}else{
|
}
|
||||||
if (isDBExists){
|
else
|
||||||
|
{
|
||||||
|
if (isDBExists) {
|
||||||
return error;
|
return error;
|
||||||
}else {
|
} else {
|
||||||
log.warning(error);
|
log.warning(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,8 @@ public class ConfigPostgreSQL implements IDatabaseConfig
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword);
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword);
|
||||||
data.setProperty(ConfigurationData.ADEMPIERE_DB_EXISTS,(isDBExists==true ?"Yes":"No"));
|
data.setProperty(ConfigurationData.ADEMPIERE_DB_EXISTS, (isDBExists ? "Y" : "N"));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} // test
|
} // test
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Ini;
|
import org.compiere.util.Ini;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.Util;
|
||||||
|
|
||||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
|
|
||||||
|
@ -175,15 +176,16 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
public String getConnectionURL (CConnection connection)
|
public String getConnectionURL (CConnection connection)
|
||||||
{
|
{
|
||||||
// jdbc:postgresql://hostname:portnumber/databasename?encoding=UNICODE
|
// jdbc:postgresql://hostname:portnumber/databasename?encoding=UNICODE
|
||||||
String urlParameters = System.getProperty("org.idempiere.postgresql.URLParameters") ;
|
StringBuilder sb = new StringBuilder("jdbc:postgresql://")
|
||||||
StringBuffer sb = new StringBuffer("jdbc:postgresql:");
|
.append(connection.getDbHost())
|
||||||
sb.append("//").append(connection.getDbHost())
|
|
||||||
.append(":").append(connection.getDbPort())
|
.append(":").append(connection.getDbPort())
|
||||||
.append("/").append(connection.getDbName())
|
.append("/").append(connection.getDbName())
|
||||||
.append("?encoding=UNICODE");
|
.append("?encoding=UNICODE");
|
||||||
|
|
||||||
if (urlParameters != null)
|
String urlParameters = System.getProperty("org.idempiere.postgresql.URLParameters");
|
||||||
sb.append(urlParameters);
|
if (!Util.isEmpty(urlParameters)) {
|
||||||
|
sb.append("&").append(urlParameters);
|
||||||
|
}
|
||||||
|
|
||||||
m_connection = sb.toString();
|
m_connection = sb.toString();
|
||||||
return m_connection;
|
return m_connection;
|
||||||
|
@ -200,15 +202,15 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
||||||
String userName)
|
String userName)
|
||||||
{
|
{
|
||||||
//String ULR = "jdbc:postgresql://"+ dbHost + ":" + dbPort + "/" + dbName;
|
StringBuilder sb = new StringBuilder("jdbc:postgresql://")
|
||||||
String urlParameters = System.getProperty("org.idempiere.postgresql.URLParameters") ;
|
.append(dbHost)
|
||||||
StringBuffer sb = new StringBuffer("jdbc:postgresql:");
|
|
||||||
sb.append("//").append(dbHost)
|
|
||||||
.append(":").append(dbPort)
|
.append(":").append(dbPort)
|
||||||
.append("/").append(dbName);
|
.append("/").append(dbName);
|
||||||
|
|
||||||
if (urlParameters != null)
|
String urlParameters = System.getProperty("org.idempiere.postgresql.URLParameters") ;
|
||||||
|
if (!Util.isEmpty(urlParameters)) {
|
||||||
sb.append("?").append(urlParameters);
|
sb.append("?").append(urlParameters);
|
||||||
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} // getConnectionURL
|
} // getConnectionURL
|
||||||
|
|
Loading…
Reference in New Issue