ConfigureDS.java revision ca669ae54f86dbeea277280690584d9f591c7571
/*
* 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-2009 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* This class provides a very basic tool that can be used to configure some of
* the most important settings in the Directory Server. This configuration is
* performed by editing the server's configuration files and therefore the
* Directory Server must be offline. This utility will be used during the
* Directory Server installation process.
* <BR><BR>
* The options that this tool can currently set include:
* <BR>
* <UL>
* <LI>The port on which the server will listen for LDAP communication</LI>
* <LI>The DN and password for the initial root user.
* <LI>The set of base DNs for user data</LI>
* </UL>
*/
public class ConfigureDS
{
/** The fully-qualified name of this class. */
private static final String CLASS_NAME =
"org.opends.server.tools.ConfigureDS";
/**
* The DN of the configuration entry defining the JE database backend.
*/
private static final String DN_JE_BACKEND =
/**
* The DN of the configuration entry defining the LDAP connection handler.
*/
public static final String DN_LDAP_CONNECTION_HANDLER =
"cn=LDAP Connection Handler," + DN_CONNHANDLER_BASE;
/**
* The DN of the configuration entry defining the Administration connector.
*/
public static final String DN_ADMIN_CONNECTOR =
"cn=Administration Connector," + DN_CONFIG_ROOT;
/**
* The DN of the configuration entry defining the LDAPS connection handler.
*/
private static final String DN_LDAPS_CONNECTION_HANDLER =
"cn=LDAPS Connection Handler," + DN_CONNHANDLER_BASE;
/**
* The DN of the configuration entry defining the JMX connection handler.
*/
private static final String DN_JMX_CONNECTION_HANDLER =
"cn=JMX Connection Handler," + DN_CONNHANDLER_BASE;
/**
* The DN of the configuration entry defining the initial root user.
*/
public static final String DN_ROOT_USER =
"cn=Directory Manager," + DN_ROOT_DN_CONFIG_BASE;
/**
* The DN of the Crypto Manager.
*/
/**
* The DN of the DIGEST-MD5 SASL mechanism handler.
*/
public static final String DN_DIGEST_MD5_SASL_MECHANISM =
"cn=DIGEST-MD5,cn=SASL Mechanisms,cn=config";
/**
* Provides the command-line arguments to the <CODE>configMain</CODE> method
* for processing.
*
* @param args The set of command-line arguments provided to this program.
*/
{
if (exitCode != 0)
{
}
}
/**
* Parses the provided command-line arguments and makes the appropriate
* changes to the Directory Server configuration.
*
* @param args The command-line arguments provided to this program.
*
* @param outStream Output stream.
* @param errStream Error stream.
* @return The exit code from the configuration processing. A nonzero value
* indicates that there was some kind of problem during the
* configuration processing.
*/
{
false);
try
{
false, true,
null,
configFile.setHidden(true);
OPTION_LONG_CONFIG_CLASS, false,
false, true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
configClass.setHidden(true);
try
{
}
catch (Exception e)
{
// Not much we can do here.
defaultHostName = "localhost";
}
OPTION_LONG_HOST, false, false, true,
null,
"ldapPort", false, false,
null, true, 1,
true, 65535,
"adminConnectorPort", false, false,
"adminConnectorPort", true, 1, true, 65535,
true, 65535,
OPTION_SHORT_START_TLS, "enableStartTLS",
null, true, 1,
true, 65535,
'k',
"keyManagerProviderDN",
false, false,
null,
null,
't',
"trustManagerProviderDN",
false, false,
null,
null,
'm',
"keyManagerPath",
false, false, true,
null,
null,
'a',
"certNickName",
false, false,
true, INFO_NICKNAME_PLACEHOLDER.get(),
null,
null,
baseDNString = new StringArgument(
"basedn", OPTION_SHORT_BASEDN,
OPTION_LONG_BASEDN, false, true,
true, INFO_BASEDN_PLACEHOLDER.get(),
"dc=example,dc=com",
null,
rootDNString = new StringArgument(
"rootdn", OPTION_SHORT_ROOT_USER_DN,
OPTION_LONG_ROOT_USER_DN, false, false,
true, INFO_ROOT_USER_DN_PLACEHOLDER.get(),
"cn=Directory Manager", null,
rootPassword = new StringArgument(
"rootpw", OPTION_SHORT_BINDPWD,
"rootPassword", false,
"rootpwfile",
"rootPasswordFile", false, false,
serverRoot.setHidden(true);
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to the program.
try
{
}
catch (ArgumentException ae)
{
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Make sure that the user actually tried to configure something.
if (!baseDNString.isPresent()
&& !rootDNString.isPresent())
{
return 1;
}
try
{
{
}
if (adminConnectorPort.isPresent())
{
{
LocalizableMessage message = ERR_CONFIGDS_PORT_ALREADY_SPECIFIED.get(adminConnectorPort.getIntValue());
return 1;
}
else
{
}
}
{
{
return 1;
}
else
{
}
}
{
{
return 1;
}
else
{
}
}
}
catch (ArgumentException ae)
{
return 1;
}
if (serverRoot.isPresent()) {
try {
} catch (InitializationException e) {
}
}
// Initialize the Directory Server configuration handler using the
// information that was provided.
try
{
}
catch (Exception e)
{
LocalizableMessage message = ERR_CONFIGDS_CANNOT_INITIALIZE_JMX.get(configFile.getValue(), e.getMessage());
return 1;
}
try
{
configFile.getValue());
}
catch (Exception e)
{
LocalizableMessage message = ERR_CONFIGDS_CANNOT_INITIALIZE_CONFIG.get(configFile.getValue(), e.getMessage());
return 1;
}
try
{
}
catch (Exception e)
{
LocalizableMessage message = ERR_CONFIGDS_CANNOT_INITIALIZE_SCHEMA.get(configFile.getValue(), e.getMessage());
return 1;
}
// Make sure that we can get an exclusive lock for the Directory Server, so
// that no other operation will be allowed while this is in progress.
{
LocalizableMessage message = ERR_CONFIGDS_CANNOT_ACQUIRE_SERVER_LOCK.get(serverLockFileName, failureReason);
return 1;
}
try
{
// If one or more base DNs were provided, then make sure that they can be
// parsed as valid DNs.
if (baseDNString.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
LocalizableMessage message = ERR_CONFIGDS_CANNOT_PARSE_BASE_DN.get(dnString, de.getMessageObject());
return 1;
}
}
}
// If a root user DN was provided, then make sure it can be parsed. Also,
// make sure that either a password or password file was specified.
if (rootDNString.isPresent())
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
if (rootPassword.isPresent())
{
}
else if (rootPasswordFile.isPresent())
{
}
else
{
return 1;
}
}
// Get the Directory Server configuration handler and use it to make the
// appropriate configuration changes.
// Check that the key manager provided is valid.
if (keyManagerProviderDN.isPresent())
{
try
{
}
catch (DirectoryException de)
{
de.getMessageObject());
return 1;
}
{
// Create the JCEKSProvider entry
try
{
"objectClass: top\n"+
"objectClass: ds-cfg-key-manager-provider\n"+
"objectClass: ds-cfg-file-based-key-manager-provider\n"+
"cn: JCEKS\n"+
"ds-cfg-java-class: org.opends.server.extensions."+
"FileBasedKeyManagerProvider\n"+
"ds-cfg-enabled: true\n"+
"ds-cfg-key-store-type: JCEKS\n"+
"ds-cfg-key-store-file: config/keystore.jceks\n"+
"ds-cfg-key-store-pin-file: config/keystore.pin";
{
}
}
catch (Exception e)
{
return 1;
}
}
else
{
try
{
}
catch (Exception e)
{
return 1;
}
}
}
// Check that the trust manager provided is valid.
if (trustManagerProviderDN.isPresent())
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
{
try
{
"objectClass: top\n"+
"objectClass: ds-cfg-trust-manager-provider\n"+
"objectClass: ds-cfg-file-based-trust-manager-provider\n"+
"cn: JCEKS\n"+
"ds-cfg-java-class: org.opends.server.extensions."+
"FileBasedTrustManagerProvider\n"+
"ds-cfg-enabled: false\n"+
"ds-cfg-trust-store-type: JCEKS\n"+
"ds-cfg-trust-store-file: config/truststore\n";
{
}
}
catch (Exception e)
{
return 1;
}
}
else
{
try
{
}
catch (Exception e)
{
return 1;
}
}
}
// Check that the keystore path values are valid.
{
return 1;
}
// If one or more base DNs were specified, then update the config
// accordingly.
{
try
{
new DNConfigAttribute(
true, true, false, baseDNs);
}
catch (Exception e)
{
return 1;
}
}
// If an LDAP port was specified, then update the config accordingly.
{
try
{
true, false, true, true, 1, true,
}
catch (Exception e)
{
return 1;
}
}
// If an Admin Connector port was specified, then update the config
// accordingly.
if (adminConnectorPort.isPresent())
{
try
{
true, false, true, true, 1, true,
65535,
}
catch (Exception e)
{
return 1;
}
}
// If an LDAPS port was specified, then update the config accordingly.
{
try
{
true, false, true, true, 1, true,
true, true);
}
catch (Exception e)
{
return 1;
}
}
// If an JMX port was specified, then update the config accordingly.
{
try
{
true, false, true, true, 1, true,
true, true);
}
catch (Exception e)
{
return 1;
}
}
// Start TLS configuration
if (enableStartTLS.isPresent())
{
try
{
true, true);
}
catch (Exception e)
{
return 1;
}
}
// Key manager provider
if (keyManagerProviderDN.isPresent())
{
{
try
{
// Enable the key manager
true, true);
}
catch (Exception e)
{
return 1;
}
}
try
{
if (enableStartTLS.isPresent())
{
// Use the key manager specified for the LDAP connection handler.
false, false, true, keyManagerProviderDN.getValue());
}
{
// Use the key manager specified for the LDAPS connection handler.
false, false,
true, keyManagerProviderDN.getValue());
}
}
catch (Exception e)
{
return 1;
}
if (keyManagerPath.isPresent())
{
try
{
// Enable the key manager
INFO_FILE_KEYMANAGER_DESCRIPTION_FILE.get(), true, true, true,
}
catch (Exception e)
{
return 1;
}
}
}
if (trustManagerProviderDN.isPresent())
{
{
// Enable the trust manager
try
{
true, true);
}
catch (Exception e)
{
return 1;
}
}
try
{
if (enableStartTLS.isPresent())
{
// Use the trust manager specified for the LDAP connection handler.
false, false,
true, trustManagerProviderDN.getValue());
}
{
// Use the trust manager specified for the LDAPS connection handler.
false, false,
true, trustManagerProviderDN.getValue());
}
}
catch (Exception e)
{
return 1;
}
}
if (certNickName.isPresent())
{
try
{
false, false, true, certNickName.getValue());
{
// Use the key manager specified for the LDAP connection handler.
}
else
{
}
// Use the key manager specified for the LDAPS connection handler.
{
}
else
{
}
false, false, true, certNickName.getValue());
// Use the key manager specified for the JMX connection handler.
{
}
else
{
}
}
catch (Exception e)
{
return 1;
}
}
else
{
try
{
// Use the key manager specified for the LDAP connection handler.
// Use the key manager specified for the LDAPS connection handler.
// Use the key manager specified for the JMX connection handler.
}
catch (Exception e)
{
return 1;
}
}
// If a root user DN and password were specified, then update the config
// accordingly.
{
try
{
new DNConfigAttribute(
false, true, false,
rootDN);
false, false, false, encodedPassword);
}
catch (Exception e)
{
return 1;
}
}
// Set the FQDN for the DIGEST-MD5 SASL mechanism.
try
{
}
catch (Exception e)
{
return 1;
}
// Check that the cipher specified is supported. This is intended to
// fix issues with JVM that do not support the default cipher (see
// issue 3075 for instance).
if (p instanceof DefinedDefaultBehaviorProvider)
{
Collection<?> defaultValues =
((DefinedDefaultBehaviorProvider<?>)p).getDefaultValues();
if (!defaultValues.isEmpty())
{
}
}
if (defaultCipher != null)
{
// Check that the default cipher is supported by the JVM.
try
{
}
catch (GeneralSecurityException ex)
{
// The cipher is not supported: try to find an alternative one.
if (alternativeCipher != null)
{
try
{
// Set the alternative cipher
}
catch (Exception e)
{
return 1;
}
}
}
}
// Write the updated configuration.
try
{
}
catch (DirectoryException de)
{
de.getMessageObject());
return 1;
}
}
finally
{
}
// If we've gotten here, then everything was successful.
return 0;
}
/**
* Returns a cipher that is supported by the JVM we are running at.
* Returns <CODE>null</CODE> if no alternative cipher could be found.
* @return a cipher that is supported by the JVM we are running at.
*/
public static String getAlternativeCipher()
{
final String[] preferredAlternativeCiphers =
{
};
{
try
{
break;
}
catch (Throwable t)
{
}
}
return alternativeCipher;
}
}