The Windows ATS Install has been updated to not perform the configuration step as part of the MSI install process.

This commit is contained in:
Juan Carlos Luciani
2007-04-12 17:38:29 +00:00
parent 05fd9550b5
commit dee103c988
49 changed files with 2069 additions and 6195 deletions

View File

@@ -0,0 +1,575 @@
/***********************************************************************
*
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
* Author: Juan Carlos Luciani <jluciani@novell.com>
*
***********************************************************************/
import java.util.Properties;
import java.util.Enumeration;
import java.io.*;
/**
*
* Class for configuring and unconfiguring an ATS under windows.
*
*/
public final class AtsConfigurator
{
private static final String usage =
"usage: AtsConfigurator -op -file propertiesFilePath [-logfolder logFolderPath]\n\n" +
" where:\n" +
" -op - Corresponds to one of the following operations:\n" +
" -c - Configure the ATS installation.\n" +
" -u - Unconfigure the ATS installation.\n" +
" -file - Path to the properties file\n" +
" -logfolder - Path to the log folder\n" +
" The following properties must be present in the file:\n" +
" ATS_INSTALL_DIR - The location of the ATS Install Directory.\n" +
" COMPUTERNAME - The computer name.\n" +
" ATS_JAVA_HOME - Java home.\n" +
" TOMCAT_HOME - Tomcat install base directory.\n" +
" HOSTNAME - Name of the host.\n" +
" TOMCAT5 - Location of the tomcat5 executable.\n";
// Error codes
final static int ERROR_NO_ERROR = 0;
final static int ERROR_EXEC_FAILED = -1;
final static int ERROR_INVALID_ARGUMENT = -2;
final static int ERROR_MISSING_INSTALL_DIR = -4;
final static int ERROR_INSTALL_DIR_NOT_A_DIR = -5;
final static int ERROR_MISSING_PROPERTIES_FILE = -7;
final static int ERROR_UNABLE_TO_READ_PROPERTIES = -8;
final static int ERROR_REQUIRED_PROPERTY_MISSING = -11;
final static int ERROR_EXEC_INTERRUPTED = -12;
final static int ERROR_IO_EXCEPTION = -13;
final static int ERROR_EXCEPTION = -14;
final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -15;
final static int ERROR_FILEWRITER_CREATE_FAILED = -16;
final static int ERROR_OUTPUT_COPY_FAILED = -17;
final static int ERROR_JAR_COPY_FAILED = -18;
final static int ERROR_ADD_FILE_TO_JAR_FAILED = -19;
final static int ERROR_WAR_TEMPLATE_FILE_MISSING = -20;
final static int ERROR_NEW_JAR_CANNOT_BE_REPLACED = -21;
final static int ERROR_CREATE_WAR_FOS_FAILED = -22;
final static int ERROR_OPEN_JAR_TEMPLATE_FAILED = -23;
final static int ERROR_JOS_FLUSH_FAILED = -24;
final static int ERROR_JOS_CLOSE_FAILED = -25;
final static int ERROR_FOS_CLOSE_FAILED = -26;
final static int ERROR_JFTEMPLATE_CLOSE_FAILED = -27;
// Required properties
final static String INSTALL_DIR_PROPERTY = "ATS_INSTALL_DIR";
final static String COMPUTERNAME_PROPERTY = "COMPUTERNAME";
final static String TOMCAT_HOME_PROPERTY = "TOMCAT_HOME";
final static String JAVA_HOME_PROPERTY = "ATS_JAVA_HOME";
final static String HOSTNAME_PROPERTY = "HOSTNAME";
final static String[] m_requiredProperties = {
INSTALL_DIR_PROPERTY,
COMPUTERNAME_PROPERTY,
TOMCAT_HOME_PROPERTY,
JAVA_HOME_PROPERTY,
HOSTNAME_PROPERTY};
// Other constants
final static String LOG_FILE_NAME = "AtsConfigurator.log";
// Configured properties
static Properties m_properties = null;
// InstallLog variables
static String m_logFolderPath = "\\temp";
static File m_logFile = null;
static FileWriter m_logFileWriter = null;
/**
* Invoke external command.
*
* @param commandArray Array of command parameters.
* @return Return code.
*/
static int invokeExternalCommand(String[] commandArray)
{
int rc;
log("AtsConfigurator.invokeExternalCommand()- Start");
try
{
Process p = Runtime.getRuntime().exec(commandArray);
try
{
int r = p.waitFor();
if (r == 0)
{
rc = ERROR_NO_ERROR;
}
else
{
log("Command " + commandArray[0] + " returned status: " + r);
rc = ERROR_EXEC_FAILED;
}
}
catch (InterruptedException ie)
{
rc = ERROR_EXEC_INTERRUPTED;
}
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_EXEC_FAILED;
}
log("AtsConfigurator.invokeExternalCommand()- End, rc= ", rc);
return rc;
}
/**
* Try to fill in missing properties from system properties.
*/
static void tryToFillInMissingProperties()
{
log("AtsConfigurator.tryToFillInMissingProperties()- Start");
for (int i = 0; i < m_requiredProperties.length; i++)
{
String propertyKey = m_requiredProperties[i];
if (!m_properties.containsKey(propertyKey))
{
AtsConfigurator.log("Trying to fill in property: " + propertyKey);
String propertyValue = System.getProperty(propertyKey);
if (propertyValue != null)
{
log(" Filling in property using system property value: " + propertyValue);
m_properties.put(propertyKey, propertyValue);
}
else
{
log(" Unable to fill in property " + propertyKey);
}
}
}
log("AtsConfigurator.tryToFillInMissingProperties()- End");
}
/**
* Verify that the properties required have been specified.
*
* @return Return code.
*/
static int verifyRequiredPropertiesSpecified()
{
int rc = ERROR_NO_ERROR;
log("AtsConfigurator.verifyRequiredPropertiesSpecified()- Start");
for (int i = 0; i < m_requiredProperties.length; i++)
{
if (!m_properties.containsKey(m_requiredProperties[i]))
{
log("Required property " + m_requiredProperties[i] + " missing");
rc = ERROR_REQUIRED_PROPERTY_MISSING;
break;
}
}
log("AtsConfigurator.verifyRequiredPropertiesSpecified()- End, rc= ", rc);
return rc;
}
/**
* Process properties.
*
* @return Return code.
*/
static int processProperties(String configFilePath)
{
int rc = ERROR_NO_ERROR;
log("AtsConfigurator.processProperties()- Start");
// Obtain configuration properties from config file
InputStream in = null;
try
{
File fileProperties = new File(configFilePath);
// Make sure the properties file can be found
if (!fileProperties.exists())
{
rc = ERROR_MISSING_PROPERTIES_FILE;
}
else
{
// Read the properties from the file
in = new FileInputStream(fileProperties);
m_properties = new Properties();
m_properties.load(in);
}
}
catch (Exception e)
{
rc = ERROR_UNABLE_TO_READ_PROPERTIES;
}
finally
{
try
{
if (in != null)
in.close();
}
catch (Exception e)
{
// Do nothing
}
}
// Continue if no errors detected
if (rc == ERROR_NO_ERROR)
{
tryToFillInMissingProperties();
// Log the properties obtained
Enumeration e = m_properties.propertyNames();
while (e.hasMoreElements())
{
String key = (String) e.nextElement();
String value = (String) m_properties.get(key);
AtsConfigurator.log("Property " + key + " = " + value);
}
// Validate that we have the required properties
if (ERROR_NO_ERROR == (rc = verifyRequiredPropertiesSpecified()))
{
// Verify that the install directory specified exists
File fileInstallDir = new File((String) m_properties.get(INSTALL_DIR_PROPERTY));
// Make sure the install dir can be found
if (!fileInstallDir.exists())
{
rc = ERROR_MISSING_INSTALL_DIR;
}
else
{
// Make sure the install dir is a directory
if (!fileInstallDir.isDirectory())
{
rc = ERROR_INSTALL_DIR_NOT_A_DIR;
}
}
}
}
log("AtsConfigurator.processProperties()- End, rc= ", rc);
return rc;
}
/**
* Log error code.
*
* @param err Error code.
*/
static void log(int err)
{
log(null, err);
}
/**
* Log string with error code.
*
* @param s Log string.
* @param err Error code.
*/
static void log(String s, int err)
{
String rcMessage;
switch (err)
{
case ERROR_NO_ERROR:
rcMessage = "No error";
break;
case ERROR_EXEC_FAILED:
rcMessage = "Execute command failed";
break;
case ERROR_MISSING_INSTALL_DIR:
rcMessage = "Missing install dir";
break;
case ERROR_INSTALL_DIR_NOT_A_DIR:
rcMessage = "Install dir is not a dir";
break;
case ERROR_MISSING_PROPERTIES_FILE:
rcMessage = "Property file not found";
break;
case ERROR_UNABLE_TO_READ_PROPERTIES:
rcMessage = "Unable to read property file";
break;
case ERROR_REQUIRED_PROPERTY_MISSING:
rcMessage = "Required property is missing";
break;
case ERROR_EXEC_INTERRUPTED:
rcMessage = "Execution interrupted";
break;
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
rcMessage = "Unable to open template file";
break;
case ERROR_FILEWRITER_CREATE_FAILED:
rcMessage = "FileWriter create failed";
break;
case ERROR_OUTPUT_COPY_FAILED:
rcMessage = "Output copy failed";
break;
case ERROR_IO_EXCEPTION:
rcMessage = "IO Exception";
break;
case ERROR_JAR_COPY_FAILED:
rcMessage = "Failed to copy Jar";
break;
case ERROR_ADD_FILE_TO_JAR_FAILED:
rcMessage = "Failed to add file to Jar";
break;
case ERROR_WAR_TEMPLATE_FILE_MISSING:
rcMessage = "Template War file missing";
break;
case ERROR_NEW_JAR_CANNOT_BE_REPLACED:
rcMessage = "Cannot create new Jar";
break;
case ERROR_CREATE_WAR_FOS_FAILED:
rcMessage = "Failed to create War File Output Stream";
break;
case ERROR_OPEN_JAR_TEMPLATE_FAILED:
rcMessage = "Failed to open Template War file";
break;
case ERROR_JOS_FLUSH_FAILED:
rcMessage = "Jar Output Stream Flush failed";
break;
case ERROR_JOS_CLOSE_FAILED:
rcMessage = "Jar Output Stream Close failed";
break;
case ERROR_FOS_CLOSE_FAILED:
rcMessage = "File Output Stream Close failed";
break;
case ERROR_JFTEMPLATE_CLOSE_FAILED:
rcMessage = "War Template Input Stream Close failed";
break;
case ERROR_EXCEPTION:
rcMessage = "Exception";
break;
default:
rcMessage = "Unknown error";
break;
}
if (s != null)
log(s + rcMessage);
else
log(rcMessage);
}
/**
* Log string.
*
* @param s Log string.
*/
static void log(String s)
{
try
{
if (m_logFileWriter != null)
m_logFileWriter.write(s + "\r\n");
}
catch (IOException ioe)
{
// Do nothing
}
}
/**
* Applications Entry Point.
*
* @param args Arguments.
*/
public static void main(String[] args)
{
String op = null;
boolean opPerformed = false;
boolean argumentsError = false;
String filePath = null;
int rc = ERROR_NO_ERROR;
try
{
// Process the command line arguments
for (int i = 0; i < args.length; i++)
{
// Proceed based on the command
if (args[i].equalsIgnoreCase("-file"))
{
// The next argument should contain the filepath
if (args.length > (i + 1))
{
filePath = args[i + 1];
i++;
}
else
{
argumentsError = true;
break;
}
}
else if (args[i].equalsIgnoreCase("-logfolder"))
{
// The next argument should contain the path to the log folder
if (args.length > (i + 1))
{
// Overwrite the default
m_logFolderPath = args[i + 1];
i++;
}
else
{
argumentsError = true;
break;
}
}
else if (args[i].equalsIgnoreCase("-c"))
{
// List operation requested
if (op == null)
{
op = "configure";
}
else
{
argumentsError = true;
break;
}
}
else if (args[i].equalsIgnoreCase("-u"))
{
// List operation requested
if (op == null)
{
op = "unconfigure";
}
else
{
argumentsError = true;
break;
}
}
}
// Get ready to log
File logFolder = new File(m_logFolderPath);
if (!logFolder.exists())
{
// Create the log folder
logFolder.mkdirs();
m_logFile = new File(logFolder.getAbsolutePath() + "\\" + LOG_FILE_NAME);
m_logFileWriter = new FileWriter(m_logFile);
}
else
{
if (logFolder.isDirectory())
{
m_logFile = new File(logFolder.getAbsolutePath() + "\\" + LOG_FILE_NAME);
m_logFileWriter = new FileWriter(m_logFile);
}
}
// Proceed based on the specified parameters
if (argumentsError == false)
{
// Verify that the necessary input parameters where specified
if (filePath != null && op != null)
{
// Process the property file
if (ERROR_NO_ERROR == (rc = processProperties(filePath)))
{
// Proceed based on the operation requested
if (op.compareTo("configure") == 0)
{
Configure c = new Configure(m_properties);
rc = c.m_rc;
}
else if (op.compareTo("unconfigure") == 0)
{
Unconfigure u = new Unconfigure(m_properties);
rc = u.m_rc;
}
else
{
log("Unsupported operation: " + op);
argumentsError = true;
}
}
else
{
argumentsError = true;
}
}
else
{
argumentsError = true;
log("Not all required parameters specified");
}
}
}
catch (Exception e)
{
rc = ERROR_EXCEPTION;
log("Exception" + e.getMessage());
}
finally
{
// Close the log file writer if necessary
if (m_logFileWriter != null)
{
try
{
m_logFileWriter.flush();
m_logFileWriter.close();
}
catch (Exception e)
{
// Do nothing
}
}
}
// Display the usage string if we encountered an error with the
// command line arguments.
if (argumentsError)
{
System.out.print(usage);
rc = ERROR_INVALID_ARGUMENT;
}
// Set the exit code
System.exit(rc);
}
}

View File

@@ -0,0 +1,795 @@
/***********************************************************************
*
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
* Authors: Juan Carlos Luciani <jluciani@novell.com>
* Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipFile;
/**
* Configure Class.
* <p>
* This class readies the Authentication Token Service after it has been
* installed.
*/
public class Configure
{
// Other constants
final static String SERVER_KEY_STORE_RELATIVE_PATH = "\\etc\\keys\\server\\jks-store";
final static String CLIENT_KEY_STORE_RELATIVE_PATH = "\\etc\\keys\\client\\jks-store";
final static String SIGNING_CERT_RELATIVE_PATH = "\\etc\\keys\\casaatsdSigningCert";
// Configured properties
Properties m_properties;
// Completion code
int m_rc;
// Template replace strings
String[] m_rgsSearchFor;
String[] m_rgsReplaceWith;
/**
* Constructor.
*
* @param properties Configuration properties.
*/
Configure(Properties properties)
{
m_rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure()- Start");
try
{
// Save the properties
m_properties = properties;
// Process the properties
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = processProperties()))
{
// Create the server keystore
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createServerKeystore()))
{
// Create the client keystore
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createClientKeystore()))
{
// Setup the relocatable files
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = setupRelocatableFiles()))
{
// Setup the War file
if (AtsConfigurator.ERROR_NO_ERROR == (m_rc = createWarFileFromTemplate()))
{
// Create the ATS Service
m_rc = createATSService();
}
}
}
}
}
}
catch (Exception e)
{
m_rc = AtsConfigurator.ERROR_EXCEPTION;
AtsConfigurator.log("Exception" + e.getMessage());
}
AtsConfigurator.log("Configure()- End, rc= ", m_rc);
}
/**
* Process properties.
*
* @return Return code.
*/
int processProperties()
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.processProperties()- Start");
// Setup replace template key/values arrays
int i = 0;
Enumeration e = m_properties.propertyNames();
m_rgsSearchFor = new String[m_properties.size()];
m_rgsReplaceWith = new String[m_properties.size()];
while (e.hasMoreElements())
{
String key = (String) e.nextElement();
String value = (String) m_properties.get(key);
m_rgsSearchFor[i] = key;
m_rgsReplaceWith[i] = value;
i++;
}
AtsConfigurator.log("Configure.processProperties()- End, rc= ", rc);
return rc;
}
/**
* Check if the keystore already exists
*
* @param keyStoreRelPath Relative path to the keystore
* @return true if the keystore exists otherwise false.
*/
boolean keyStoreAlreadyExists(String keyStoreRelPath)
{
boolean retValue = false;
AtsConfigurator.log("Configure.keyStoreAlreadyExists()- Start, relPath = " + keyStoreRelPath);
File fileKeystore = new File(((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + keyStoreRelPath);
File fileParent = fileKeystore.getParentFile();
String[] rgChildren = fileParent.list();
if (null != rgChildren)
{
for (int i = 0; i < rgChildren.length; i++)
{
AtsConfigurator.log("child " + i + " = " + rgChildren[i]);
if ("jks-store".equals(rgChildren[i]))
{
retValue = true;
}
}
}
AtsConfigurator.log("Configure.keyStoreAlreadyExists()- End, retValue = " + retValue );
return retValue;
}
/**
* Create the server keystore.
*
* @return Return code.
*/
int createServerKeystore()
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.createServerKeystore()- Start");
// Proceed only if the server keystore has not been created
if (!keyStoreAlreadyExists(SERVER_KEY_STORE_RELATIVE_PATH))
{
String keytoolPath = m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY) + "\\bin\\keytool";
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
// Allocate and setup commandArray to create signing key
String[] commandArray = new String[14];
commandArray[0] = keytoolPath;
commandArray[1] = "-genkey";
commandArray[2] = "-alias"; commandArray[3] = "signingKey";
commandArray[4] = "-keypass"; commandArray[5] = "secret";
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
commandArray[8] = "-storepass"; commandArray[9] = "secret";
commandArray[10] = "-dname"; commandArray[11] = "cn=casaatsd@" + (String) m_properties.get("COMPUTERNAME");
commandArray[12] = "-validity"; commandArray[13] = "3600";
// Create the signing key
if (AtsConfigurator.ERROR_NO_ERROR == (rc =AtsConfigurator.invokeExternalCommand(commandArray)))
{
// Allocate and setup commandArray to export the signing certificate
commandArray = new String[12];
commandArray[0] = keytoolPath;
commandArray[1] = "-export";
commandArray[2] = "-alias"; commandArray[3] = "signingKey";
commandArray[4] = "-keypass"; commandArray[5] = "secret";
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
commandArray[8] = "-storepass"; commandArray[9] = "secret";
commandArray[10] = "-file"; commandArray[11] = installDir + SIGNING_CERT_RELATIVE_PATH;
// Export self-signed certificate for the signing key
if (AtsConfigurator.ERROR_NO_ERROR == (rc = AtsConfigurator.invokeExternalCommand(commandArray)))
{
// Allocate and setup commandArray to create key for Tomcat to do SSL communications
commandArray = new String[14];
commandArray[0] = keytoolPath;
commandArray[1] = "-genkey";
commandArray[2] = "-alias"; commandArray[3] = "tomcat";
commandArray[4] = "-keypass"; commandArray[5] = "secret";
commandArray[6] = "-keystore"; commandArray[7] = installDir + SERVER_KEY_STORE_RELATIVE_PATH;
commandArray[8] = "-storepass"; commandArray[9] = "secret";
commandArray[10] = "-dname"; commandArray[11] = "cn=" + (String) m_properties.get("COMPUTERNAME");
commandArray[12] = "-keyalg"; commandArray[13] = "RSA";
// Create a key for Tomcat to do SSL communications
rc = AtsConfigurator.invokeExternalCommand(commandArray);
}
}
}
AtsConfigurator.log("Configure.createServerKeystore()- End, rc= ", rc);
return rc;
}
/**
* Create the client keystore.
*
* @return Return code.
*/
int createClientKeystore()
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.createClientKeystore()- Start");
// Proceed only if the client keystore has not been created
if (!keyStoreAlreadyExists(CLIENT_KEY_STORE_RELATIVE_PATH))
{
String keytoolPath = m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY) + "\\bin\\keytool";
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
// Allocate and setup commandArray to export the signing certificate
String[] commandArray = new String[13];
commandArray[0] = keytoolPath;
commandArray[1] = "-import";
commandArray[2] = "-noprompt";
commandArray[3] = "-alias"; commandArray[4] = "signingCert";
commandArray[5] = "-keypass"; commandArray[6] = "secret";
commandArray[7] = "-keystore"; commandArray[8] = installDir + CLIENT_KEY_STORE_RELATIVE_PATH;
commandArray[9] = "-storepass"; commandArray[10] = "secret";
commandArray[11] = "-file"; commandArray[12] = installDir + SIGNING_CERT_RELATIVE_PATH;
// Import the servers certificate in the client keystore
rc = AtsConfigurator.invokeExternalCommand(commandArray);
}
AtsConfigurator.log("Configure.createClientKeystore()- End, rc= ", rc);
return rc;
}
/**
* Create file from template.
*
* @param fileTemplate Template file.
* @param fileOutput Output file path.
* @param escapePathCharsInReplaceString Escape Windows Path Chars in Replace String before using.
* @param useUnixPathCharsInReplaceString Replace Windows Path Chars with "//" in Replace String before using.
* @return Return code.
*/
int createFileFromTemplate(File fileTemplate, File fileOutput, boolean escapePathCharsInReplaceString, boolean useUnixPathCharsInReplaceString)
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
LineNumberReader lnr = null;
FileWriter fwOutput = null;
AtsConfigurator.log("Configure.createFileFromTemplate()- Start, template = " + fileTemplate);
try
{
// Open the files
lnr = new LineNumberReader(new FileReader(fileTemplate));
try
{
fwOutput = new FileWriter(fileOutput);
try
{
// For each line of text in the template file...
String sLineTemplate;
while (null != (sLineTemplate = lnr.readLine()))
{
String sLineOutput = sLineTemplate;
// For each term to be replaced...
for (int i = 0; i < m_rgsSearchFor.length; i++)
{
// Replace all instances of the term on the line
int iSearchFor;
while (-1 != (iSearchFor = sLineOutput.indexOf(m_rgsSearchFor[i])))
{
// Check if we must escape path characters in replace string
String replaceString;
if (useUnixPathCharsInReplaceString)
{
replaceString = m_rgsReplaceWith[i].replace("\\", "//");
}
else
{
if (escapePathCharsInReplaceString)
replaceString = m_rgsReplaceWith[i].replace("\\", "\\\\");
else
replaceString = m_rgsReplaceWith[i];
}
AtsConfigurator.log("replacing " + m_rgsSearchFor[i] + " at position " + iSearchFor + " with " + replaceString);
sLineOutput = sLineOutput.substring(0, iSearchFor) + replaceString +
sLineOutput.substring(iSearchFor + m_rgsSearchFor[i].length());
}
}
try
{
fwOutput.write(sLineOutput + "\r\n");
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_EXCEPTION;
}
}
// Clean up
fwOutput.flush();
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_OUTPUT_COPY_FAILED;
}
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_FILEWRITER_CREATE_FAILED;
}
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_UNABLE_TO_OPEN_TEMPLATE;
}
finally
{
try
{
if (lnr != null)
lnr.close();
if (fwOutput != null)
fwOutput.close();
}
catch (Exception e)
{
// Do nothing
}
}
AtsConfigurator.log("Configure.createFileFromTemplate()- End, rc= ", rc);
return rc;
}
/**
* Setup all of the needed relocatable files.
*
* @return Return code.
*/
int setupRelocatableFiles()
{
int rc;
AtsConfigurator.log("Configure.setupRelocatableFiles()- Start");
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\server-sun.xml"),
new File(installDir + "\\catalinabase\\conf\\server.xml"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\startup.bat"),
new File(installDir + "\\bin\\startup.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\shutdown.bat"),
new File(installDir + "\\bin\\shutdown.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaAuthPolicyEditor.bat"),
new File(installDir + "\\bin\\CasaAuthPolicyEditor.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaAuthTokenSettingsEditor.bat"),
new File(installDir + "\\bin\\CasaAuthTokenSettingsEditor.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaIdenTokenSettingsEditor.bat"),
new File(installDir + "\\bin\\CasaIdenTokenSettingsEditor.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\CasaSvcSettingsEditor.bat"),
new File(installDir + "\\bin\\CasaSvcSettingsEditor.bat"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\svc.settings"),
new File(installDir + "\\etc\\svc\\svc.settings"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\jaas.conf"),
new File(installDir + "\\etc\\svc\\jaas.conf"),
false, false)))
if (AtsConfigurator.ERROR_NO_ERROR == (rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\casa_crypto.properties"),
new File(installDir + "\\etc\\svc\\casa_crypto.properties"),
false, true)))
rc = createFileFromTemplate(new File(installDir + "\\etc\\svc\\templates\\log4j.properties"),
new File(installDir + "\\etc\\svc\\log4j.properties"),
true, false);
AtsConfigurator.log("Configure.setupRelocatableFiles()- End, rc= ", rc);
return rc;
}
/**
* Move files from Jar to Jar.
*
* @param josDst Destination Jar Output stream.
* @param jfSrc Source Jar.
* @return Return code.
*/
int moveFilesFromJarToJar(ZipOutputStream josDst, ZipFile jfSrc)
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.moveFilesFromJarToJar()- Start");
try
{
Enumeration entries = jfSrc.entries();
while (entries.hasMoreElements())
{
ZipEntry jeLoop = (ZipEntry)entries.nextElement();
// Skip WEB-INF/classes/cypto.properties
if (jeLoop.getName().equalsIgnoreCase("WEB-INF/classes/casa_crypto.properties"))
{
AtsConfigurator.log("skipping: " + "WEB-INF/classes/casa_crypto.properties");
continue;
}
// Move the rest of the files over
else
{
AtsConfigurator.log("Transferring jar file: " + jeLoop.getName());
// Create the input stream
InputStream isLoop = jfSrc.getInputStream(jeLoop);
// Set up the output stream
ZipEntry zeIndex = new ZipEntry(jeLoop.getName());
josDst.putNextEntry( zeIndex);
// Transfer the file contents
int bRead;
byte [] b = new byte[4096];
while (-1 != (bRead = isLoop.read(b)))
{
josDst.write(b, 0, bRead);
}
// all done
josDst.closeEntry();
isLoop.close();
}
}
}
catch (Exception e)
{
rc = AtsConfigurator.ERROR_JAR_COPY_FAILED;
}
AtsConfigurator.log("Configure.moveFilesFromJarToJar()- End, rc= ", rc);
return rc;
}
/**
* Add file to Jar.
*
* @param sFilename Path to file.
* @param sName Zip entry name.
* @param josJarNew Jar output stream.
* @return Return code.
*/
int addFileToJar(String sFilename, String sName, ZipOutputStream josJarNew)
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.addFileToJar()- Start");
try
{
// Create the input stream
FileInputStream fis = new FileInputStream(sFilename);
// Set up the output stream
ZipEntry je = new ZipEntry(sName);
josJarNew.putNextEntry(je);
// Tansfer the contents of the file
int bRead;
byte [] b = new byte[4096];
while (-1 != (bRead = fis.read(b)))
{
josJarNew.write(b, 0, bRead);
}
// All done
fis.close();
josJarNew.closeEntry();
}
catch (Exception e)
{
AtsConfigurator.log(e.toString());
rc = AtsConfigurator.ERROR_ADD_FILE_TO_JAR_FAILED;
}
AtsConfigurator.log("Configure.addFileToJar()- End, rc= ", rc);
return rc;
}
/**
* Create War file from template.
*
* @return Return code.
*/
int createWarFileFromTemplate()
{
String sWarTemplate = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\etc\\svc\\templates\\CasaAuthTokenSvc.war";
String sWarNew = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\catalinabase\\webapps\\CasaAuthTokenSvc.war";
File fileWarTemplate = new File(sWarTemplate);
File fileWarNew = new File(sWarNew);
FileOutputStream fosWarNew = null;
ZipOutputStream josWarNew = null;
ZipFile jfTemplate = null;
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.createWarFileFromTemplate()- Start");
// Ensure that the war template exists
AtsConfigurator.log("looking for war template: " + sWarTemplate);
if (!fileWarTemplate.exists())
{
rc = AtsConfigurator.ERROR_WAR_TEMPLATE_FILE_MISSING;
}
if (rc == AtsConfigurator.ERROR_NO_ERROR)
{
// Ensure that the new jar name does not exist
if (fileWarNew.exists())
{
AtsConfigurator.log("war file already exists: " + sWarNew);
if (!fileWarNew.delete())
{
AtsConfigurator.log("could not delete war file: " + sWarNew);
rc = AtsConfigurator.ERROR_NEW_JAR_CANNOT_BE_REPLACED;
}
}
}
if (rc == AtsConfigurator.ERROR_NO_ERROR)
{
// Create/open the new jar
try
{
AtsConfigurator.log("create new war file output stream: " + sWarNew);
fosWarNew = new FileOutputStream(fileWarNew);
josWarNew = new ZipOutputStream(fosWarNew);
}
catch (IOException ioe0)
{
AtsConfigurator.log(ioe0.toString());
rc = AtsConfigurator.ERROR_CREATE_WAR_FOS_FAILED;
}
}
if (rc == AtsConfigurator.ERROR_NO_ERROR)
{
// Open the old jar
try
{
jfTemplate = new ZipFile(sWarTemplate);
}
catch (IOException ioe1)
{
rc = AtsConfigurator.ERROR_OPEN_JAR_TEMPLATE_FAILED;
}
}
if (rc == AtsConfigurator.ERROR_NO_ERROR)
{
// Transfer the files
rc = moveFilesFromJarToJar(josWarNew, jfTemplate);
}
// Add the files
if (rc == AtsConfigurator.ERROR_NO_ERROR)
{
int i;
String [] rgsFilesToAdd = new String[1];
rgsFilesToAdd[0] = ((String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY)) + "\\etc\\svc\\casa_crypto.properties";
String [] rgsNames = new String[1];
rgsNames[0] = "WEB-INF/classes/casa_crypto.properties";
for (i = 0; i < rgsFilesToAdd.length; i++)
{
AtsConfigurator.log("Adding file: " + rgsFilesToAdd[i] + " with name " + rgsNames[i]);
rc = addFileToJar(rgsFilesToAdd[i], rgsNames[i], josWarNew);
}
}
// Close up
if (null != josWarNew)
{
try
{
josWarNew.flush();
}
catch (IOException ioe2)
{
rc = AtsConfigurator.ERROR_JOS_FLUSH_FAILED;
}
try
{
josWarNew.close();
}
catch (IOException ioe3)
{
rc = AtsConfigurator.ERROR_JOS_CLOSE_FAILED;
}
try
{
fosWarNew.close();
}
catch (IOException ioe4)
{
rc = AtsConfigurator.ERROR_FOS_CLOSE_FAILED;
}
}
if (null != jfTemplate)
{
try
{
jfTemplate.close();
}
catch (IOException ioe5)
{
rc = AtsConfigurator.ERROR_JFTEMPLATE_CLOSE_FAILED;
}
}
AtsConfigurator.log("Configure.createWarFileFromTemplate()- End, rc= ", rc);
return rc;
}
/**
* Create ATS Service.
*
* @return Return code.
*/
int createATSService()
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Configure.createATSService()- Start");
String installDir = (String) m_properties.get(AtsConfigurator.INSTALL_DIR_PROPERTY);
String sDirCatalinaBase = installDir + "/catalinabase";
String sDirCatalinaHome = (String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY);
String sExe = ((String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY)) + "\\bin\\tomcat5.exe";
String sFileJaasConf = installDir + "\\etc\\svc\\jaas.conf";
String sDirConfig = installDir + "/etc/svc";
String sDirJavaHome = (String) m_properties.get(AtsConfigurator.JAVA_HOME_PROPERTY);
String sLogPrefix = "casa-auth-token-svc";
String sDirLogs = sDirCatalinaBase + "/logs";
/*
* Note that in the following code we do not bother to check the return of the invokeExternalCommand
* call. This is because I have found that some versions of tomcat5.exe do not always return success
* even though they should.
*/
String[] commandArray = {
sExe, "//IS//CasaAuthTokenService", "--StartClass", "org.apache.catalina.startup.Bootstrap", "--StopClass", "org.apache.catalina.startup.Bootstrap", "--StartParams", "start", "--StopParams", "stop", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray);
String[] commandArray1 = {
sExe, "//US//CasaAuthTokenService", "--Startup", "auto", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray1);
String[] commandArray2 = {
sExe, "//US//CasaAuthTokenService", "--JvmOptions", "\"-Dcatalina.base=" + sDirCatalinaBase + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray2);
String[] commandArray3 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dcatalina.home=" + sDirCatalinaHome + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray3);
String[] commandArray4 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.endorsed.dirs=" + sDirCatalinaHome + "/common/endorsed\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray4);
String[] commandArray5 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.security.auth.login.config=" + sFileJaasConf + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray5);
String[] commandArray6 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dcom.novell.casa.authtoksvc.config=" + sDirConfig + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray6);
String[] commandArray7 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Dlog4j.configuration=file:" + installDir + "/etc/log4j.properties" + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray7);
String[] commandArray8 = {
sExe, "//US//CasaAuthTokenService", "++JvmOptions", "\"-Djava.io.tmpdir=" + sDirCatalinaBase+ "/temp\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray8);
String[] commandArray9 = {
sExe, "//US//CasaAuthTokenService", "--StartMode", "jvm", "--StopMode", "jvm", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray9);
String[] commandArray10 = {
sExe, "//US//CasaAuthTokenService", "--JvmMs", "128", "--JvmMx", "512", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray10);
String[] commandArray11 = {
sExe, "//US//CasaAuthTokenService", "--Classpath", "\"" + sDirCatalinaHome + "/bin/bootstrap.jar\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray11);
String[] commandArray12 = {
sExe, "//US//CasaAuthTokenService", "--Jvm", "\"" + sDirJavaHome + "/jre/bin/server/jvm.dll\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray12);
String[] commandArray13 = {
sExe, "//US//CasaAuthTokenService", "--LogPath", "\"" + sDirLogs + "\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray13);
String[] commandArray14 = {
sExe, "//US//CasaAuthTokenService", "--LogPrefix", "\"" + sLogPrefix + "_service.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray14);
String[] commandArray15 = {
sExe, "//US//CasaAuthTokenService", "--StdOutput", "\"" + sDirLogs + File.separator + sLogPrefix + "_stdout.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray15);
String[] commandArray16 = {
sExe, "//US//CasaAuthTokenService", "--StdError", "\"" + sDirLogs + File.separator + sLogPrefix + "_stderr.log\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray16);
String[] commandArray17 = {
sExe, "//US//CasaAuthTokenService", "--DisplayName", "CasaAuthTokenSvc", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray17);
String[] commandArray18 = {
sExe, "//US//CasaAuthTokenService", "--Description", "\"Casa Authentication Token Service\"", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcInstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray18);
AtsConfigurator.log("Configure.createATSService()- End, rc= ", rc);
return rc;
}
}

View File

@@ -0,0 +1,40 @@
#######################################################################
#
# Copyright (C) 2006 Novell, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Juan Carlos Luciani <jluciani@novell.com>
#
#######################################################################
SUBDIRS =
DIST_SUBDIRS =
JAVAFILES = AtsConfigurator.java \
Configure.java \
Unconfigure.java
EXTRA_DIST = $(JAVAFILES)
.PHONY: package package-clean package-install package-uninstall
package package-clean package-install package-uninstall:
$(MAKE) -C $(TARGET_OS) $@
maintainer-clean-local:
rm -f Makefile.in

View File

@@ -0,0 +1,101 @@
/***********************************************************************
*
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
* Authors: Juan Carlos Luciani <jluciani@novell.com>
* Greg Richardson <grichardson@novell.com>
*
***********************************************************************/
import java.util.Properties;
import java.io.File;
/**
* Unconfigure Class.
* <p>
* This class readies the Authentication Token Service to be un-installed.
*/
public class Unconfigure
{
// Configured properties
Properties m_properties;
// Completion code
int m_rc;
/**
* Constructor.
*
* @param properties Configuration properties.
*/
Unconfigure(Properties properties)
{
m_rc = AtsConfigurator.ERROR_NO_ERROR;
AtsConfigurator.log("Unconfigure()- Start");
try
{
// Save the properties
m_properties = properties;
// delete the ATS service
m_rc = deleteATSService();
}
catch (Exception e)
{
m_rc = AtsConfigurator.ERROR_EXCEPTION;
AtsConfigurator.log("Exception" + e.getMessage());
}
AtsConfigurator.log("Unconfigure()- End, rc= ", m_rc);
}
/**
* Delete ATS Service.
*
* @return Return code.
*/
int deleteATSService()
{
int rc = AtsConfigurator.ERROR_NO_ERROR;
String sExe = ((String) m_properties.get(AtsConfigurator.TOMCAT_HOME_PROPERTY)) + "\\bin\\tomcat5.exe";
AtsConfigurator.log("Unconfigure.deleteATSService()- Start");
/*
* Note that in the following code we do not bother to check the return of the invokeExternalCommand
* call. This is because I have found that some versions of tomcat5.exe do not always return success
* even though they should.
*/
String[] commandArray = {
sExe, "//SS//CasaAuthTokenService", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcUninstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray);
String[] commandArray1 = {
sExe, "//DS//CasaAuthTokenService", "--LogPath", AtsConfigurator.m_logFolderPath, "--LogPrefix", "AtsSvcUninstall.log"
};
AtsConfigurator.invokeExternalCommand(commandArray1);
AtsConfigurator.log("Unconfigure().deleteATSService- End, rc= ", rc);
return rc;
}
}