Adempiere 3.1.2

This commit is contained in:
vpj-cd 2006-12-07 03:23:16 +00:00
parent 8a0bf1e3c7
commit b4c4d18be1
6 changed files with 3042 additions and 3128 deletions

View File

@ -98,6 +98,15 @@ public abstract class Config
p_data.p_properties.setProperty(key, value); p_data.p_properties.setProperty(key, value);
} // setProperty } // setProperty
/**
* Get Configuration Property
* @param key key
* @return value or ""
*/
protected String getProperty(String key)
{
return p_data.p_properties.getProperty(key, "");
} // getProperty
/** /**
* UI Signal OK * UI Signal OK

View File

@ -3,53 +3,53 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.install; package org.compiere.install;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.sql.*; import java.sql.*;
import org.compiere.db.*; import org.compiere.db.*;
import org.compiere.util.*; import org.compiere.util.*;
import com.ibm.db2.jcc.*; import com.ibm.db2.jcc.*;
/** /**
* DB/2 Configuration Test * DB/2 Configuration Test
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: ConfigDB2.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ * @version $Id: ConfigDB2.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $
*/ */
public class ConfigDB2 extends Config public class ConfigDB2 extends Config
{ {
/** /**
* ConfigOracle * ConfigOracle
* @param data configuration * @param data configuration
*/ */
public ConfigDB2 (ConfigurationData data) public ConfigDB2 (ConfigurationData data)
{ {
super (data); super (data);
} // ConfigOracle } // ConfigOracle
/** DB/2 Driver */ /** DB/2 Driver */
private static DB2Driver s_db2Driver = null; private static DB2Driver s_db2Driver = null;
/** Last Connection */ /** Last Connection */
private Connection m_con = null; private Connection m_con = null;
/** /**
* Init * Init
*/ */
public void init() public void init()
{ {
p_data.setDatabasePort(String.valueOf(DB_DB2.DEFAULT_PORT_0)); p_data.setDatabasePort(String.valueOf(DB_DB2.DEFAULT_PORT_0));
@ -57,30 +57,30 @@ public class ConfigDB2 extends Config
p_data.setDatabaseSystemPassword(true); p_data.setDatabaseSystemPassword(true);
} // init } // init
/************************************************************************** /**************************************************************************
* Test * Test
* @return error message or null if OK * @return error message or null if OK
*/ */
public String test() public String test()
{ {
// Database Server // Database Server
String server = p_data.getDatabaseServer(); String server = p_data.getDatabaseServer();
boolean pass = server != null && server.length() > 0 boolean pass = server != null && server.length() > 0
&& server.toLowerCase().indexOf("localhost") == -1 && server.toLowerCase().indexOf("localhost") == -1
&& !server.equals("127.0.0.1"); && !server.equals("127.0.0.1");
String error = "Not correct: DB Server = " + server; String error = "Not correct: DB Server = " + server;
InetAddress databaseServer = null; InetAddress databaseServer = null;
try try
{ {
if (pass) if (pass)
databaseServer = InetAddress.getByName(server); databaseServer = InetAddress.getByName(server);
} }
catch (Exception e) catch (Exception e)
{ {
error += " - " + e.getMessage(); error += " - " + e.getMessage();
pass = false; pass = false;
} }
signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer", signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer",
pass, true, error); pass, true, error);
log.info("OK: Database Server = " + databaseServer); log.info("OK: Database Server = " + databaseServer);
@ -89,10 +89,10 @@ public class ConfigDB2 extends Config
// Database Port // Database Port
int databasePort = p_data.getDatabasePort(); int databasePort = p_data.getDatabasePort();
pass = p_data.testPort (databaseServer, databasePort, true); pass = p_data.testPort (databaseServer, databasePort, true);
error = "DB Server Port = " + databasePort; error = "DB Server Port = " + databasePort;
signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort",
pass, true, error); pass, true, error);
if (!pass) if (!pass)
return error; return error;
log.info("OK: Database Port = " + databasePort); log.info("OK: Database Port = " + databasePort);
@ -100,24 +100,24 @@ public class ConfigDB2 extends Config
// JDBC Database Info // JDBC Database Info
String databaseName = p_data.getDatabaseName(); // Service Name String databaseName = p_data.getDatabaseName(); // Service Name
String systemPassword = p_data.getDatabaseSystemPassword(); String systemPassword = p_data.getDatabaseSystemPassword();
pass = systemPassword != null && systemPassword.length() > 0; pass = systemPassword != null && systemPassword.length() > 0;
error = "No Database System Password entered"; error = "No Database System Password entered";
signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", signalOK(getPanel().okDatabaseSystem, "ErrorJDBC",
pass, true, error); pass, true, error);
if (!pass) if (!pass)
return error; return error;
// //
// URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1
String url = "jdbc:db2://" + databaseServer.getHostName() String url = "jdbc:db2://" + databaseServer.getHostName()
+ ":" + databasePort + ":" + databasePort
+ "/" + databaseName; + "/" + databaseName;
pass = testJDBC(url, "db2admin", systemPassword); pass = testJDBC(url, "db2admin", systemPassword);
error = "Error connecting: " + url error = "Error connecting: " + url
+ " - as db2admin/" + systemPassword; + " - as db2admin/" + systemPassword;
signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", signalOK(getPanel().okDatabaseSystem, "ErrorJDBC",
pass, true, error); pass, true, error);
if (!pass) if (!pass)
return error; return error;
log.info("OK: Connection = " + url); log.info("OK: Connection = " + url);
@ -128,20 +128,20 @@ public class ConfigDB2 extends Config
// Database User Info // Database User Info
String databaseUser = p_data.getDatabaseUser(); // UID String databaseUser = p_data.getDatabaseUser(); // UID
String databasePassword = p_data.getDatabasePassword(); // PWD String databasePassword = p_data.getDatabasePassword(); // PWD
pass = databasePassword != null && databasePassword.length() > 0; pass = databasePassword != null && databasePassword.length() > 0;
error = "Invalid Database User Password"; error = "Invalid Database User Password";
signalOK(getPanel().okDatabaseUser, "ErrorJDBC", signalOK(getPanel().okDatabaseUser, "ErrorJDBC",
pass, true, error); pass, true, error);
if (!pass) if (!pass)
return error; return error;
// Ignore result as it might not be imported // Ignore result as it might not be imported
pass = testJDBC(url, databaseUser, databasePassword); pass = testJDBC(url, databaseUser, databasePassword);
error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword; error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword;
signalOK(getPanel().okDatabaseUser, "ErrorJDBC", signalOK(getPanel().okDatabaseUser, "ErrorJDBC",
pass, false, error); pass, false, 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)
@ -154,99 +154,99 @@ public class ConfigDB2 extends Config
if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT)) if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT))
{ {
String cmd = "db2 "; String cmd = "db2 ";
if (Env.isWindows()) if (Env.isWindows())
cmd = "db2cmd -c -w -i db2 "; cmd = "db2cmd -c -w -i db2 ";
String sqlcmd1 = cmd + "connect to xx"; String sqlcmd1 = cmd + "connect to xx";
String sqlcmd2 = cmd + "-f utils/db2/Test.sql"; String sqlcmd2 = cmd + "-f utils/db2/Test.sql";
log.config(sqlcmd2); log.config(sqlcmd2);
pass = testSQL(sqlcmd2); pass = testSQL(sqlcmd2);
error = "Error connecting via: " + sqlcmd2; error = "Error connecting via: " + sqlcmd2;
signalOK(getPanel().okDatabaseSQL, "ErrorTNS", signalOK(getPanel().okDatabaseSQL, "ErrorTNS",
pass, true, error); pass, true, error);
if (pass) if (pass)
log.info("OK: Database SQL Connection"); log.info("OK: Database SQL Connection");
} }
m_con = null; m_con = null;
return null; return null;
} // test } // test
/** /**
* Test JDBC Connection to Server * Test JDBC Connection to Server
* @param url connection string * @param url connection string
* @param uid user id * @param uid user id
* @param pwd password * @param pwd password
* @return true if OK * @return true if OK
*/ */
private boolean testJDBC (String url, String uid, String pwd) private boolean testJDBC (String url, String uid, String pwd)
{ {
log.fine("Url=" + url + ", UID=" + uid); log.fine("Url=" + url + ", UID=" + uid);
try try
{ {
if (s_db2Driver == null) if (s_db2Driver == null)
{ {
s_db2Driver = new DB2Driver(); s_db2Driver = new DB2Driver();
DriverManager.registerDriver(s_db2Driver); DriverManager.registerDriver(s_db2Driver);
} }
m_con = DriverManager.getConnection(url, uid, pwd); m_con = DriverManager.getConnection(url, uid, pwd);
} }
catch (Exception e) catch (Exception e)
{ {
log.severe(e.toString()); log.warning(e.toString());
return false; return false;
} }
return true; return true;
} // testJDBC } // testJDBC
/** /**
* Test Command Line Connection * Test Command Line Connection
* @param sqlcmd sql command line * @param sqlcmd sql command line
* @return true if OK * @return true if OK
*/ */
private boolean testSQL (String sqlcmd) private boolean testSQL (String sqlcmd)
{ {
if (true) if (true)
return true; return true;
// //
StringBuffer sbOut = new StringBuffer(); StringBuffer sbOut = new StringBuffer();
StringBuffer sbErr = new StringBuffer(); StringBuffer sbErr = new StringBuffer();
int result = -1; int result = -1;
try try
{ {
Process p = Runtime.getRuntime().exec (sqlcmd); Process p = Runtime.getRuntime().exec (sqlcmd);
InputStream in = p.getInputStream(); InputStream in = p.getInputStream();
int c; int c;
while ((c = in.read()) != -1) while ((c = in.read()) != -1)
{ {
sbOut.append((char)c); sbOut.append((char)c);
System.out.print((char)c); System.out.print((char)c);
} }
in.close(); in.close();
in = p.getErrorStream(); in = p.getErrorStream();
while ((c = in.read()) != -1) while ((c = in.read()) != -1)
sbErr.append((char)c); sbErr.append((char)c);
in.close(); in.close();
// Get result // Get result
try try
{ {
Thread.yield(); Thread.yield();
result = p.exitValue(); result = p.exitValue();
} }
catch (Exception e) // Timing issue on Solaris. catch (Exception e) // Timing issue on Solaris.
{ {
Thread.sleep(200); // .2 sec Thread.sleep(200); // .2 sec
result = p.exitValue(); result = p.exitValue();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
log.severe(ex.toString()); log.warning(ex.toString());
} }
log.finer(sbOut.toString()); log.finer(sbOut.toString());
if (sbErr.length() > 0) if (sbErr.length() > 0)
log.warning(sbErr.toString()); log.warning(sbErr.toString());
return result == 0; return result == 0;
} // testSQL } // testSQL
} // ConfigDB2 } // ConfigDB2

View File

@ -1,466 +1,416 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.install; package org.compiere.install;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import java.util.regex.*; import java.util.regex.*;
import org.compiere.db.*; import org.compiere.db.*;
import oracle.jdbc.*; import oracle.jdbc.*;
/** /**
* Oracle Confguration * Oracle Confguration
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: ConfigOracle.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ * @version $Id: ConfigOracle.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $
*/ */
public class ConfigOracle extends Config public class ConfigOracle extends Config
{ {
/** /**
* ConfigOracle * ConfigOracle
* @param data configuration * @param data configuration
*/ * @param XE express edition
public ConfigOracle (ConfigurationData data) */
{ public ConfigOracle (ConfigurationData data, boolean XE)
super (data); {
} // ConfigOracle super (data);
m_XE = XE;
/** Oracle Driver */ } // ConfigOracle
private static OracleDriver s_oracleDriver = null;
/** Discovered TNS */ /** Oracle Driver */
private String[] p_discovered = null; private static OracleDriver s_oracleDriver = null;
/** Discovered Database Name */ /** Discoverd TNS */
private String[] p_dbname = null; private String[] p_discovered = null;
/** Last Connection */ /** Last Connection */
private Connection m_con = null; private Connection m_con = null;
/** Express Edition */
/** private boolean m_XE = false;
* Init
*/ /**
public void init() * Init
{ */
p_data.setDatabasePort(String.valueOf(DB_Oracle.DEFAULT_PORT)); public void init()
// {
p_data.setDatabaseSystemPassword(true); p_data.setDatabasePort(String.valueOf(DB_Oracle.DEFAULT_PORT));
} // init //
p_data.setDatabaseSystemPassword(true);
/** } // init
* Discover Databases.
* To be overwritten by database configs /**
* @param selected selected database * Discover Databases.
* @return array of databases * To be overwritten by database configs
*/ * @param selected selected database
public String[] discoverDatabases(String selected) * @return array of databases
{ */
if (p_discovered != null) public String[] discoverDatabases(String selected)
return p_discovered; {
// if (p_discovered != null)
ArrayList<String> list = new ArrayList<String>(); return p_discovered;
ArrayList<String> dblist = new ArrayList<String>(); //
// default value to lowercase or null ArrayList<String> list = new ArrayList<String>();
String def = selected; // default value to lowercase or null
if (def != null && def.trim().length() == 0) String def = selected;
def = null; if (def != null && def.trim().length() == 0)
if (def != null) { def = null;
list.add(def.toLowerCase()); if (def != null)
dblist.add(def.toLowerCase()); list.add(def.toLowerCase());
}
if (m_XE)
String path = System.getenv("ORACLE_HOME"); {
if (path == null) String serviceName = "xe";
{ if (!list.contains(serviceName))
// Search for Oracle Info list.add(serviceName);
path = System.getProperty("java.library.path"); }
String[] entries = path.split(File.pathSeparator); // Search for Oracle Info
for (int e = 0; e < entries.length; e++) String path = System.getProperty("java.library.path");
{ String[] entries = path.split(File.pathSeparator);
String entry = entries[e].toLowerCase(); for (int e = 0; e < entries.length; e++)
if (entry.indexOf("ora") != -1 && entry.endsWith("bin")) {
{ String entry = entries[e].toLowerCase();
StringBuffer sb = getTNS_File (entries[e].substring(0, entries[e].length()-4)); if (entry.indexOf("ora") != -1 && entry.endsWith("bin"))
String[] tnsnames = getTNS_Names (sb, true); {
String[] dbNames = getTNS_Names (sb, false); StringBuffer sb = getTNS_File (entries[e].substring(0, entries[e].length()-4));
if (tnsnames != null) String[] serviceNames = getTNS_Names (sb);
{ if (serviceNames != null)
for (int i = 0; i < tnsnames.length; i++) {
{ for (int i = 0; i < serviceNames.length; i++)
String tns = tnsnames[i]; // is lower case {
String db = dbNames[i]; String serviceName = serviceNames[i].toLowerCase();
if (!tns.equals(def)) { if (!list.contains(serviceName))
list.add(tns); list.add(serviceName);
dblist.add(db); }
} else { break;
dblist.remove(0); }
dblist.add(0, db); }
} } // for all path entries
}
break; p_discovered = new String[list.size()];
} list.toArray(p_discovered);
} return p_discovered;
} // for all path entries } // discoverDatabases
}
else /**
{ * Get File tnmsnames.ora in StringBuffer
StringBuffer sb = getTNS_File (path); * @param oraHome ORACLE_HOME
String[] tnsnames = getTNS_Names (sb, true); * @return tnsnames.ora or null
String[] dbNames = getTNS_Names (sb, false); */
if (tnsnames != null) private StringBuffer getTNS_File (String oraHome)
{ {
for (int i = 0; i < tnsnames.length; i++) String tnsnames = oraHome + File.separator
{ + "network" + File.separator
String tns = tnsnames[i]; // is lower case + "admin" + File.separator
String db = dbNames[i]; + "tnsnames.ora";
if (!tns.equals(def)) { File tnsfile = new File (tnsnames);
list.add(tns); if (!tnsfile.exists())
dblist.add(db); return null;
} else {
dblist.remove(0); log.fine(tnsnames);
dblist.add(0, db); StringBuffer sb = new StringBuffer();
} try
} {
} FileReader fr = new FileReader (tnsfile);
} int c;
while ((c = fr.read()) != -1)
p_discovered = new String[list.size()]; sb.append((char)c);
list.toArray(p_discovered); }
p_dbname = new String[dblist.size()]; catch (IOException ex)
dblist.toArray(p_dbname); {
return p_discovered; log.warning("Error Reading " + tnsnames);
} // discoverDatabases ex.printStackTrace();
return null;
}
@Override if (sb.length() == 0)
public String getDatabaseName(String nativeConnectioName) return null;
{ return sb;
int idx = -1; } // getTNS_File
if (p_discovered == null) return nativeConnectioName;
for (int i = 0; i < p_discovered.length; i++) /**
{ * Get TNS Names entries.
if (p_discovered[i].equals(nativeConnectioName)) * Assumes standard tnsmanes.ora formatting of NetMgr
{ * @param tnsnames content of tnsnames.ora
idx = i; * @return service names or null
break; */
} private String[] getTNS_Names (StringBuffer tnsnames)
} {
if (idx >= 0 if (tnsnames == null)
&& p_dbname != null return null;
&& idx < p_dbname.length)
return p_dbname[idx]; ArrayList<String> list = new ArrayList<String>();
else Pattern pattern = Pattern.compile("$", Pattern.MULTILINE);
return nativeConnectioName; String[] lines = pattern.split(tnsnames);
} for (int i = 0; i < lines.length; i++)
{
/** String line = lines[i].trim();
* Get File tnmsnames.ora in StringBuffer log.finest(i + ": " + line);
* @param oraHome ORACLE_HOME if (false) // get TNS Name
* @return tnsnames.ora or null {
*/ if (line.length() > 0
private StringBuffer getTNS_File (String oraHome) && Character.isLetter(line.charAt(0)) // no # (
{ && line.indexOf("=") != -1
String tnsnames = oraHome + File.separator && line.indexOf("EXTPROC_") == -1
+ "network" + File.separator && line.indexOf("_HTTP") == -1)
+ "admin" + File.separator {
+ "tnsnames.ora"; String entry = line.substring(0, line.indexOf('=')).trim().toLowerCase();
File tnsfile = new File (tnsnames); log.fine(entry);
if (!tnsfile.exists()) list.add(entry);
return null; }
}
log.fine(tnsnames); else // search service names
StringBuffer sb = new StringBuffer(); {
try if (line.length() > 0
{ && line.toUpperCase().indexOf("SERVICE_NAME") != -1)
FileReader fr = new FileReader (tnsfile); {
int c; String entry = line.substring(line.indexOf('=')+1).trim().toLowerCase();
while ((c = fr.read()) != -1) int index = entry.indexOf(')');
sb.append((char)c); if (index != 0)
} entry = entry.substring(0, index).trim();
catch (IOException ex) log.fine(entry);
{ list.add(entry);
log.severe("Error Reading " + tnsnames); }
ex.printStackTrace();
return null; }
} }
if (sb.length() == 0) // Convert to Array
return null; if (list.size() == 0)
return sb; return null;
} // getTNS_File String[] retValue = new String[list.size()];
list.toArray(retValue);
/** return retValue;
* Get TNS Names entries. } // getTNS_Names
* Assumes standard tnsmanes.ora formatting of NetMgr
* @param tnsnames content of tnsnames.ora
* @return tns names or null /**************************************************************************
*/ * Test
private String[] getTNS_Names (StringBuffer tnsnames, boolean tns) * @return error message or null if OK
{ */
if (tnsnames == null) public String test()
return null; {
// Database Server
ArrayList<String> list = new ArrayList<String>(); String server = p_data.getDatabaseServer();
Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); boolean pass = server != null && server.length() > 0
String[] lines = pattern.split(tnsnames); && server.toLowerCase().indexOf("localhost") == -1
for (int i = 0; i < lines.length; i++) && !server.equals("127.0.0.1");
{ String error = "Not correct: DB Server = " + server;
String line = lines[i].trim(); InetAddress databaseServer = null;
log.finest(i + ": " + line); try
if (tns) // get TNS Name {
{ if (pass)
if (line.length() > 0 databaseServer = InetAddress.getByName(server);
&& Character.isLetter(line.charAt(0)) // no # ( }
&& line.indexOf("=") != -1 catch (Exception e)
&& line.indexOf("EXTPROC_") == -1 {
&& line.indexOf("_HTTP") == -1) error += " - " + e.getMessage();
{ pass = false;
String entry = line.substring(0, line.indexOf('=')).trim().toLowerCase(); }
log.fine(entry); signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer",
list.add(entry); pass, true, error);
} log.info("OK: Database Server = " + databaseServer);
} setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName());
else // search service names setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, p_data.getDatabaseType());
{ setProperty(ConfigurationData.ADEMPIERE_DB_PATH, "oracle");
if (line.length() > 0
&& line.toUpperCase().indexOf("SERVICE_NAME") != -1) // Database Port
{ int databasePort = p_data.getDatabasePort();
String entry = line.substring(line.indexOf('=')+1).trim().toLowerCase(); pass = p_data.testPort (databaseServer, databasePort, true);
int index = entry.indexOf(')'); error = "DB Server Port = " + databasePort;
if (index != 0) signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort",
entry = entry.substring(0, index).trim(); pass, true, error);
log.fine(entry); if (!pass)
list.add(entry); return error;
} log.info("OK: Database Port = " + databasePort);
setProperty(ConfigurationData.ADEMPIERE_DB_PORT, String.valueOf(databasePort));
}
}
// Convert to Array // JDBC Database Info
if (list.size() == 0) String databaseName = p_data.getDatabaseName(); // Service Name
return null; String systemPassword = p_data.getDatabaseSystemPassword();
String[] retValue = new String[list.size()]; pass = systemPassword != null && systemPassword.length() > 0;
list.toArray(retValue); error = "No Database System Password entered";
return retValue; signalOK(getPanel().okDatabaseSystem, "ErrorJDBC",
} // getTNS_Names pass, true, error);
if (!pass)
return error;
/************************************************************************** //
* Test // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1
* @return error message or null if OK String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName()
*/ + ":" + databasePort
public String test() + "/" + databaseName;
{ pass = testJDBC(url, "system", systemPassword);
// Database Server error = "Error connecting: " + url
String server = p_data.getDatabaseServer(); + " - as system/" + systemPassword;
boolean pass = server != null && server.length() > 0 signalOK(getPanel().okDatabaseSystem, "ErrorJDBC",
&& server.toLowerCase().indexOf("localhost") == -1 pass, true, error);
&& !server.equals("127.0.0.1"); if (!pass)
String error = "Not correct: DB Server = " + server; return error;
InetAddress databaseServer = null; log.info("OK: Connection = " + url);
try setProperty(ConfigurationData.ADEMPIERE_DB_URL, url);
{ log.info("OK: Database System User " + databaseName);
if (pass) setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName);
databaseServer = InetAddress.getByName(server); setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword);
}
catch (Exception e)
{ // Database User Info
error += " - " + e.getMessage(); String databaseUser = p_data.getDatabaseUser(); // UID
pass = false; String databasePassword = p_data.getDatabasePassword(); // PWD
} pass = databasePassword != null && databasePassword.length() > 0;
signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer", error = "Invalid Database User Password";
pass, true, error); signalOK(getPanel().okDatabaseUser, "ErrorJDBC",
log.info("OK: Database Server = " + databaseServer); pass, true, error);
setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName()); if (!pass)
setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, p_data.getDatabaseType()); return error;
// Ignore result as it might not be imported
// Database Port pass = testJDBC(url, databaseUser, databasePassword);
int databasePort = p_data.getDatabasePort(); error = "Cannot connect to User: " + databaseUser + "/" + databasePassword + " - Database may not be imported yet (OK on initial run).";
pass = p_data.testPort (databaseServer, databasePort, true); signalOK(getPanel().okDatabaseUser, "ErrorJDBC",
error = "DB Server Port = " + databasePort; pass, false, error);
signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", if (pass)
pass, true, error); {
if (!pass) log.info("OK: Database User = " + databaseUser);
return error; if (m_con != null)
log.info("OK: Database Port = " + databasePort); setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, getWebStores(m_con));
setProperty(ConfigurationData.ADEMPIERE_DB_PORT, String.valueOf(databasePort)); }
else
log.warning(error);
// JDBC Database Info setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser);
String databaseName = p_data.getDatabaseName(); // Service Name setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword);
String systemPassword = p_data.getDatabaseSystemPassword();
pass = systemPassword != null && systemPassword.length() > 0; // TNS Name Info via sqlplus - if not tomcat
error = "No Database System Password entered"; if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT))
signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", {
pass, true, error); String sqlplus = "sqlplus system/" + systemPassword + "@" + databaseName
if (!pass) + " @" + getProperty(ConfigurationData.ADEMPIERE_HOME)
return error; + "/utils/oracle/Test.sql";
// log.config(sqlplus);
// URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 pass = testSQL(sqlplus);
String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName() error = "Error connecting via: " + sqlplus;
+ ":" + databasePort signalOK(getPanel().okDatabaseSQL, "ErrorTNS",
+ "/" + databaseName; pass, true, error);
pass = testJDBC(url, "system", systemPassword); if (pass)
error = "Error connecting: " + url log.info("OK: Database SQL Connection");
+ " - as system/" + systemPassword; }
signalOK(getPanel().okDatabaseSystem, "ErrorJDBC",
pass, true, error); // OCI Test
if (!pass) if (System.getProperty("TestOCI", "N").equals("Y"))
return error; {
log.info("OK: Connection = " + url); url = "jdbc:oracle:oci8:@" + databaseName;
setProperty(ConfigurationData.ADEMPIERE_DB_URL, url); pass = testJDBC(url, "system", systemPassword);
log.info("OK: Database System User " + databaseName); if (pass)
setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName); log.info("OK: Connection = " + url);
setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword); else
log.warning("Cannot connect via Net8: " + url);
}
// Database User Info log.info("OCI Test Skipped");
String databaseUser = p_data.getDatabaseUser(); // UID
String databasePassword = p_data.getDatabasePassword(); // PWD //
pass = databasePassword != null && databasePassword.length() > 0; m_con = null;
error = "Invalid Database User Password"; return null;
signalOK(getPanel().okDatabaseUser, "ErrorJDBC", } // test
pass, true, error);
if (!pass)
return error; /**
// Ignore result as it might not be imported * Test JDBC Connection to Server
pass = testJDBC(url, databaseUser, databasePassword); * @param url connection string
error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword; * @param uid user id
signalOK(getPanel().okDatabaseUser, "ErrorJDBC", * @param pwd password
pass, false, error); * @return true if OK
if (pass) */
{ private boolean testJDBC (String url, String uid, String pwd)
log.info("OK: Database User = " + databaseUser); {
if (m_con != null) log.fine("Url=" + url + ", UID=" + uid);
setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, getWebStores(m_con)); try
} {
else if (s_oracleDriver == null)
log.warning(error); {
setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser); s_oracleDriver = new OracleDriver();
setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword); DriverManager.registerDriver(s_oracleDriver);
}
// TNS Name Info via sqlplus - if not tomcat m_con = DriverManager.getConnection(url, uid, pwd);
if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT)) }
{ catch (UnsatisfiedLinkError ule)
String sqlplus = "sqlplus system/" + systemPassword + "@" {
+ databaseServer.getHostName() + "/" + databaseName log.warning("Check [ORACLE_HOME]/jdbc/Readme.txt for (OCI) driver setup");
+ " @utils/oracle/Test.sql"; log.warning(ule.toString());
log.config(sqlplus); }
pass = testSQL(sqlplus); catch (Exception e)
error = "Error connecting via: " + sqlplus; {
signalOK(getPanel().okDatabaseSQL, "ErrorTNS", log.warning(e.toString());
pass, true, error); return false;
if (pass) }
log.info("OK: Database SQL Connection"); return true;
} } // testJDBC
// OCI Test /**
if (System.getProperty("TestOCI", "N").equals("Y")) * Test TNS Connection
{ * @param sqlplus sqlplus command line
url = "jdbc:oracle:oci8:@" + databaseName; * @return true if OK
pass = testJDBC(url, "system", systemPassword); */
if (pass) private boolean testSQL (String sqlplus)
log.info("OK: Connection = " + url); {
else StringBuffer sbOut = new StringBuffer();
log.warning("Cannot connect via Net8: " + url); StringBuffer sbErr = new StringBuffer();
} int result = -1;
log.info("OCI Test Skipped"); try
{
// Process p = Runtime.getRuntime().exec (sqlplus);
m_con = null; InputStream in = p.getInputStream();
return null; int c;
} // test while ((c = in.read()) != -1)
{
sbOut.append((char)c);
/** System.out.print((char)c);
* Test JDBC Connection to Server }
* @param url connection string in.close();
* @param uid user id in = p.getErrorStream();
* @param pwd password while ((c = in.read()) != -1)
* @return true if OK sbErr.append((char)c);
*/ in.close();
private boolean testJDBC (String url, String uid, String pwd) // Get result
{ try
log.fine("Url=" + url + ", UID=" + uid); {
try Thread.yield();
{ result = p.exitValue();
if (s_oracleDriver == null) }
{ catch (Exception e) // Timing issue on Solaris.
s_oracleDriver = new OracleDriver(); {
DriverManager.registerDriver(s_oracleDriver); Thread.sleep(200); // .2 sec
} result = p.exitValue();
m_con = DriverManager.getConnection(url, uid, pwd); }
} }
catch (UnsatisfiedLinkError ule) catch (Exception ex)
{ {
log.warning("Check [ORACLE_HOME]/jdbc/Readme.txt for (OCI) driver setup"); log.warning(ex.toString());
log.warning(ule.toString()); }
} log.finer(sbOut.toString());
catch (Exception e) if (sbErr.length() > 0)
{ log.warning(sbErr.toString());
log.severe(e.toString()); return result == 0;
return false; } // testSQL
}
return true; } // ConfigOracle
} // testJDBC
/**
* Test TNS Connection
* @param sqlplus sqlplus command line
* @return true if OK
*/
private boolean testSQL (String sqlplus)
{
StringBuffer sbOut = new StringBuffer();
StringBuffer sbErr = new StringBuffer();
int result = -1;
try
{
Process p = Runtime.getRuntime().exec (sqlplus);
InputStream in = p.getInputStream();
int c;
while ((c = in.read()) != -1)
{
sbOut.append((char)c);
System.out.print((char)c);
}
in.close();
in = p.getErrorStream();
while ((c = in.read()) != -1)
sbErr.append((char)c);
in.close();
// Get result
try
{
Thread.yield();
result = p.exitValue();
}
catch (Exception e) // Timing issue on Solaris.
{
Thread.sleep(200); // .2 sec
result = p.exitValue();
}
}
catch (Exception ex)
{
log.severe(ex.toString());
}
log.finer(sbOut.toString());
if (sbErr.length() > 0)
log.warning(sbErr.toString());
return result == 0;
} // testSQL
} // ConfigOracle

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,426 +1,433 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.install; package org.compiere.install;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.security.*; import java.security.*;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import javax.swing.*; import javax.swing.*;
import org.compiere.*; import org.compiere.*;
import org.compiere.util.*; import org.compiere.util.*;
import sun.security.tools.*; import sun.security.tools.*;
/** /**
* Class to manage SSL KeyStore * Class to manage SSL KeyStore
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: KeyStoreMgt.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ * @version $Id: KeyStoreMgt.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $
*/ */
public class KeyStoreMgt public class KeyStoreMgt
{ {
/** /**
* Constructor. * Constructor.
* @param fileName key store file name * @param fileName key store file name
* @param password - same password for key store and certificate * @param password - same password for key store and certificate
*/ */
public KeyStoreMgt (String fileName, char[] password) public KeyStoreMgt (String fileName, char[] password)
{ {
log.info(fileName); log.info(fileName);
m_file = new File (fileName); m_file = new File (fileName);
m_password = password; m_password = password;
} // KeyStoreMgt } // KeyStoreMgt
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(KeyStoreMgt.class); private static CLogger log = CLogger.getCLogger(KeyStoreMgt.class);
/** KeyStore File */ /** KeyStore File */
private File m_file = null; private File m_file = null;
/** KeyStore Password */ /** KeyStore Password */
private char[] m_password = null; private char[] m_password = null;
/** KeyStore */ /** KeyStore */
private KeyStore m_keyStore = null; private KeyStore m_keyStore = null;
/** Directory below ADEMPIERE_HOME */ /** Directory below ADEMPIERE_HOME */
public static String KEYSTORE_DIRECTORY = "keystore"; public static String KEYSTORE_DIRECTORY = "keystore";
/** Name of KeyStore */ /** Name of KeyStore */
public static String KEYSTORE_NAME = "myKeystore"; public static String KEYSTORE_NAME = "myKeystore";
/** Certificate Alias */ /** Certificate Alias */
public static String CERTIFICATE_ALIAS = "adempiere"; public static String CERTIFICATE_ALIAS = "adempiere";
/** /**
* Verify/Create Key Store * Verify/Create Key Store
* @param parent frame * @param parent frame
* @return null or error message * @return null or error message
*/ */
public String verify (JFrame parent) public String verify (JFrame parent)
{ {
KeyStore ks = null; KeyStore ks = null;
try try
{ {
ks = getKeyStore(); ks = getKeyStore();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "get KeyStore", e); log.log(Level.SEVERE, "get KeyStore", e);
return e.getMessage(); return e.getMessage();
} }
// No KeyStore // No KeyStore
if (ks == null) if (ks == null)
{ {
createCertificate(CERTIFICATE_ALIAS, parent); createCertificate(CERTIFICATE_ALIAS, parent);
try try
{ {
ks = getKeyStore(); ks = getKeyStore();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "new KeyStore", e); log.log(Level.SEVERE, "new KeyStore", e);
return e.getMessage(); return e.getMessage();
} }
} // new key store } // new key store
// No KeyStore // No KeyStore
if (ks == null) if (ks == null)
return "No Key Store"; return "No Key Store";
// Verify Certificate // Verify Certificate
Certificate cert = null; Certificate cert = null;
try try
{ {
cert = getCertificate(CERTIFICATE_ALIAS); cert = getCertificate(CERTIFICATE_ALIAS);
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "certificate", e); log.log(Level.SEVERE, "certificate", e);
return e.getMessage(); return e.getMessage();
} }
if (cert == null) if (cert == null)
return "No Certificate found"; return "No Certificate found";
return null; // OK return null; // OK
} // verify } // verify
/** /**
* Get KeyStore * Get KeyStore
* @return KeyStore or null * @return KeyStore or null
* @throws Exception * @throws Exception
*/ */
public KeyStore getKeyStore() throws Exception public KeyStore getKeyStore() throws Exception
{ {
try try
{ {
m_keyStore = KeyStore.getInstance("JKS"); m_keyStore = KeyStore.getInstance("JKS");
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "Instance", e); log.log(Level.SEVERE, "Instance", e);
} }
// Load Existing // Load Existing
if (m_file.exists()) if (m_file.exists())
{ {
log.fine(m_file.toString()); log.fine(m_file.toString());
InputStream is = null; InputStream is = null;
try try
{ {
is = new FileInputStream (m_file); is = new FileInputStream (m_file);
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "load", e); log.log(Level.SEVERE, "load", e);
return null; return null;
} }
m_keyStore.load(is, m_password); m_keyStore.load(is, m_password);
} }
else else
return null; // does not exist return null; // does not exist
// //
log.fine("Provider=" + m_keyStore.getProvider() log.fine("Provider=" + m_keyStore.getProvider()
+ " - Type=" + m_keyStore.getType()); + " - Type=" + m_keyStore.getType());
// //
return m_keyStore; return m_keyStore;
} // getKeyStore } // getKeyStore
/** /**
* Get Certificate * Get Certificate
* @param alias alias * @param alias alias
* @return certificate or null * @return certificate or null
* @throws Exception * @throws Exception
*/ */
public Certificate getCertificate (String alias) throws Exception public Certificate getCertificate (String alias) throws Exception
{ {
log.config("Alias=" + alias); log.config("Alias=" + alias);
Date date = m_keyStore.getCreationDate(alias); Date date = m_keyStore.getCreationDate(alias);
if (date == null) // no certificate if (date == null) // no certificate
return null; return null;
log.fine("Created=" + date); log.fine("Created=" + date);
// //
Key key = m_keyStore.getKey(alias, m_password); Key key = m_keyStore.getKey(alias, m_password);
if (CLogMgt.isLevelFinest()) if (CLogMgt.isLevelFinest())
log.info("Key=" + key); // Multiple lines log.info("Key=" + key); // Multiple lines
else else
log.fine(key.getAlgorithm()); log.fine(key.getAlgorithm());
// //
Certificate cert = m_keyStore.getCertificate(alias); Certificate cert = m_keyStore.getCertificate(alias);
if (CLogMgt.isLevelFinest()) if (CLogMgt.isLevelFinest())
log.info("Certificate = " + cert); // Multiple lines log.info("Certificate = " + cert); // Multiple lines
else else
log.fine(cert.getType()); log.fine(cert.getType());
// log.fine("Certificate - Type=" + cert.getType() // log.fine("Certificate - Type=" + cert.getType()
// + " - PublicKey=" + cert.getPublicKey()); // + " - PublicKey=" + cert.getPublicKey());
return cert; return cert;
} // getCertificate } // getCertificate
/************************************************************************** /**************************************************************************
* Create Certificate * Create Certificate
* @param alias alias * @param alias alias
* @param parent interactive dialog * @param parent interactive dialog
*/ */
private void createCertificate (String alias, JFrame parent) private void createCertificate (String alias, JFrame parent)
{ {
log.info(""); log.info("");
try try
{ {
File dir = m_file.getParentFile(); File dir = m_file.getParentFile();
if (!dir.exists()) if (!dir.exists())
dir.mkdir(); dir.mkdir();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "directory", e); log.log(Level.SEVERE, "directory", e);
} }
String dname = getDname(parent); String dname = getDname(parent);
if (dname == null) if (dname == null)
return; return;
// //
try try
{ {
genkey (alias, m_password, m_file.getAbsolutePath(), dname); genkey (alias, m_password, m_file.getAbsolutePath(), dname);
selfcert (alias, m_password, m_file.getAbsolutePath(), dname); selfcert (alias, m_password, m_file.getAbsolutePath(), dname);
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "certificate", e); log.log(Level.SEVERE, "certificate", e);
} }
} // createCertificate } // createCertificate
/** /**
* Get Distinguised Name * Get Distinguised Name
* @param parent interactive dialog * @param parent interactive dialog
* @return dname or null * @return dname or null
*/ */
public static String getDname(JFrame parent) public static String getDname(JFrame parent)
{ {
String cn = null; String cn = null;
try try
{ {
InetAddress address = InetAddress.getLocalHost(); InetAddress address = InetAddress.getLocalHost();
cn = address.getCanonicalHostName(); cn = address.getCanonicalHostName();
} }
catch (Exception e) catch (Exception e)
{ {
} }
String ou = System.getProperty("user.name"); String ou = System.getProperty("user.name");
String o = "AdempiereUser"; String o = "AdempiereUser";
String l = "MyTown"; String l = "MyTown";
String s = ""; String s = "";
String c = System.getProperty("user.country"); String c = System.getProperty("user.country");
// //
if (parent != null) if (parent != null)
{ {
KeyStoreDialog skd = new KeyStoreDialog(parent, KeyStoreDialog skd = new KeyStoreDialog(parent,
cn, ou, o, l, s, c); cn, ou, o, l, s, c);
if (!skd.isOK()) if (!skd.isOK())
return null; return null;
cn = skd.getCN(); cn = skd.getCN();
ou = skd.getOU(); ou = skd.getOU();
o = skd.getO(); o = skd.getO();
l = skd.getL(); l = skd.getL();
s = skd.getS(); s = skd.getS();
c = skd.getC(); c = skd.getC();
} }
// //
if (cn == null || cn.length() == 0) if (cn == null || cn.length() == 0)
{ {
log.severe("No Common Name (CN)"); log.warning("No Common Name (CN)");
return null; return null;
} }
if (ou == null || ou.length() == 0) if (ou == null || ou.length() == 0)
{ {
log.severe("No Organization Unit (OU)"); log.warning("No Organization Unit (OU)");
return null; return null;
} }
if (o == null || o.length() == 0) if (o == null || o.length() == 0)
{ {
log.severe("No Organization (O)"); log.warning("No Organization (O)");
return null; return null;
} }
if (c == null || c.length() == 0) if (c == null || c.length() == 0)
{ {
log.severe("No Country (C)"); log.warning("No Country (C)");
return null; return null;
} }
// Escape commas // Escape commas
StringBuffer dname = new StringBuffer(); StringBuffer dname = new StringBuffer();
dname.append("CN=").append(escapeCommas(cn)); // common name dname.append("CN=").append(escapeCommas(cn)); // common name
dname.append(", OU=").append(escapeCommas(ou)); // org unit dname.append(", OU=").append(escapeCommas(ou)); // org unit
dname.append(", O=").append(escapeCommas(o)); // org dname.append(", O=").append(escapeCommas(o)); // org
if (l != null && l.length() > 0) if (l != null && l.length() > 0)
dname.append(", L=").append(escapeCommas(l)); // locality dname.append(", L=").append(escapeCommas(l)); // locality
if (s != null && s.length() > 0) if (s != null && s.length() > 0)
dname.append(", S=").append(escapeCommas(s)); // state dname.append(", S=").append(escapeCommas(s)); // state
dname.append(", C=").append(escapeCommas(c)); // country dname.append(", C=").append(escapeCommas(c)); // country
return dname.toString(); return dname.toString();
} // getDname } // getDname
/** /**
* Escape Commas * Escape Commas
* @param in input string * @param in input string
* @return excaped string * @return excaped string
*/ */
public static String escapeCommas(String in) public static String escapeCommas(String in)
{ {
if (in == null || in.indexOf(",") == -1) if (in == null || in.indexOf(",") == -1)
return in; return in;
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
char[] chars = in.toCharArray(); char[] chars = in.toCharArray();
for (int i = 0; i < chars.length; i++) for (int i = 0; i < chars.length; i++)
{ {
if (chars[i] == ',') if (chars[i] == ',')
out.append('\\').append(','); out.append('\\').append(',');
else else
out.append(chars[i]); out.append(chars[i]);
} }
return out.toString(); return out.toString();
} // escapeCommas } // escapeCommas
/** /**
* Generate Key * Generate Key
* @param alias adempiere * @param alias adempiere
* @param password password * @param password password
* @param fileName key store file name (may have spaces) * @param fileName key store file name (may have spaces)
* @param dname distinguished name * @param dname distinguished name
*/ */
public static void genkey (String alias, char[] password, String fileName, String dname) public static void genkey (String alias, char[] password, String fileName, String dname)
{ {
StringBuffer cmd = new StringBuffer ("-genkey -keyalg rsa"); StringBuffer cmd = new StringBuffer ("-genkey -keyalg rsa");
cmd.append(" -alias ").append(alias); cmd.append(" -alias ").append(alias);
cmd.append(" -dname \"").append(dname).append("\""); cmd.append(" -dname \"").append(dname).append("\"");
cmd.append(" -keypass ").append(password).append(" -validity 365"); cmd.append(" -keypass ").append(password).append(" -validity 365");
if (fileName.indexOf(' ') != -1) if (fileName.indexOf(' ') != -1)
cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password);
else else
cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password);
keytool (cmd.toString()); keytool (cmd.toString());
} // genkey } // genkey
/** /**
* Generate Key * Generate Key
* @param alias adempiere * @param alias adempiere
* @param password password * @param password password
* @param fileName key store file name (may have spaces) * @param fileName key store file name (may have spaces)
* @param dname distinguished name * @param dname distinguished name
*/ */
public static void selfcert (String alias, char[] password, String fileName, String dname) public static void selfcert (String alias, char[] password, String fileName, String dname)
{ {
StringBuffer cmd = new StringBuffer ("-selfcert"); StringBuffer cmd = new StringBuffer ("-selfcert");
cmd.append(" -alias ").append(alias); cmd.append(" -alias ").append(alias);
cmd.append(" -dname \"").append(dname).append("\""); cmd.append(" -dname \"").append(dname).append("\"");
cmd.append(" -keypass ").append(password).append(" -validity 180"); cmd.append(" -keypass ").append(password).append(" -validity 180");
if (fileName.indexOf(' ') != -1) if (fileName.indexOf(' ') != -1)
cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password);
else else
cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password);
keytool (cmd.toString()); keytool (cmd.toString());
} // selfcert } // selfcert
/** /**
* Submit Command to Key Tool * Submit Command to Key Tool
* @param cmd command * @param cmd command
*/ */
public static void keytool(String cmd) public static void keytool(String cmd)
{ {
log.info("keytool " + cmd); log.info("keytool " + cmd);
ArrayList<String> list = new ArrayList<String>(); ArrayList<String> list = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(cmd, " "); StringTokenizer st = new StringTokenizer(cmd, " ");
String quoteBuffer = null; String quoteBuffer = null;
while (st.hasMoreTokens()) while (st.hasMoreTokens())
{ {
String token = st.nextToken(); String token = st.nextToken();
// System.out.println("= " + token + " = quoteBuffer=" + quoteBuffer + " - Size=" + list.size() ); // System.out.println("= " + token + " = quoteBuffer=" + quoteBuffer + " - Size=" + list.size() );
if (quoteBuffer == null) if (quoteBuffer == null)
{ {
if (token.startsWith("\"")) if (token.startsWith("\""))
quoteBuffer = token.substring(1); quoteBuffer = token.substring(1);
else else
list.add(token); list.add(token);
} }
else else
quoteBuffer += " " + token; quoteBuffer += " " + token;
if (token.endsWith("\"")) if (token.endsWith("\""))
{ {
String str = quoteBuffer.substring(0, quoteBuffer.length()-1); String str = quoteBuffer.substring(0, quoteBuffer.length()-1);
// System.out.println(" Buffer= " + str ); // System.out.println(" Buffer= " + str );
list.add(str); list.add(str);
quoteBuffer = null; quoteBuffer = null;
} }
} // all tokens } // all tokens
// //
String[] args = new String[list.size()]; String[] args = new String[list.size()];
list.toArray(args); list.toArray(args);
// System.out.println(" args #" + args.length); // System.out.println(" args #" + args.length);
KeyTool.main(args); //vpj-cd add support java 6
} // ketyool try
{
/** KeyTool.main(args);
* Get Keystore File Name }
* @param baseDir ADEMPIERE_HOME catch (Exception e)
* @return file name {
*/ }
public static String getKeystoreFileName (String baseDir) } // ketyool
{
String fileName = baseDir; /**
if (fileName == null) * Get Keystore File Name
fileName = ""; * @param baseDir ADEMPIERE_HOME
else if (!fileName.endsWith(File.separator)) * @return file name
fileName += File.separator; */
fileName += KEYSTORE_DIRECTORY + File.separator + KEYSTORE_NAME; public static String getKeystoreFileName (String baseDir)
return fileName; {
} // getKeystoreFileName String fileName = baseDir;
if (fileName == null)
fileName = "";
/************************************************************************** else if (!fileName.endsWith(File.separator))
* Test fileName += File.separator;
* @param args ignored fileName += KEYSTORE_DIRECTORY + File.separator + KEYSTORE_NAME;
*/ return fileName;
public static void main (String[] args) } // getKeystoreFileName
{
Adempiere.startupEnvironment(true);
System.out.println(new KeyStoreMgt ( /**************************************************************************
"C:/Adempiere/keystore/myKeystore2", "myPassword".toCharArray()).verify(null)); * Test
} // main * @param args ignored
*/
} // MyKeyStore public static void main (String[] args)
{
Adempiere.startupEnvironment(true);
System.out.println(new KeyStoreMgt (
"C:/Adempiere/keystore/myKeystore2", "myPassword".toCharArray()).verify(null));
} // main
} // MyKeyStore