OPENDJ-1303 Split out CLI support from opendj-ldap-toolkit into a separate Maven module, "opendj-cli"
- Replaced ConnectionUtils.getDefaultLDAPTimeout() by CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT;
- LDAPManagementContextFactory.java : code cleanup - removed unused code.
| | |
| | | */ |
| | | public class ConnectionUtils |
| | | { |
| | | private static final int DEFAULT_LDAP_CONNECT_TIMEOUT = 30000; |
| | | |
| | | private static final String STARTTLS_PROPERTY = |
| | | "org.opends.connectionutils.isstarttls"; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the default LDAP timeout in milliseconds when we try to connect to |
| | | * a server. |
| | | * @return the default LDAP timeout in milliseconds when we try to connect to |
| | | * a server. |
| | | */ |
| | | public static int getDefaultLDAPTimeout() |
| | | { |
| | | return DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | } |
| | | |
| | | /** |
| | | * Returns the String that can be used to represent a given host name in a |
| | | * LDAP URL. |
| | | * This method must be used when we have IPv6 addresses (the address in the |
| | | * LDAP URL must be enclosed with brackets). |
| | | * @param host the host name. |
| | | * @return the String that can be used to represent a given host name in a |
| | | * LDAP URL. This method must be used when we have IPv6 addresses (the address |
| | | * in the LDAP URL must be enclosed with brackets). |
| | | * |
| | | * @param host |
| | | * The host name. |
| | | * @return The String that can be used to represent a given host name in a |
| | | * LDAP URL. |
| | | */ |
| | | public static String getHostNameForLdapUrl(String host) |
| | |
| | | |
| | | import java.util.LinkedHashSet; |
| | | |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.quicksetup.Constants; |
| | | import org.opends.quicksetup.UserData; |
| | |
| | | remoteArg = CommonArguments.getRemote(); |
| | | addArgument(remoteArg); |
| | | |
| | | connectTimeoutArg = |
| | | CommonArguments.getConnectTimeOut(ConnectionUtils |
| | | .getDefaultLDAPTimeout()); |
| | | connectTimeoutArg = CommonArguments.getConnectTimeOut(); |
| | | connectTimeoutArg.setHidden(false); |
| | | addArgument(connectTimeoutArg); |
| | | |
| | |
| | | import org.opends.server.types.LDAPURL; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | |
| | | /** |
| | | * An LDAPConnectionPool is a pool of LDAPConnection. |
| | | * <BR><BR> |
| | |
| | | |
| | | private Control[] requestControls = new Control[] {}; |
| | | private ApplicationTrustManager trustManager; |
| | | private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | private int connectTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the connection passed is registered in the |
| | |
| | | import org.opends.server.tools.ConfigureWindowsService; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | |
| | | /** |
| | | * This is the classes that is shared among all the different places in the |
| | | * Control Panel. It contains information about the server status and |
| | |
| | | private boolean stopPooling; |
| | | private boolean pooling; |
| | | private ApplicationTrustManager trustManager; |
| | | private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | private int connectTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | private ConnectionProtocolPolicy connectionPolicy = |
| | | ConnectionProtocolPolicy.USE_MOST_SECURE_AVAILABLE; |
| | | private String ldapURL; |
| | |
| | | |
| | | import org.opends.admin.ads.ServerDescriptor; |
| | | import org.opends.admin.ads.SuffixDescriptor; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.quicksetup.installer.AuthenticationData; |
| | | import org.opends.quicksetup.installer.DataReplicationOptions; |
| | | import org.opends.quicksetup.installer.NewSuffixOptions; |
| | | import org.opends.quicksetup.installer.SuffixesToReplicateOptions; |
| | | import org.opends.quicksetup.util.Utils; |
| | | |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | |
| | | /** |
| | | * This class is used to provide a data model for the different parameters |
| | | * that the user can provide in the installation wizard. |
| | |
| | | |
| | | private static String defaultHostName; |
| | | |
| | | private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | private int connectTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | |
| | | /** |
| | | * The script name to be used to get and set the java arguments for the |
| | |
| | | import org.opends.server.util.SetupUtils; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | |
| | | import javax.naming.NamingException; |
| | | import javax.naming.ldap.InitialLdapContext; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Map; |
| | | import java.io.BufferedReader; |
| | |
| | | String ldapUrl = "ldaps://"+hostName+":" + port; |
| | | try |
| | | { |
| | | int timeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int timeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | if (application != null) |
| | | { |
| | | if (application.getUserData() != null) |
| | |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.admin.ads.util.ApplicationTrustManager; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.server.admin.AdministrationConnector; |
| | | import org.opends.server.admin.server.ServerManagementContext; |
| | | import org.opends.server.admin.std.server.AdministrationConnectorCfg; |
| | |
| | | certNicknameArg = CommonArguments.getCertNickName(); |
| | | argList.add(certNicknameArg); |
| | | |
| | | connectTimeoutArg = |
| | | CommonArguments.getConnectTimeOut(ConnectionUtils |
| | | .getDefaultLDAPTimeout()); |
| | | connectTimeoutArg = CommonArguments.getConnectTimeOut(); |
| | | connectTimeoutArg.setHidden(false); |
| | | argList.add(connectTimeoutArg); |
| | | |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.quicksetup.Constants; |
| | | import org.opends.quicksetup.Installation; |
| | | import org.opends.quicksetup.UserData; |
| | |
| | | INFO_INSTALLDS_DESCRIPTION_CERT_NICKNAME.get()); |
| | | addDefaultArgument(certNicknameArg); |
| | | |
| | | connectTimeoutArg = |
| | | CommonArguments.getConnectTimeOut(ConnectionUtils |
| | | .getDefaultLDAPTimeout()); |
| | | connectTimeoutArg = CommonArguments.getConnectTimeOut(); |
| | | addArgument(connectTimeoutArg); |
| | | |
| | | acceptLicense = CommonArguments.getAcceptLicense(); |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.server.controls.LDAPAssertionRequestControl; |
| | | import org.opends.server.protocols.ldap.CompareRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.CompareResponseProtocolOp; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.FileBasedArgument; |
| | |
| | | version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION); |
| | | argParser.addArgument(version); |
| | | |
| | | int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int defaultTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT, |
| | | null, OPTION_LONG_CONNECT_TIMEOUT, |
| | | false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(), |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.server.controls.SubtreeDeleteControl; |
| | | import org.opends.server.protocols.ldap.DeleteRequestProtocolOp; |
| | | import org.opends.server.protocols.ldap.DeleteResponseProtocolOp; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.FileBasedArgument; |
| | | import com.forgerock.opendj.cli.IntegerArgument; |
| | |
| | | version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION); |
| | | argParser.addArgument(version); |
| | | |
| | | int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int defaultTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT, |
| | | null, OPTION_LONG_CONNECT_TIMEOUT, |
| | | false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(), |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.server.controls.*; |
| | | import org.opends.server.plugins.ChangeNumberControlPlugin; |
| | | import org.opends.server.protocols.ldap.AddRequestProtocolOp; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.FileBasedArgument; |
| | | import com.forgerock.opendj.cli.IntegerArgument; |
| | |
| | | version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION); |
| | | argParser.addArgument(version); |
| | | |
| | | int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int defaultTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT, |
| | | null, OPTION_LONG_CONNECT_TIMEOUT, |
| | | false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(), |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.opends.server.controls.PasswordPolicyErrorType; |
| | | import org.opends.server.controls.PasswordPolicyResponseControl; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.ConsoleApplication; |
| | | import com.forgerock.opendj.cli.FileBasedArgument; |
| | |
| | | controlStr.setPropertyName("control"); |
| | | argParser.addArgument(controlStr); |
| | | |
| | | int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int defaultTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT, |
| | | null, OPTION_LONG_CONNECT_TIMEOUT, |
| | | false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(), |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.server.controls.*; |
| | | import org.opends.server.protocols.ldap.*; |
| | | import org.opends.server.types.*; |
| | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentParser; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.CommonArguments; |
| | | import com.forgerock.opendj.cli.FileBasedArgument; |
| | | import com.forgerock.opendj.cli.IntegerArgument; |
| | |
| | | version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION); |
| | | argParser.addArgument(version); |
| | | |
| | | int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout(); |
| | | int defaultTimeout = CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; |
| | | connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT, |
| | | null, OPTION_LONG_CONNECT_TIMEOUT, |
| | | false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(), |
| | |
| | | { |
| | | // Interact with the user though the console to get |
| | | // LDAP connection information |
| | | String hostName = ConnectionUtils.getHostNameForLdapUrl(ci.getHostName()); |
| | | Integer portNumber = ci.getPortNumber(); |
| | | String bindDN = ci.getBindDN(); |
| | | String bindPassword = ci.getBindPassword(); |
| | | final String hostName = ConnectionUtils.getHostNameForLdapUrl(ci.getHostName()); |
| | | final Integer portNumber = ci.getPortNumber(); |
| | | final String bindDN = ci.getBindDN(); |
| | | final String bindPassword = ci.getBindPassword(); |
| | | TrustManager trustManager = ci.getTrustManager(); |
| | | KeyManager keyManager = ci.getKeyManager(); |
| | | final KeyManager keyManager = ci.getKeyManager(); |
| | | |
| | | // Do we have a secure connection ? |
| | | final LDAPOptions options = new LDAPOptions(); |
| | | options.setConnectTimeout(ci.getConnectTimeout(), TimeUnit.MILLISECONDS); |
| | | LDAPConnectionFactory factory = null; |
| | | Connection connection; |
| | | if (ci.useSSL()) |
| | | { |
| | | Connection connection = null; |
| | | while (true) |
| | | { |
| | | try |
| | |
| | | catch (ErrorResultException e) |
| | | { |
| | | final Throwable cause = e.getCause(); |
| | | if (app.isInteractive() |
| | | && ci.isTrustStoreInMemory() |
| | | && cause != null |
| | | if (app.isInteractive() && ci.isTrustStoreInMemory() && cause != null |
| | | && cause instanceof SSLException |
| | | && cause.getCause() instanceof CertificateException) |
| | | { |
| | |
| | | { |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT.get(hostName, portNumber)); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { // FIXME The dsconfig is always using secure connection. This code can be |
| | | // removed in this case but statusCli and uninstall are also using it. Cleanup needed. |
| | | // Create the management context. |
| | | try |
| | | { |
| | | factory = new LDAPConnectionFactory(hostName, portNumber, options); |
| | | connection = factory.getConnection(); |
| | | connection.bind(bindDN, bindPassword.toCharArray()); |
| | | } |
| | | catch (ErrorResultException e) |
| | | { |
| | | throw couldNotConnect(e.getCause(), hostName, portNumber, bindDN); |
| | | } |
| | | finally |
| | | { |
| | | if (factory != null) |
| | | { |
| | | factory.close(); |
| | | } |
| | | } finally { |
| | | closeSilently(factory); |
| | | } |
| | | } |
| | | context = |
| | | LDAPManagementContext.newManagementContext(connection, LDAPProfile.getInstance()); |
| | | LDAPManagementContext.newManagementContext(connection, LDAPProfile |
| | | .getInstance()); |
| | | } |
| | | return context; |
| | | } |
| | |
| | | |
| | | import com.forgerock.opendj.cli.Argument; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | import com.forgerock.opendj.cli.StringArgument; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | |
| | | { |
| | | ctx = |
| | | ConnectionUtils.createStartTLSContext(ldapUrl, bindDN, |
| | | bindPassword, ConnectionUtils.getDefaultLDAPTimeout(), null, |
| | | bindPassword, CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT, null, |
| | | trustManager, keyManager, null); |
| | | ctx.reconnect(null); |
| | | break; |
| | |
| | | { |
| | | ctx = |
| | | ConnectionUtils.createLdapContext(ldapUrl, bindDN, bindPassword, |
| | | ConnectionUtils.getDefaultLDAPTimeout(), null); |
| | | CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT, null); |
| | | ctx.reconnect(null); |
| | | break; |
| | | } |
| | |
| | | import static org.opends.messages.ToolMessages.ERR_BUILDVERSION_MALFORMED; |
| | | import static org.opends.messages.ToolMessages.ERR_BUILDVERSION_MISMATCH; |
| | | import static org.opends.server.config.ConfigConstants.CONFIG_DIR_NAME; |
| | | import static org.forgerock.util.Utils.closeSilently; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (final Exception e) |
| | | { |
| | | // Ignore. |
| | | } |
| | | } |
| | | closeSilently(reader); |
| | | } |
| | | } |
| | | |
| | |
| | | this.rev = rev; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public int compareTo(final BuildVersion version) |
| | | { |
| | | if (major == version.major) |
| | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public boolean equals(final Object obj) |
| | | { |
| | | if (this == obj) |
| | |
| | | else if (obj instanceof BuildVersion) |
| | | { |
| | | final BuildVersion other = (BuildVersion) obj; |
| | | return (major == other.major) && (minor == other.minor) |
| | | && (point == other.point) && (rev == other.rev); |
| | | return major == other.major && minor == other.minor |
| | | && point == other.point && rev == other.rev; |
| | | } |
| | | else |
| | | { |
| | |
| | | return rev; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public int hashCode() |
| | | { |
| | | return Arrays.hashCode(new int[] { major, minor, point, (int) (rev >>> 32), |
| | | (int) (rev & 0xFFFFL) }); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | public String toString() |
| | | { |
| | | final StringBuilder builder = new StringBuilder(); |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import com.forgerock.opendj.cli.CliConstants; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | |
| | | "ldaps://" + "127.0.0.1" + ":" |
| | | + String.valueOf(TestCaseUtils.getServerAdminPort()), |
| | | "cn=Directory Manager", "password", |
| | | ConnectionUtils.getDefaultLDAPTimeout(), null, null, null); |
| | | CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT, null, null, null); |
| | | // TODO: should the below dn be in ConfigConstants? |
| | | final String dnStr = "ds-cfg-key-id=ads-certificate,cn=ads-truststore"; |
| | | final LdapName dn = new LdapName(dnStr); |