/*
* 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 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS.
*/
/**
* This class is used to provide a data model for the different parameters
* that the user can provide in the installation wizard.
*/
public class UserData
{
private int serverPort;
private int adminConnectorPort;
private boolean startServer;
private boolean stopServer;
private boolean enableWindowsService;
private boolean createAdministrator;
private boolean quiet;
private boolean verbose;
private final boolean interactive;
private boolean forceOnError;
/**
* The script name to be used to get and set the java arguments for the
* server runtime.
*/
/**
* The script name to be used to get and set the java arguments for the
* (off-line) import.
*/
/**
* Creates a user data object with default values.
*/
public UserData() {
interactive = true;
startServer = true;
enableWindowsService = false;
forceOnError = true;
verbose = false;
// See what we can propose as port
int defaultLdapPort = getDefaultPort();
if (defaultLdapPort != -1)
{
}
// See what we can propose as port
if (defaultAdminPort != -1)
{
}
new HashSet<SuffixDescriptor>(),
new HashSet<SuffixDescriptor>());
remoteWithNoReplicationPort = new HashMap<>();
}
/**
* Sets the location of the server (installation path).
* @param serverLocation the new server location (installation path).
*/
{
this.serverLocation = serverLocation;
}
/**
* Returns the location of the server (installation path).
* @return the location of the server (installation path).
*/
{
return serverLocation;
}
/**
* Sets the host name.
* @param hostName the server host name.
*/
{
}
/**
* Returns the server host name.
* @return the server host name.
*/
{
return hostName;
}
/**
* Sets the server LDAP port.
* @param serverPort the new server LDAP port.
*/
{
this.serverPort = serverPort;
}
/**
* Returns the server LDAP port.
* @return the server LDAP port.
*/
public int getServerPort()
{
return serverPort;
}
/**
* Sets the admin connector port.
* @param adminConnectorPort the new admin connector port.
*/
{
this.adminConnectorPort = adminConnectorPort;
}
/**
* Returns the admin connector port.
* @return the admin connector port.
*/
public int getAdminConnectorPort()
{
return adminConnectorPort;
}
/**
* Sets the server JMX port.
* @param serverJMXPort the new server JMX port.
*/
{
this.serverJMXPort = serverJMXPort;
}
/**
* Returns the server JMX port.
* @return the server JMX port.
*/
public int getServerJMXPort()
{
return serverJMXPort;
}
/**
* Returns the Directory Manager DN.
* @return the Directory Manager DN.
*/
{
return directoryManagerDn;
}
/**
* Sets the new Directory Manager DN.
* @param directoryManagerDn the new Directory Manager DN.
*/
{
this.directoryManagerDn = directoryManagerDn;
}
/**
* Returns the Directory Manager password.
* @return the Directory Manager password.
*/
{
return directoryManagerPwd;
}
/**
* Sets the new Directory Manager password.
* @param directoryManagerPwd the new Directory Manager password.
*/
{
}
/**
* Returns <CODE>true</CODE> if the server must be started once the
* installation is finished, <CODE>false</CODE> if not.
* @return <CODE>true</CODE> if the server must be started once the
* installation is finished, <CODE>false</CODE> if not.
*/
public boolean getStartServer()
{
return startServer;
}
/**
* Sets whether we want to start the server once the installation is finished
* or not.
* @param startServer the boolean indicating whether to start the server or
* not.
*/
{
this.startServer = startServer;
}
/**
* Sets whether to stop the server or not.
* @param stopServer stop the server or not.
*/
{
this.stopServer = stopServer;
}
/**
* Returns whether the user wants to stop the server or not.
* @return <CODE>true</CODE> if the user wants to stop the server and <CODE>\
* false</CODE> otherwise.
*/
public boolean getStopServer()
{
return stopServer;
}
/**
* Returns <CODE>true</CODE> if the windows service must be enabled during
* installation, <CODE>false</CODE> if not.
* @return <CODE>true</CODE> if the windows service must be enabled during
* installation, <CODE>false</CODE> if not.
*/
public boolean getEnableWindowsService()
{
return enableWindowsService;
}
/**
* Sets whether we want to enable windows service during installation or not.
* @param enableWindowsService the boolean indicating whether we want to
* enable windows service during installation or not.
*/
{
}
/**
* Returns the new userRoot backend type.
*
* @return the new userRoot backend type.
*/
{
return backendType;
}
/**
* Sets the new userRoot backend type.
*
* @param backendType
* The new backend type. This string must be compatible with
* dsconfig tool.
*/
public void setBackendType(ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
{
this.backendType = backendType;
}
/**
* Returns the NewSuffixOptions object representing the data in the New Suffix
* Data Options panel.
* @return the NewSuffixOptions object representing the data in the New Suffix
* Data Options panel.
*/
{
return newSuffixOptions;
}
/**
* Sets the NewSuffixOptions object representing the data in the New Suffix
* Data Options panel.
* @param newSuffixOptions the NewSuffixOptions object representing the data
* in the New Suffix Data Options panel.
*/
{
this.newSuffixOptions = newSuffixOptions;
}
/**
* Returns the DataReplicationOptions object representing the data in the
* Data Replication panel.
* @return the DataReplicationOptions object representing the data in the
* Data Replication panel.
*/
{
return replicationOptions;
}
/**
* Sets the DataReplicationOptions object representing the data in the
* Data Replication panel.
* @param replicationOptions the DataReplicationOptions object
* representing the data in the Data Replication panel.
*/
public void setReplicationOptions(
{
this.replicationOptions = replicationOptions;
}
/**
* Returns whether must create a global administrator or not.
* @return <CODE>true</CODE> if we must create a global administrator and
* <CODE>false</CODE> otherwise.
*/
public boolean mustCreateAdministrator()
{
return createAdministrator;
}
/**
* Sets whether must create a global administrator or not.
* @param createAdministrator whether we must create a global administrator or
* not.
*/
{
}
/**
* Returns the UID of the global administrator.
* @return the UID of the global administrator.
*/
{
return globalAdministratorUID;
}
/**
* Sets the UID of the global administrator.
* @param globalAdministratorUID the UID of the global administrator.
*/
{
}
/**
* Returns the password of the global administrator.
* @return the password of the global administrator.
*/
{
return globalAdministratorPassword;
}
/**
* Sets the password of the global administrator.
* @param globalAdministratorPwd the password of the global administrator.
*/
{
}
/**
* Sets the suffixes to replicate options.
* @param suffixesToReplicateOptions the suffixes to replicate options
* object.
*/
public void setSuffixesToReplicateOptions(
{
}
/**
* Returns the suffixes to replicate options.
* @return the suffixes to replicate options.
*/
{
return suffixesToReplicateOptions;
}
/**
* chosen by the user.
* chosen by the user.
*/
{
return securityOptions;
}
/**
* chosen by the user.
* configuration chosen by the user.
*/
{
this.securityOptions = securityOptions;
}
/**
* Sets whether or not this session should print messages to the
* console if in CLI mode.
* @param quiet where true indicates this session should be quiet
*/
}
/**
* Indicates whether or not the user has requested quiet mode.
* <p>
* Quiet mode in the CLI means that nothing is written to output including
* prompts for information and whether or not to continue an operation
* experiencing errors.
*
* @return boolean where true indicates this session should be quiet.
*/
public boolean isQuiet() {
return this.quiet;
}
/**
* Sets whether or not this session should be verbose.
* @param verbose where true indicates this session should be verbose
*/
}
/**
* Indicates whether or not the user has requested verbose mode.
*
* @return boolean where true indicates this session should be verbose.
*/
public boolean isVerbose() {
return this.verbose;
}
/**
* Sets whether or not we must continue when there is a non critical error.
* @param forceOnError where true indicates to continue uninstall if there is
* a non critical error.
*/
this.forceOnError = forceOnError;
}
/**
* Indicates whether or not the user has requested to continue when a non
* critical error occurs.
*
* @return boolean where true indicates to continue uninstall if there is a
* non critical error.
*/
public boolean isForceOnError() {
return this.forceOnError;
}
/**
* Indicates whether or not the user has requested interactive mode.
* <p>
* Interactive mode in the CLI means that the CLI will prompt the user
* for more information if it is required. Interactivity does NOT
* affect prompts to the user regarding actions like continuing an operation
* that is experiencing errors.
*
* @return boolean where true indicates this session should be interactive
*/
public boolean isInteractive() {
return this.interactive;
}
/**
* Provides the port that will be proposed to the user in the second page of
* the installation wizard. It will check whether we can use ports of type
* X389 and if not it will return -1.
*
* @return the free port of type x389 if it is available and we can use and -1
* if not.
*/
public static int getDefaultPort()
{
return getDefaultPort(389);
}
/**
* Provides the administration port that will be proposed to the user in the
* second page of the installation wizard. It will check whether we can use
* ports of type X444 and if not it will return -1.
*
* @return the free port of type x444 if it is available and we can use and -1
* if not.
*/
public static int getDefaultAdminConnectorPort()
{
return getDefaultPort(4444);
}
/**
* Provides the port that will be proposed to the user in the security dialog
* of the installation wizard. It will check whether we can use ports of type
* X636 and if not it will return -1.
* @param defaultLdapPort the default port used for LDAP.
*
* @return the free port of type X636 if it is available and we can use and -1
* if not.
*/
{
// Try first with the correlated port of the default LDAP port.
{
return port;
}
return getDefaultPort(636);
}
{
for (int i = 0; i < 10000; i += 1000)
{
{
return port;
}
}
return -1;
}
/**
* Provides the port that will be used by default for JMX.
*
* @param forbiddenPorts an array of ports that we cannot use.
* @return the port X689 if it is available and we can use and -1 if not.
*/
{
int defaultJMXPort = -1;
{
boolean isForbidden = false;
if (forbiddenPorts != null)
{
{
}
}
{
}
}
return defaultJMXPort;
}
/**
* Provides the default host name that will be proposed to the user for the
* local host.
* @return the default host name that will be proposed to the user for the
* local host.
*/
{
if (defaultHostName == null)
{
// Run a thread in the background in order to avoid blocking the
// application if reverse DNS lookups take a long time.
{
/**
* Search for a host name of the form host.example.com on each
* interface, except the loop back. Prefer interfaces of the form ethX.
*/
public void run()
{
try
{
while (i.hasMoreElements())
{
NetworkInterface n = i.nextElement();
// Skip loop back interface.
if (n.isLoopback())
{
continue;
}
// Check each interface address (IPv4 and IPv6).
while (j.hasMoreElements())
{
// Ignore hostnames which are IP addresses.
{
if (address instanceof Inet4Address)
{
}
else if (address instanceof Inet6Address)
{
}
}
}
// Remember the host name if it looks fully qualified.
{
}
{
}
if (fqHostName != null)
{
// This looks like a fully qualified name on a ethX interface,
// so
// use that and break out.
{
break;
}
}
}
{
// No ethX host name, so try any other host name that was found.
}
}
catch (Exception e)
{
// Ignore - we'll default to the loopback address later.
}
}
});
try
{
t.setDaemon(true);
t.start();
}
catch (Exception e)
{
// Ignore - we'll default to the loopback address later.
}
if (defaultHostName == null)
{
// No host names found, so use the loop back.
try
{
}
catch (Exception e)
{
// Not much we can do here.
defaultHostName = "localhost";
}
}
}
return defaultHostName;
}
/**
* Returns a Map containing as key a ServerDescriptor and as value an Integer
* corresponding to the Replication Port chosen by the user.
*
* Only the servers that have no replication port appear on this map.
* @return a Map containing as key a ServerDescriptor and as value an
* AuthenticationData corresponding to the Replication Port chosen by the
* user.
*/
{
return new HashMap<>(remoteWithNoReplicationPort);
}
/**
* Sets a the Replication Ports chosen by the user in the remote servers.
* @param remoteWithNoReplicationPort the Map containing as key a
* ServerDescriptor and as value an AuthenticationData corresponding to the
* Replication Port chosen by the user.
*/
public void setRemoteWithNoReplicationPort(
{
this.remoteWithNoReplicationPort.clear();
}
/**
* Returns the different script names for which there are java arguments.
* @return the different script names for which there are java arguments.
*/
{
return hmJavaArguments.keySet();
}
/**
* Returns the java arguments associated with a script name. Returns
* <CODE>null</CODE> if no java arguments are defined.
* @param scriptName the script name.
* @return the java arguments associated with a script name.
*/
{
}
/**
* Returns the default java arguments associated with a script name. Returns
* <CODE>null</CODE> if no java arguments are defined.
* @param scriptName the script name.
* @return the default java arguments associated with a script name.
*/
{
}
/**
* Sets the java arguments associated with a script name.
* @param scriptName the script name.
* @param args the java arguments associated with a script name.
*/
{
}
private void createDefaultJavaArguments()
{
hmJavaArguments = new HashMap<>();
int maxMemoryMb = 256;
int minMemoryMb = 128;
// If the current max memory is bigger than the max heap we want to set,
// assume that the JVM ergonomics are going to be able to allocate enough
// memory.
{
maxMemoryMb = -1;
minMemoryMb = -1;
}
{
}
{
}
}
{
return new String[] {
"backup.online", "base64", "create-rc-script", "dsconfig",
"dsreplication", "export-ldif.online",
"import-ldif.online", "ldapcompare", "ldapdelete",
"ldapmodify", "ldappasswordmodify", "ldapsearch", "list-backends",
"manage-account", "manage-tasks", "restore.online", "stop-ds",
"status", "uninstall", "setup"
};
}
{
return new String[]
{
"backup.offline", "dsreplication.offline",
"encode-password", "export-ldif.offline",
"upgrade", "verify-index", "backendstat"
};
}
/**
* Sets the timeout to be used to establish a connection.
* @param connectTimeout the timeout to be used to establish a connection.
*/
{
this.connectTimeout = connectTimeout;
}
/**
* Returns the timeout to be used to connect in milliseconds.
* @return the timeout to be used to connect in milliseconds. Returns
* {@code 0} if there is no timeout.
*/
public int getConnectTimeout()
{
return connectTimeout;
}
}