SetupUtils.java revision a89f7014aeb71dba5c94404dfea7eb89e7eeee74
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* This class provides a number of utility methods that may be used during the
* graphical or command-line setup process.
*/
mayInstantiate=false,
mayExtend=false,
mayInvoke=true)
public class SetupUtils
{
/**
* Java property used to known if we are using web start or not.
*/
/**
* Specific environment variable used by the scripts to find java.
*/
/**
* Specific environment variable used by the scripts to set java arguments.
*/
/**
* Java property used to know which are the jar files that must be downloaded
* lazily. The current code in WebStartDownloader that uses this property
* assumes that the URL are separated with an space.
*/
public static final String LAZY_JAR_URLS =
"org.opends.quicksetup.lazyjarurls";
/**
* Java property used to know which is the name of the zip file that must
* be unzipped and whose contents must be extracted during the Web Start
* based setup.
*/
public static final String ZIP_FILE_NAME =
"org.opends.quicksetup.zipfilename";
/**
* The relative path where all the libraries (jar files) are.
*/
/**
* The relative path where the setup stores the name of the host the user
* provides. This is used for instance to generate the self-signed admin
* certificate the first time the server starts.
*/
+ "hostname";
/* These string values must be synchronized with Directory Server's main
* method. These string values are considered stable by the server team and
* not candidates for internationalization. */
/** Product name. */
/** Build ID. */
/** Major version. */
/** Minor version. */
/** Point version of the product. */
/** Revision number in SVN. */
/** The SVN url repository. */
/** The version qualifier. */
/** Incompatibilities found between builds (used by the upgrade tool). */
/** Fix IDs associated with the build. */
/** Debug build identifier. */
/** The OS used during the build. */
/** The user that generated the build. */
/** The java version used to generate the build. */
/** The java vendor of the JVM used to build. */
/** The version of the JVM used to create the build. */
/** The vendor of the JVM used to create the build. */
/** The build number. */
/**
* A variable used to keep the latest read host name from the file written
* by the setup.
*/
private static String lastReadHostName;
/**
* Creates a MakeLDIF template file using the provided information.
*
* @param baseDN The base DN for the data in the template file.
* @param numEntries The number of user entries the template file should
* create.
*
* @return The {@code File} object that references the created template file.
*
* @throws IOException If a problem occurs while writing the template file.
*/
throws IOException
{
}
/**
* Creates a MakeLDIF template file using the provided information.
*
* @param baseDNs The base DNs for the data in the template file.
* @param numEntries The number of user entries the template file should
* create.
*
* @return The {@code File} object that references the created template file.
*
* @throws IOException If a problem occurs while writing the template file.
*/
int numEntries)
throws IOException
{
int i = 0;
{
i++;
}
if (numEntries > 0)
{
}
{
if (numEntries > 0)
{
}
}
{
"<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}");
}
{
}
return templateFile;
}
/**
* Returns {@code true} if the provided port is free and we can use it,
* {@code false} otherwise.
* @param hostname the host name we are analyzing. Use <CODE>null</CODE>
* to connect to any address.
* @param port the port we are analyzing.
* @return {@code true} if the provided port is free and we can use it,
* {@code false} otherwise.
*/
{
boolean canUseAsPort = false;
try
{
{
}
else
{
}
serverSocket = new ServerSocket();
if (!OperatingSystem.isWindows())
{
serverSocket.setReuseAddress(true);
}
canUseAsPort = true;
/* Try to create a socket because sometimes even if we can create a server
* socket there is already someone listening to the port (is the case
* of products as Sun DS 6.0).
*/
try
{
s = new Socket();
canUseAsPort = false;
} catch (Throwable t)
{
}
finally
{
if (s != null)
{
try
{
s.close();
}
catch (Throwable t)
{
}
}
}
} catch (IOException ex)
{
canUseAsPort = false;
} finally
{
try
{
if (serverSocket != null)
{
}
{
}
}
return canUseAsPort;
}
/**
* Returns {@code true} if the provided port is free and we can use it,
* {@code false} otherwise.
* @param port the port we are analyzing.
* @return {@code true} if the provided port is free and we can use it,
* {@code false} otherwise.
*/
public static boolean canUseAsPort(int port)
{
}
/**
* Returns {@code true} if the provided port is a privileged port,
* {@code false} otherwise.
* @param port the port we are analyzing.
* @return {@code true} if the provided port is a privileged port,
* {@code false} otherwise.
*/
public static boolean isPrivilegedPort(int port)
{
}
/**
* Indicates whether we are in a web start installation or not.
*
* @return <CODE>true</CODE> if we are in a web start installation and
* <CODE>false</CODE> if not.
*/
public static boolean isWebStart()
{
}
/**
* Returns the String that can be used to launch an script using Runtime.exec.
* This method is required because in Windows the script that contain a "="
* in their path must be quoted.
* @param script the script name
* @return the absolute path for the given parentPath and relativePath.
*/
{
if (OperatingSystem.isWindows()
{
}
return s;
}
/**
* Returns a randomly generated password for a self-signed certificate
* keystore.
* @return a randomly generated password for a self-signed certificate
* keystore.
*/
public static char[] createSelfSignedCertificatePwd() {
int pwdLength = 50;
}
return pwd;
}
/**
* Export a certificate in a file. If the certificate alias to export is null,
* It will export the first certificate defined.
*
* @param certManager
* Certificate manager to use.
* @param alias
* Certificate alias to export. If {@code null} the first certificate
* defined will be exported.
* @param path
* Path of the output file.
* @throws CertificateEncodingException
* If the certificate manager cannot encode the certificate.
* @throws IOException
* If a problem occurs while creating or writing in the output file.
* @throws KeyStoreException
* If the certificate manager cannot retrieve the certificate to be
* exported.
*/
{
final Certificate certificate =
try
{
}
finally
{
}
}
/**
* The next two methods are used to generate the random password for the
* self-signed certificate.
*/
{
char generatedChar;
int d;
switch (type)
{
case 0:
// Will return a digit
d = next % 10;
if (d < 0)
{
d = d * -1;
}
generatedChar = (char) (d+48);
break;
case 1:
// Will return a lower case letter
d = next % 26;
if (d < 0)
{
d = d * -1;
}
generatedChar = (char) (d + 97);
break;
default:
// Will return a capital letter
d = next % 26;
if (d < 0)
{
d = d * -1;
}
generatedChar = (char) (d + 65) ;
}
return generatedChar;
}
{
}
/**
* Returns the host name to be used to create self-signed certificates. <br>
* The method will first try to read the host name file written by the setup
* where the user provided the host name where OpenDJ has been installed. If
* the file cannot be read, the class {@link java.net.InetAddress} is used.
*
* @param installationRoot the path where the server is installed.
* @return the host name to be used to create self-signed certificates.
* @throws UnknownHostException
* if a host name could not be used.
*/
public static String getHostNameForCertificate(
{
try
{
s = s.trim();
if (s.length() > 0)
{
hostName = s;
}
}
catch (IOException ioe)
{
}
finally
{
}
{
}
{
}
return hostName;
}
}