mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
28.37.2016 ea9450b6eede5663464dbdc1e2bdc1ccc7011509
ReplicationCliMain.java: code cleanup

In promptIfRequired() methods, replaced the use of "cancelled" local boolean variable with early exits.
In both methods from OperationBetweenSourceAndDestinationServers, reverted the meaning of the returned boolean value.
Extracted methods setConnectionDetails(), initializeGlobalArguments(), initializeFirstConnection(), initializeConnection2(),
getPwdFile(), initializeDestinationConnection(), getHostPort(LDAPConnectionConsoleInteraction) and getHostPort2(LDAPConnectionConsoleInteraction).
2 files modified
1001 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java 991 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java
@@ -205,15 +205,13 @@
    }
  }
  private EnableReplicationServerData server1 = new EnableReplicationServerData();
  private EnableReplicationServerData server2 = new EnableReplicationServerData();
  private final EnableReplicationServerData server1 = new EnableReplicationServerData();
  private final EnableReplicationServerData server2 = new EnableReplicationServerData();
  private boolean replicateSchema = true;
  /**
   * Returns <CODE>true</CODE> if the user asked to replicate schema and <CODE>
   * false</CODE> otherwise.
   * @return <CODE>true</CODE> if the user asked to replicate schema and <CODE>
   * false</CODE> otherwise.
   * Returns whether the user asked to replicate schema.
   * @return {@code true} if the user asked to replicate schema, {@code false} otherwise.
   */
  public boolean replicateSchema()
  {
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -278,11 +278,9 @@
     * @param baseDNs user specified baseDNs
     * @param source the source server
     * @param dest the destination server
     * @param interactive if user has to input information
     * @return whether we should stop
     * @return whether we should continue
     */
    boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, ConnectionWrapper dest,
        boolean interactive);
    boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, ConnectionWrapper dest);
    /**
     * Confirm with the user whether the current task should continue.
@@ -291,7 +289,7 @@
     * @param connSource connection to the source server
     * @param connDestination connection to the destination server
     * @param defaultValue default yes or no
     * @return whether the current task should be interrupted
     * @return whether the current task should continue
     */
    boolean confirmOperation(SourceDestinationServerUserData uData, ConnectionWrapper connSource,
        ConnectionWrapper connDestination, final boolean defaultValue);
@@ -350,11 +348,9 @@
   *                           program.
   * @param initializeServer   Indicates whether to initialize the server.
   * @param  outStream         The output stream to use for standard output, or
   *                           <CODE>null</CODE> if standard output is not
   *                           needed.
   *                           {@code null} if standard output is not needed.
   * @param  errStream         The output stream to use for standard error, or
   *                           <CODE>null</CODE> if standard error is not
   *                           needed.
   *                           {@code null} if standard error is not needed.
   * @return The error code.
   */
  public static int mainCLI(String[] args, boolean initializeServer,
@@ -1100,12 +1096,10 @@
  private ConnectionWrapper createConnectionInteracting(LDAPConnectionConsoleInteraction ci,
      boolean promptForCertificate) throws ClientException
  {
    // Interact with the user though the console to get
    // LDAP connection information
    final String hostName = getHostNameForLdapUrl(ci.getHostName());
    final int portNumber = ci.getPortNumber();
    final HostPort hostPort = new HostPort(hostName, portNumber);
    // Interact with the user though the console to get LDAP connection information
    final HostPort hostPort = getHostPort(ci);
    final String hostName = hostPort.getHost();
    final int portNumber = hostPort.getPort();
    if (ci.useSSL())
    {
      while (true)
@@ -1207,13 +1201,21 @@
  private ConnectionWrapper newConnectionWrapper(
      LDAPConnectionConsoleInteraction ci, Type connType, int connectTimeout) throws NamingException
  {
    String hostName = getHostNameForLdapUrl(ci.getHostName());
    int portNumber = ci.getPortNumber();
    HostPort hostPort = new HostPort(hostName, portNumber);
    return new ConnectionWrapper(hostPort, connType, ci.getBindDN(), ci.getBindPassword(),
    return new ConnectionWrapper(getHostPort(ci), connType, ci.getBindDN(), ci.getBindPassword(),
        connectTimeout, ci.getTrustManager(), ci.getKeyManager());
  }
  private HostPort getHostPort(LDAPConnectionConsoleInteraction ci)
  {
    final String hostName = getHostNameForLdapUrl(ci.getHostName());
    return new HostPort(hostName, ci.getPortNumber());
  }
  private HostPort getHostPort2(LDAPConnectionConsoleInteraction ci)
  {
    return new HostPort(ci.getHostName(), ci.getPortNumber());
  }
  private String getAuthType(TrustManager trustManager)
  {
    if (trustManager instanceof ApplicationTrustManager)
@@ -1278,8 +1280,7 @@
        resetChangeNumberOperations = new OperationBetweenSourceAndDestinationServers()
    {
      @Override
      public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source,
          ConnectionWrapper dest, boolean interactive)
      public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, ConnectionWrapper dest)
      {
        TopologyCacheFilter filter = new TopologyCacheFilter();
        filter.setSearchMonitoringInformation(false);
@@ -1289,20 +1290,20 @@
          String cn = getNewestChangeNumber(source);
          if (cn.isEmpty())
          {
            return true;
            return false;
          }
          argParser.setResetChangeNumber(
              ask(logger, INFO_RESET_CHANGE_NUMBER_TO.get(uData.getSource(), uData.getDestination()), cn));
        }
        return false;
        return true;
      }
      @Override
      public boolean confirmOperation(SourceDestinationServerUserData uData, ConnectionWrapper connSource,
          ConnectionWrapper connDestination, boolean defaultValue)
      {
        return !askConfirmation(INFO_RESET_CHANGE_NUMBER_CONFIRM_RESET.get(uData.getDestinationHostPort()),
            defaultValue);
        LocalizableMessage promptMsg = INFO_RESET_CHANGE_NUMBER_CONFIRM_RESET.get(uData.getDestinationHostPort());
        return askConfirmation(promptMsg, defaultValue);
      }
    };
@@ -1829,18 +1830,17 @@
        initializeReplicationOperations = new OperationBetweenSourceAndDestinationServers()
    {
      @Override
      public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source,
          ConnectionWrapper dest, boolean interactive)
      public boolean continueAfterUserInput(Collection<DN> baseDNs, ConnectionWrapper source, ConnectionWrapper dest)
      {
        checkSuffixesForInitializeReplication(baseDNs, source, dest, interactive);
        return baseDNs.isEmpty();
        checkSuffixesForInitializeReplication(baseDNs, source, dest, true);
        return !baseDNs.isEmpty();
      }
      @Override
      public boolean confirmOperation(SourceDestinationServerUserData uData, ConnectionWrapper connSource,
          ConnectionWrapper connDestination, boolean defaultValue)
      {
        return !askConfirmation(getInitializeReplicationPrompt(uData, connSource, connDestination), defaultValue);
        return askConfirmation(getInitializeReplicationPrompt(uData, connSource, connDestination), defaultValue);
      }
    };
    return promptIfRequired(uData, initializeReplicationOperations) ? initializeReplication(uData) : USER_CANCELLED;
@@ -1852,20 +1852,19 @@
   * information is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user canceled the operation.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user canceled the operation.
   */
  private boolean promptIfRequired(PurgeHistoricalUserData uData)
  {
    ConnectionWrapper conn = null;
    try
    {
      conn = getConnection(uData);
    ConnectionWrapper conn = getConnection(uData);
      if (conn == null)
      {
        return false;
      }
    try
    {
      /* Prompt for maximum duration */
      int maximumDuration = argParser.getMaximumDuration();
      if (!argParser.maximumDurationArg.isPresent())
@@ -1920,26 +1919,18 @@
  private ConnectionWrapper getConnection(PurgeHistoricalUserData uData)
  {
    boolean firstTry = true;
    Boolean serverRunning = null;
    boolean serverRunning = Utilities.isServerRunning(Installation.getLocal().getInstanceDirectory());
    boolean firstTry = true;
    while (true)
    {
      boolean promptForConnection = firstTry && argParser.connectionArgumentsPresent();
      if (!promptForConnection)
      {
        if (serverRunning == null)
        {
          serverRunning = Utilities.isServerRunning(Installation.getLocal().getInstanceDirectory());
        }
        if (!serverRunning)
      if (!promptForConnection && !serverRunning)
        {
          try
          {
            println();
            promptForConnection = !askConfirmation(
                INFO_REPLICATION_PURGE_HISTORICAL_LOCAL_PROMPT.get(), true, logger);
          promptForConnection = !askConfirmation(INFO_REPLICATION_PURGE_HISTORICAL_LOCAL_PROMPT.get(), true, logger);
          }
          catch (ClientException ce)
          {
@@ -1952,7 +1943,6 @@
            return null;
          }
        }
      }
      try
      {
@@ -1962,7 +1952,7 @@
        if (conn != null)
        {
          uData.setOnline(true);
          uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber()));
          uData.setHostPort(getHostPort2(sourceServerCI));
          uData.setAdminUid(sourceServerCI.getAdministratorUID());
          uData.setAdminPwd(sourceServerCI.getBindPassword());
        }
@@ -2005,64 +1995,30 @@
   * is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @throws ReplicationCliException if a critical error occurs reading the
   * ADS.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   * @throws ReplicationCliException if a critical error occurs reading the ADS.
   */
  private boolean promptIfRequired(EnableReplicationUserData uData)
  throws ReplicationCliException
  private boolean promptIfRequired(EnableReplicationUserData uData) throws ReplicationCliException
  {
    boolean cancelled = false;
    boolean administratorDefined = false;
    sourceServerCI.setUseAdminOrBindDn(true);
    ConnectionWrapper conn1 = null;
    ConnectionWrapper conn2 = null;
    try
    {
    String adminPwd = argParser.getBindPasswordAdmin();
    String adminUid = argParser.getAdministratorUID();
    /* Try to connect to the first server. */
    String host1 = getValue(argParser.server1.hostNameArg);
    int port1 = getValue(argParser.server1.portArg);
    String bindDn1 = getValue(argParser.server1.bindDnArg);
    String pwd1 = argParser.server1.getBindPassword();
    String pwd = null;
    Map<String, String> pwdFile = null;
    if (argParser.server1.bindPasswordArg.isPresent())
      initializeGlobalArguments(sourceServerCI, argParser.server1, adminPwd, adminUid);
      conn1 = initializeFirstConnection(INFO_REPLICATION_ENABLE_HOST1_CONNECTION_PARAMETERS.get());
      if (conn1 == null)
    {
      pwd = argParser.server1.bindPasswordArg.getValue();
    }
    else if (argParser.server1.bindPasswordFileArg.isPresent())
    {
      pwdFile = argParser.server1.bindPasswordFileArg.getNameToValueMap();
    }
    else if (bindDn1 == null)
    {
      pwd = adminPwd;
      if (argParser.getSecureArgsList().getBindPasswordFileArg().isPresent())
      {
        pwdFile = argParser.getSecureArgsList().getBindPasswordFileArg().
          getNameToValueMap();
      }
        return false;
    }
    /*
     * Use a copy of the argument properties since the map might be cleared
     * in initializeGlobalArguments.
     */
    sourceServerCI.initializeGlobalArguments(host1, port1, adminUid, bindDn1, pwd,
        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
    ConnectionWrapper conn1 = null;
    while (conn1 == null && !cancelled)
    {
      try
      {
        sourceServerCI.setHeadingMessage(INFO_REPLICATION_ENABLE_HOST1_CONNECTION_PARAMETERS.get());
        sourceServerCI.run();
        host1 = sourceServerCI.getHostName();
        port1 = sourceServerCI.getPortNumber();
        if (sourceServerCI.getProvidedAdminUID() != null)
        {
          adminUid = sourceServerCI.getProvidedAdminUID();
@@ -2074,42 +2030,16 @@
            adminPwd = sourceServerCI.getBindPassword();
          }
        }
        bindDn1 = sourceServerCI.getBindDN();
        pwd1 = sourceServerCI.getBindPassword();
        conn1 = createConnectionInteracting(sourceServerCI);
        if (conn1 == null)
        {
          cancelled = true;
        }
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Client exception "+ce));
        errPrintln();
        errPrintln(ce.getMessageObject());
        errPrintln();
        sourceServerCI.resetConnectionArguments();
      }
      catch (ArgumentException ae)
      {
        logger.warn(LocalizableMessage.raw("Argument exception "+ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        cancelled = true;
      }
    }
      String host1 = sourceServerCI.getHostName();
      int port1 = sourceServerCI.getPortNumber();
      setConnectionDetails(uData.getServer1(), sourceServerCI);
    if (!cancelled)
    {
      uData.getServer1().setHostPort(new HostPort(host1, port1));
      uData.getServer1().setBindDn(bindDn1);
      uData.getServer1().setPwd(pwd1);
    }
      boolean administratorDefined = false;
    int replicationPort1 = -1;
    boolean secureReplication1 = argParser.server1.secureReplicationArg.isPresent();
    boolean configureReplicationServer1 = argParser.server1.configureReplicationServer();
    boolean configureReplicationDomain1 = argParser.server1.configureReplicationDomain();
    if (conn1 != null)
    {
      int repPort1 = getReplicationPort(conn1);
      boolean replicationServer1Configured = repPort1 > 0;
@@ -2119,13 +2049,12 @@
            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(conn1.getHostPort(), repPort1);
        if (!askConfirmation(msg, false))
        {
          cancelled = true;
            return false;
        }
      }
      // Try to get the replication port for server 1 only if it is required.
      if (!cancelled
          && configureReplicationServer1
        if (configureReplicationServer1
          && !replicationServer1Configured
          && argParser.advancedArg.isPresent()
          && configureReplicationDomain1)
@@ -2134,19 +2063,16 @@
        // the replication server MUST be configured).
        try
        {
          configureReplicationServer1 = askConfirmation(
              INFO_REPLICATION_ENABLE_REPLICATION_SERVER1_PROMPT.get(),
              true, logger);
            configureReplicationServer1 =
                askConfirmation(INFO_REPLICATION_ENABLE_REPLICATION_SERVER1_PROMPT.get(), true, logger);
        }
        catch (ClientException ce)
        {
          errPrintln(ce.getMessageObject());
          cancelled = true;
            return false;
        }
      }
      if (!cancelled
          && configureReplicationServer1
          && !replicationServer1Configured)
        if (configureReplicationServer1 && !replicationServer1Configured)
      {
        boolean tryWithDefault = argParser.getReplicationPort1() != -1;
        while (replicationPort1 == -1)
@@ -2158,9 +2084,9 @@
          }
          else
          {
            replicationPort1 = askPort(
                INFO_REPLICATION_ENABLE_REPLICATIONPORT1_PROMPT.get(),
                getDefaultValue(argParser.server1.replicationPortArg), logger);
              replicationPort1 =
                  askPort(INFO_REPLICATION_ENABLE_REPLICATIONPORT1_PROMPT.get(), getDefaultValue(
                      argParser.server1.replicationPortArg), logger);
            println();
          }
          if (!argParser.skipReplicationPortCheck() && isLocalHost(host1))
@@ -2188,33 +2114,28 @@
          try
          {
            secureReplication1 =
              askConfirmation(INFO_REPLICATION_ENABLE_SECURE1_PROMPT.get(replicationPort1),
                  false, logger);
                  askConfirmation(INFO_REPLICATION_ENABLE_SECURE1_PROMPT.get(replicationPort1), false, logger);
          }
          catch (ClientException ce)
          {
            errPrintln(ce.getMessageObject());
            cancelled = true;
              return false;
          }
          println();
        }
      }
      if (!cancelled &&
          configureReplicationDomain1 &&
          configureReplicationServer1 &&
          argParser.advancedArg.isPresent())
        if (configureReplicationDomain1 && configureReplicationServer1 && argParser.advancedArg.isPresent())
      {
        // Only necessary to ask if the replication server will be configured
        try
        {
          configureReplicationDomain1 = askConfirmation(
              INFO_REPLICATION_ENABLE_REPLICATION_DOMAIN1_PROMPT.get(),
              true, logger);
            configureReplicationDomain1 =
                askConfirmation(INFO_REPLICATION_ENABLE_REPLICATION_DOMAIN1_PROMPT.get(), true, logger);
        }
        catch (ClientException ce)
        {
          errPrintln(ce.getMessageObject());
          cancelled = true;
            return false;
        }
      }
      // If the server contains an ADS. Try to load it and only load it: if
@@ -2222,21 +2143,19 @@
      // enableReplication(EnableReplicationUserData) method.  Here we have
      // to load the ADS to ask the user to accept the certificates and
      // eventually admin authentication data.
      if (!cancelled)
      {
        AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(conn1);
        cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, true);
        conn1 = aux.get();
      }
      if (!cancelled)
        if (!loadADSAndAcceptCertificates(sourceServerCI, aux, uData, true))
      {
          return false;
        }
        conn1 = aux.get();
        administratorDefined |= hasAdministrator(conn1);
        if (uData.getAdminPwd() != null)
        {
          adminPwd = uData.getAdminPwd();
        }
      }
    }
    uData.getServer1().setReplicationPort(replicationPort1);
    uData.getServer1().setSecureReplication(secureReplication1);
    uData.getServer1().setConfigureReplicationServer(configureReplicationServer1);
@@ -2248,62 +2167,18 @@
    }
    /* Prompt for information on the second server. */
    String host2 = null;
    int port2 = -1;
    String bindDn2 = null;
    String pwd2 = null;
    LDAPConnectionConsoleInteraction destinationServerCI = new LDAPConnectionConsoleInteraction(this,
        argParser.getSecureArgsList());
    destinationServerCI.resetHeadingDisplayed();
    boolean doNotDisplayFirstError = false;
    if (!cancelled)
    {
      host2 = getValue(argParser.server2.hostNameArg);
      port2 = getValue(argParser.server2.portArg);
      bindDn2 = getValue(argParser.server2.bindDnArg);
      pwd2 = argParser.server2.getBindPassword();
      pwdFile = null;
      pwd = null;
      if (argParser.server2.bindPasswordArg.isPresent())
      {
        pwd = argParser.server2.bindPasswordArg.getValue();
      }
      else if (argParser.server2.bindPasswordFileArg.isPresent())
      {
        pwdFile = argParser.server2.bindPasswordFileArg.getNameToValueMap();
      }
      else if (bindDn2 == null)
      {
        doNotDisplayFirstError = true;
        pwd = adminPwd;
        if (argParser.getSecureArgsList().getBindPasswordFileArg().isPresent())
        {
          pwdFile = argParser.getSecureArgsList().getBindPasswordFileArg().
            getNameToValueMap();
        }
      }
      /*
       * Use a copy of the argument properties since the map might be cleared
       * in initializeGlobalArguments.
       */
      destinationServerCI.initializeGlobalArguments(host2, port2, adminUid, bindDn2, pwd,
          pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
      LDAPConnectionConsoleInteraction destinationServerCI =
          new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList());
      boolean doNotDisplayFirstError =
          initializeGlobalArguments(destinationServerCI, argParser.server2, adminPwd, adminUid);
      destinationServerCI.setUseAdminOrBindDn(true);
      conn2 = initializeConnection2(destinationServerCI, sourceServerCI, doNotDisplayFirstError);
      if (conn2 == null)
      {
        return false;
    }
    ConnectionWrapper conn2 = null;
    while (conn2 == null && !cancelled)
    {
      try
      {
        destinationServerCI.setHeadingMessage(INFO_REPLICATION_ENABLE_HOST2_CONNECTION_PARAMETERS.get());
        destinationServerCI.run();
        host2 = destinationServerCI.getHostName();
        port2 = destinationServerCI.getPortNumber();
        if (destinationServerCI.getProvidedAdminUID() != null)
        {
          adminUid = destinationServerCI.getProvidedAdminUID();
@@ -2315,69 +2190,15 @@
            adminPwd = destinationServerCI.getBindPassword();
          }
        }
        bindDn2 = destinationServerCI.getBindDN();
        pwd2 = destinationServerCI.getBindPassword();
        boolean error = false;
        if (host1.equalsIgnoreCase(host2) && port1 == port2)
        {
          port2 = -1;
          errPrintln();
          errPrintln(ERR_REPLICATION_ENABLE_SAME_SERVER_PORT.get(host1, port1));
          errPrintln();
          error = true;
        }
        if (!error)
        {
          conn2 = createConnectionInteracting(destinationServerCI, true);
          if (conn2 == null)
          {
            cancelled = true;
          }
        }
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Client exception "+ce));
        if (!doNotDisplayFirstError)
        {
          errPrintln();
          errPrintln(ce.getMessageObject());
          errPrintln();
          destinationServerCI.resetConnectionArguments();
        }
        else
        {
          // Reset only the credential parameters.
          destinationServerCI.resetConnectionArguments();
          destinationServerCI.initializeGlobalArguments(host2, port2, null, null, null, null);
        }
      }
      catch (ArgumentException ae)
      {
        logger.warn(LocalizableMessage.raw("Argument exception "+ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        cancelled = true;
      }
      finally
      {
        doNotDisplayFirstError = false;
      }
    }
    if (!cancelled)
    {
      uData.getServer2().setHostPort(new HostPort(host2, port2));
      uData.getServer2().setBindDn(bindDn2);
      uData.getServer2().setPwd(pwd2);
    }
      String host2 = destinationServerCI.getHostName();
      int port2 = destinationServerCI.getPortNumber();
      setConnectionDetails(uData.getServer2(), destinationServerCI);
    int replicationPort2 = -1;
    boolean secureReplication2 = argParser.server2.secureReplicationArg.isPresent();
    boolean configureReplicationServer2 = argParser.server2.configureReplicationServer();
    boolean configureReplicationDomain2 = argParser.server2.configureReplicationDomain();
    if (conn2 != null)
    {
      int repPort2 = getReplicationPort(conn2);
      boolean replicationServer2Configured = repPort2 > 0;
@@ -2387,35 +2208,29 @@
            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(conn2.getHostPort(), repPort2);
        if (!askConfirmation(prompt, false))
        {
          cancelled = true;
            return false;
        }
      }
      // Try to get the replication port for server 2 only if it is required.
      if (!cancelled
          && configureReplicationServer2
          && !replicationServer2Configured)
        if (configureReplicationServer2 && !replicationServer2Configured)
      {
        // Only ask if the replication domain will be configured (if not the
        // replication server MUST be configured).
        if (argParser.advancedArg.isPresent() &&
            configureReplicationDomain2)
          if (argParser.advancedArg.isPresent() && configureReplicationDomain2)
        {
          try
          {
            configureReplicationServer2 = askConfirmation(
                INFO_REPLICATION_ENABLE_REPLICATION_SERVER2_PROMPT.get(),
                true, logger);
              configureReplicationServer2 =
                  askConfirmation(INFO_REPLICATION_ENABLE_REPLICATION_SERVER2_PROMPT.get(), true, logger);
          }
          catch (ClientException ce)
          {
            errPrintln(ce.getMessageObject());
            cancelled = true;
              return false;
          }
        }
        if (!cancelled
            && configureReplicationServer2
            && !replicationServer2Configured)
          if (configureReplicationServer2 && !replicationServer2Configured)
        {
          boolean tryWithDefault = argParser.getReplicationPort2() != -1;
          while (replicationPort2 == -1)
@@ -2427,13 +2242,12 @@
            }
            else
            {
              replicationPort2 = askPort(
                  INFO_REPLICATION_ENABLE_REPLICATIONPORT2_PROMPT.get(),
                  getDefaultValue(argParser.server2.replicationPortArg), logger);
                replicationPort2 =
                    askPort(INFO_REPLICATION_ENABLE_REPLICATIONPORT2_PROMPT.get(), getDefaultValue(
                        argParser.server2.replicationPortArg), logger);
              println();
            }
            if (!argParser.skipReplicationPortCheck() &&
                isLocalHost(host2))
              if (!argParser.skipReplicationPortCheck() && isLocalHost(host2))
            {
              if (!SetupUtils.canUseAsPort(replicationPort2))
              {
@@ -2451,9 +2265,7 @@
              errPrintln(ERR_REPLICATION_PORT_AND_REPLICATION_PORT_EQUAL.get(host2, replicationPort2));
              replicationPort2 = -1;
            }
            if (host1.equalsIgnoreCase(host2)
                && replicationPort1 > 0
                && replicationPort1 == replicationPort2)
              if (host1.equalsIgnoreCase(host2) && replicationPort1 > 0 && replicationPort1 == replicationPort2)
            {
              errPrintln();
              errPrintln(ERR_REPLICATION_SAME_REPLICATION_PORT.get(replicationPort2, host1));
@@ -2471,44 +2283,37 @@
            catch (ClientException ce)
            {
              errPrintln(ce.getMessageObject());
              cancelled = true;
                return false;
            }
            println();
          }
        }
      }
      if (!cancelled &&
          configureReplicationDomain2 &&
          configureReplicationServer2 &&
          argParser.advancedArg.isPresent())
        if (configureReplicationDomain2 && configureReplicationServer2 && argParser.advancedArg.isPresent())
      {
        // Only necessary to ask if the replication server will be configured
        try
        {
          configureReplicationDomain2 = askConfirmation(
              INFO_REPLICATION_ENABLE_REPLICATION_DOMAIN2_PROMPT.get(),
              true, logger);
            configureReplicationDomain2 =
                askConfirmation(INFO_REPLICATION_ENABLE_REPLICATION_DOMAIN2_PROMPT.get(), true, logger);
        }
        catch (ClientException ce)
        {
          errPrintln(ce.getMessageObject());
          cancelled = true;
            return false;
        }
      }
      // If the server contains an ADS. Try to load it and only load it: if
      // there are issues with the ADS they will be encountered in the
      // enableReplication(EnableReplicationUserData) method.  Here we have
      // to load the ADS to ask the user to accept the certificates.
      if (!cancelled)
      {
        AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(conn2);
        cancelled = !loadADSAndAcceptCertificates(destinationServerCI, aux, uData, false);
        conn2 = aux.get();
      }
      if (!cancelled)
        if (!loadADSAndAcceptCertificates(destinationServerCI, aux, uData, false))
      {
        administratorDefined |= hasAdministrator(conn2);
          return false;
      }
        conn2 = aux.get();
        administratorDefined |= hasAdministrator(conn2);
    }
    uData.getServer2().setReplicationPort(replicationPort2);
    uData.getServer2().setSecureReplication(secureReplication2);
@@ -2525,14 +2330,13 @@
    // credentials even if the administrators are defined: where all the servers
    // can be accessed with another user (for instance if all the server have
    // defined cn=directory manager and all the entries have the same password).
    if (!cancelled && uData.getAdminUid() == null && !administratorDefined)
      if (uData.getAdminUid() == null && !administratorDefined)
    {
      if (adminUid == null)
      {
        println(INFO_REPLICATION_ENABLE_ADMINISTRATOR_MUST_BE_CREATED.get());
        promptedForAdmin = true;
        adminUid= askForAdministratorUID(
            getDefaultValue(argParser.getAdminUidArg()), logger);
          adminUid = askForAdministratorUID(getDefaultValue(argParser.getAdminUidArg()), logger);
        println();
      }
      uData.setAdminUid(adminUid);
@@ -2542,7 +2346,7 @@
    {
      uData.setAdminPwd(adminPwd);
    }
    if (!cancelled && uData.getAdminPwd() == null && !administratorDefined)
      if (uData.getAdminPwd() == null && !administratorDefined)
    {
      adminPwd = null;
      int nPasswordPrompts = 0;
@@ -2550,10 +2354,8 @@
      {
        if (nPasswordPrompts > CONFIRMATION_MAX_TRIES)
        {
          errPrintln(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get(
              CONFIRMATION_MAX_TRIES));
          cancelled = true;
          break;
            errPrintln(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get(CONFIRMATION_MAX_TRIES));
            return false;
        }
        nPasswordPrompts ++;
        if (!promptedForAdmin)
@@ -2591,65 +2393,64 @@
      uData.setAdminPwd(adminPwd);
    }
    if (!cancelled)
    {
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      checkSuffixesForEnableReplication(suffixes, conn1, conn2, true, uData);
      cancelled = suffixes.isEmpty();
      uData.setBaseDNs(suffixes);
      return !suffixes.isEmpty();
    }
    finally
    {
    close(conn1, conn2);
    uData.setReplicateSchema(!argParser.noSchemaReplication());
    return !cancelled;
    }
  }
  /**
   * Updates the contents of the provided DisableReplicationUserData object
   * with the information provided in the command-line.  If some information
   * is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @throws ReplicationCliException if there is a critical error reading the
   * ADS.
   */
  private boolean promptIfRequired(DisableReplicationUserData uData) throws ReplicationCliException
  private boolean initializeGlobalArguments(LDAPConnectionConsoleInteraction serverCI, ServerArgs serverArgs,
      String adminPwd, String adminUid)
  {
    boolean cancelled = false;
    boolean doNotDisplayFirstError = false;
    String host = getValue(serverArgs.hostNameArg);
    int port = getValue(serverArgs.portArg);
    String bindDn = getValue(serverArgs.bindDnArg);
    String adminPwd = argParser.getBindPasswordAdmin();
    String adminUid = argParser.getAdministratorUID();
    String bindDn = argParser.getBindDNToDisable();
    String pwd = null;
    LinkedHashMap<String, String> pwdFile = null;
    if (serverArgs.bindPasswordArg.isPresent())
    {
      pwd = serverArgs.bindPasswordArg.getValue();
    }
    else if (serverArgs.bindPasswordFileArg.isPresent())
    {
      pwdFile = new LinkedHashMap<>(serverArgs.bindPasswordFileArg.getNameToValueMap());
    }
    else if (bindDn == null)
    {
      doNotDisplayFirstError = true;
      pwd = adminPwd;
      pwdFile = getPwdFile();
    }
    // This is done because we want to ask explicitly for this
    serverCI.initializeGlobalArguments(host, port, adminUid, bindDn, pwd, pwdFile);
    return doNotDisplayFirstError;
  }
    String host = argParser.getHostNameToDisable();
    int port = argParser.getPortToDisable();
  private void setConnectionDetails(EnableReplicationServerData serverData, LDAPConnectionConsoleInteraction serverCI)
  {
    serverData.setHostPort(getHostPort2(serverCI));
    serverData.setBindDn(serverCI.getBindDN());
    serverData.setPwd(serverCI.getBindPassword());
  }
    /* Try to connect to the server. */
    ConnectionWrapper conn = null;
    while (conn == null && !cancelled)
  private ConnectionWrapper initializeFirstConnection(LocalizableMessage headingMsg)
  {
    while (true)
    {
      try
      {
        sourceServerCI.setUseAdminOrBindDn(true);
        sourceServerCI.setHeadingMessage(headingMsg);
        sourceServerCI.run();
        host = sourceServerCI.getHostName();
        port = sourceServerCI.getPortNumber();
        bindDn = sourceServerCI.getProvidedBindDN();
        adminUid = sourceServerCI.getProvidedAdminUID();
        adminPwd = sourceServerCI.getBindPassword();
        conn = createConnectionInteracting(sourceServerCI);
        if (conn == null)
        {
          cancelled = true;
        }
        return createConnectionInteracting(sourceServerCI);
      }
      catch (ClientException ce)
      {
@@ -2663,18 +2464,93 @@
      {
        logger.warn(LocalizableMessage.raw("Argument exception "+ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        cancelled = true;
        return null;
      }
      }
    }
    if (!cancelled)
  private ConnectionWrapper initializeConnection2(LDAPConnectionConsoleInteraction destinationServerCI,
      LDAPConnectionConsoleInteraction sourceServerCI, boolean doNotDisplayFirstError)
    {
      uData.setHostPort(new HostPort(host, port));
      uData.setAdminUid(adminUid);
      uData.setBindDn(bindDn);
      uData.setAdminPwd(adminPwd);
    destinationServerCI.resetHeadingDisplayed();
    while (true)
    {
      try
      {
        destinationServerCI.setHeadingMessage(INFO_REPLICATION_ENABLE_HOST2_CONNECTION_PARAMETERS.get());
        destinationServerCI.run();
        String host1 = sourceServerCI.getHostName();
        int port1 = sourceServerCI.getPortNumber();
        if (host1.equalsIgnoreCase(destinationServerCI.getHostName())
            && port1 == destinationServerCI.getPortNumber())
        {
          errPrintln();
          errPrintln(ERR_REPLICATION_ENABLE_SAME_SERVER_PORT.get(host1, port1));
          errPrintln();
          return null;
    }
    if (conn != null && adminUid != null)
        return createConnectionInteracting(destinationServerCI, true);
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Client exception " + ce));
        if (!doNotDisplayFirstError)
        {
          errPrintln();
          errPrintln(ce.getMessageObject());
          errPrintln();
          destinationServerCI.resetConnectionArguments();
        }
        else
        {
          // Reset only the credential parameters.
          destinationServerCI.resetConnectionArguments();
          destinationServerCI.initializeGlobalArguments(
              destinationServerCI.getHostName(), destinationServerCI.getPortNumber(), null, null, null, null);
        }
      }
      catch (ArgumentException ae)
      {
        logger.warn(LocalizableMessage.raw("Argument exception " + ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        return null;
      }
      finally
      {
        doNotDisplayFirstError = false;
      }
    }
  }
  /**
   * Updates the contents of the provided DisableReplicationUserData object
   * with the information provided in the command-line.  If some information
   * is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   * @throws ReplicationCliException if there is a critical error reading the ADS.
   */
  private boolean promptIfRequired(DisableReplicationUserData uData) throws ReplicationCliException
  {
    ConnectionWrapper conn = createConnection();
    if (conn == null)
    {
      return false;
    }
    try
    {
      final String adminUid = sourceServerCI.getProvidedAdminUID();
      uData.setHostPort(getHostPort2(sourceServerCI));
      uData.setAdminUid(adminUid);
      uData.setBindDn(sourceServerCI.getProvidedBindDN());
      uData.setAdminPwd(sourceServerCI.getBindPassword());
      if (adminUid != null)
    {
      // If the server contains an ADS, try to load it and only load it: if
      // there are issues with the ADS they will be encountered in the
@@ -2682,96 +2558,103 @@
      // to load the ADS to ask the user to accept the certificates and
      // eventually admin authentication data.
      AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(conn);
      cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false);
        if (!loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false))
        {
          return false;
        }
      conn = aux.get();
    }
    boolean disableAll = argParser.disableAllArg.isPresent();
    boolean disableReplicationServer =
      argParser.disableReplicationServerArg.isPresent();
    if (disableAll ||
        (argParser.advancedArg.isPresent() &&
        argParser.getBaseDNs().isEmpty() &&
        !disableReplicationServer))
      boolean disableReplicationServer = argParser.disableReplicationServerArg.isPresent();
      if (disableAll
          || (argParser.advancedArg.isPresent()
              && argParser.getBaseDNs().isEmpty()
              && !disableReplicationServer))
    {
      try
      {
        disableAll = askConfirmation(INFO_REPLICATION_PROMPT_DISABLE_ALL.get(),
          disableAll, logger);
          disableAll = askConfirmation(INFO_REPLICATION_PROMPT_DISABLE_ALL.get(), disableAll, logger);
      }
      catch (ClientException ce)
      {
        errPrintln(ce.getMessageObject());
        cancelled = true;
          return false;
      }
    }
    int repPort = getReplicationPort(conn);
    if (!disableAll
        && (argParser.advancedArg.isPresent() || disableReplicationServer)
        && repPort > 0)
          && repPort > 0
          && (argParser.advancedArg.isPresent() || disableReplicationServer))
    {
      try
      {
        disableReplicationServer = askConfirmation(
            INFO_REPLICATION_PROMPT_DISABLE_REPLICATION_SERVER.get(repPort),
            disableReplicationServer,
            logger);
          LocalizableMessage prompt = INFO_REPLICATION_PROMPT_DISABLE_REPLICATION_SERVER.get(repPort);
          disableReplicationServer = askConfirmation(prompt, disableReplicationServer, logger);
      }
      catch (ClientException ce)
      {
        errPrintln(ce.getMessageObject());
        cancelled = true;
          return false;
      }
    }
    if (disableReplicationServer && repPort < 0)
    {
      disableReplicationServer = false;
      final LocalizableMessage msg = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(conn.getHostPort());
      try
      {
        cancelled = askConfirmation(msg, false, logger);
          LocalizableMessage prompt = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(conn.getHostPort());
          if (!askConfirmation(prompt, false, logger))
          {
            return false;
          }
      }
      catch (ClientException ce)
      {
        errPrintln(ce.getMessageObject());
        cancelled = true;
          return false;
      }
    }
    if (repPort > 0 && disableAll)
    {
      disableReplicationServer = true;
    }
    uData.setDisableAll(disableAll);
    uData.setDisableReplicationServer(disableReplicationServer);
    if (!cancelled && !disableAll)
      if (!disableAll)
    {
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      checkSuffixesForDisableReplication(suffixes, conn, true, !disableReplicationServer);
      cancelled = suffixes.isEmpty() && !disableReplicationServer;
        if (suffixes.isEmpty() && !disableReplicationServer)
        {
          return false;
        }
      uData.setBaseDNs(suffixes);
      if (!uData.disableReplicationServer() && repPort > 0
        if (!uData.disableReplicationServer()
            && repPort > 0
          && disableAllBaseDns(conn, uData)
          && !argParser.advancedArg.isPresent())
      {
        try
        {
          uData.setDisableReplicationServer(askConfirmation(
              INFO_REPLICATION_DISABLE_ALL_SUFFIXES_DISABLE_REPLICATION_SERVER.get(
                  conn.getHostPort(), repPort), true,
              logger));
            LocalizableMessage prompt =
                INFO_REPLICATION_DISABLE_ALL_SUFFIXES_DISABLE_REPLICATION_SERVER.get(conn.getHostPort(), repPort);
            uData.setDisableReplicationServer(askConfirmation(prompt, true, logger));
        }
        catch (ClientException ce)
        {
          errPrintln(ce.getMessageObject());
          cancelled = true;
            return false;
        }
      }
    }
    if (!cancelled)
    {
      // Ask for confirmation to disable if not already done.
      boolean disableADS = false;
      boolean disableSchema = false;
@@ -2786,6 +2669,8 @@
          disableSchema = true;
        }
      }
      boolean cancelled = false;
      if (disableADS)
      {
        println();
@@ -2809,11 +2694,39 @@
        }
        println();
      }
      return !cancelled;
    }
    finally
    {
      close(conn);
    }
    }
    close(conn);
    return !cancelled;
  private ConnectionWrapper createConnection()
  {
    while (true)
    {
      try
      {
        sourceServerCI.setUseAdminOrBindDn(true);
        sourceServerCI.run();
        return createConnectionInteracting(sourceServerCI);
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Client exception " + ce));
        errPrintln();
        errPrintln(ce.getMessageObject());
        errPrintln();
        sourceServerCI.resetConnectionArguments();
      }
      catch (ArgumentException ae)
      {
        logger.warn(LocalizableMessage.raw("Argument exception " + ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        return null;
      }
    }
  }
  /**
@@ -2822,18 +2735,20 @@
   * information is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   */
  private boolean promptIfRequired(InitializeAllReplicationUserData uData)
  {
    try (ConnectionWrapper conn = getConnection(uData))
    {
    ConnectionWrapper conn = getConnection(uData);
      if (conn == null)
      {
        return false;
      }
    try
    {
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      checkSuffixesForInitializeReplication(suffixes, conn, true);
      if (suffixes.isEmpty())
@@ -2844,12 +2759,13 @@
      // Ask for confirmation to initialize.
      println();
      if (!askConfirmation(getPrompt(uData, conn), true))
      {
        return false;
      }
      final boolean cancelled = !askConfirmation(getPrompt(uData, conn), true);
      println();
      return true;
      return !cancelled;
    }
    finally
    {
      close(conn);
    }
  }
@@ -2882,22 +2798,27 @@
   * If some information is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   */
  private boolean promptIfRequiredForPreOrPost(MonoServerReplicationUserData uData)
  {
    try (ConnectionWrapper conn = getConnection(uData))
    {
    ConnectionWrapper conn = getConnection(uData);
      if (conn == null)
      {
        return false;
      }
    try
    {
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      checkSuffixesForInitializeReplication(suffixes, conn, true);
      uData.setBaseDNs(suffixes);
      return !suffixes.isEmpty();
    }
    finally
    {
      close(conn);
    }
  }
  private ConnectionWrapper getConnection(MonoServerReplicationUserData uData)
@@ -2916,7 +2837,7 @@
        ConnectionWrapper conn = createConnectionInteracting(sourceServerCI);
        if (conn != null)
        {
          uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber()));
          uData.setHostPort(getHostPort2(sourceServerCI));
          uData.setAdminUid(sourceServerCI.getAdministratorUID());
          uData.setAdminPwd(sourceServerCI.getBindPassword());
          if (uData instanceof StatusReplicationUserData)
@@ -2949,40 +2870,34 @@
   * is missing, ask the user to provide valid data.
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   * @throws ReplicationCliException if a critical error occurs reading the ADS.
   */
  private boolean promptIfRequired(StatusReplicationUserData uData)
  throws ReplicationCliException
  private boolean promptIfRequired(StatusReplicationUserData uData) throws ReplicationCliException
  {
    ConnectionWrapper conn = null;
    try
    {
      conn = getConnection(uData);
    ConnectionWrapper conn = getConnection(uData);
      if (conn == null)
      {
        return false;
      }
    try
    {
      // If the server contains an ADS, try to load it and only load it: if
      // there are issues with the ADS they will be encountered in the
      // statusReplication(StatusReplicationUserData) method. Here we have
      // to load the ADS to ask the user to accept the certificates and
      // eventually admin authentication data.
      AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(conn);
      boolean cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false);
      conn = aux.get();
      if (cancelled)
      if (!loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false))
      {
        return false;
      }
      conn = aux.get();
      if (!cancelled)
      {
        uData.setBaseDNs(toDNs(argParser.getBaseDNs()));
      }
      return !cancelled;
      return true;
    }
    finally
    {
@@ -2997,74 +2912,36 @@
   * We assume that if this method is called we are in interactive mode.
   * @param uData the object to be updated.
   * @param serversOperations Additional processing for the command
   * @return <CODE>true</CODE> if the object was successfully updated and
   * <CODE>false</CODE> if the user cancelled the operation.
   * @return {@code true} if the object was successfully updated and
   * {@code false} if the user cancelled the operation.
   */
  private boolean promptIfRequired(SourceDestinationServerUserData uData,
      OperationBetweenSourceAndDestinationServers serversOperations)
  {
    boolean cancelled = false;
    String adminPwd = argParser.getBindPasswordAdmin();
    String adminUid = argParser.getAdministratorUID();
    String hostSource = argParser.getHostNameSource();
    int portSource = argParser.getPortSource();
    Map<String, String> pwdFile = null;
    if (argParser.getSecureArgsList().getBindPasswordFileArg().isPresent())
    {
      pwdFile = argParser.getSecureArgsList().getBindPasswordFileArg().getNameToValueMap();
    }
    /*
     * Use a copy of the argument properties since the map might be cleared
     * in initializeGlobalArguments.
     */
    sourceServerCI.initializeGlobalArguments(hostSource, portSource, adminUid, null, adminPwd,
        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
    // Try to connect to the source server
    ConnectionWrapper connSource = null;
    while (connSource == null && !cancelled)
    {
    ConnectionWrapper connDestination = null;
      try
      {
        sourceServerCI.setHeadingMessage(INFO_INITIALIZE_SOURCE_CONNECTION_PARAMETERS.get());
        sourceServerCI.run();
        hostSource = sourceServerCI.getHostName();
        portSource = sourceServerCI.getPortNumber();
      // Prompt for source server credentials
      sourceServerCI.initializeGlobalArguments(argParser.getHostNameSource(), argParser.getPortSource(), adminUid, null,
          adminPwd, getPwdFile());
      // Try to connect to the source server
      connSource = initializeFirstConnection(INFO_INITIALIZE_SOURCE_CONNECTION_PARAMETERS.get());
      if (connSource == null)
      {
        return false;
      }
        adminUid = sourceServerCI.getAdministratorUID();
        adminPwd = sourceServerCI.getBindPassword();
        connSource = createConnectionInteracting(sourceServerCI);
        if (connSource == null)
        {
          cancelled = true;
        }
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Client exception "+ce));
        errPrintln();
        errPrintln(ce.getMessageObject());
        errPrintln();
        sourceServerCI.resetConnectionArguments();
      }
      catch (ArgumentException ae)
      {
        logger.warn(LocalizableMessage.raw("Argument exception "+ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        cancelled = true;
      }
    }
    if (!cancelled)
    {
      uData.setHostNameSource(hostSource);
      uData.setPortSource(portSource);
      uData.setHostNameSource(sourceServerCI.getHostName());
      uData.setPortSource(sourceServerCI.getPortNumber());
      uData.setAdminUid(adminUid);
      uData.setAdminPwd(adminPwd);
    }
    firstServerCommandBuilder = new CommandBuilder();
    if (mustPrintCommandBuilder())
@@ -3072,50 +2949,74 @@
      firstServerCommandBuilder.append(sourceServerCI.getCommandBuilder());
    }
    /* Prompt for destination server credentials */
    String hostDestination = argParser.getHostNameDestination();
    int portDestination = argParser.getPortDestination();
      // Prompt for destination server credentials
      LDAPConnectionConsoleInteraction destinationServerCI =
          new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList());
      destinationServerCI.initializeGlobalArguments(argParser.getHostNameDestination(), argParser.getPortDestination(),
          adminUid, null, adminPwd, getPwdFile());
    /*
     * Use a copy of the argument properties since the map might be cleared
     * in initializeGlobalArguments.
     */
    LDAPConnectionConsoleInteraction destinationServerCI = new LDAPConnectionConsoleInteraction(this,
        argParser.getSecureArgsList());
    destinationServerCI.initializeGlobalArguments(hostDestination, portDestination, adminUid, null, adminPwd,
        pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
      // Try to connect to the destination server.
      connDestination = initializeDestinationConnection(sourceServerCI, destinationServerCI);
      if (connDestination == null)
      {
        return false;
      }
    /* Try to connect to the destination server. */
    ConnectionWrapper connDestination = null;
      uData.setHostNameDestination(destinationServerCI.getHostName());
      uData.setPortDestination(destinationServerCI.getPortNumber());
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      uData.setBaseDNs(suffixes);
      if (!serversOperations.continueAfterUserInput(suffixes, connSource, connDestination))
      {
        return false;
      }
      println();
      final boolean confirmed = serversOperations.confirmOperation(uData, connSource, connDestination, true);
      println();
      return confirmed;
    }
    finally
    {
      close(connSource, connDestination);
    }
  }
  private LinkedHashMap<String, String> getPwdFile()
  {
    FileBasedArgument bindPasswordFileArg = argParser.getSecureArgsList().getBindPasswordFileArg();
    if (bindPasswordFileArg.isPresent())
    {
      // Use a copy of the argument properties since the map might be cleared in
      // {@link LDAPConnectionConsoleInteraction#initializeGlobalArguments()}
      return new LinkedHashMap<>(bindPasswordFileArg.getNameToValueMap());
    }
    return null;
  }
  private ConnectionWrapper initializeDestinationConnection(LDAPConnectionConsoleInteraction sourceServerCI,
      LDAPConnectionConsoleInteraction destinationServerCI)
  {
    destinationServerCI.resetHeadingDisplayed();
    while (connDestination == null && !cancelled)
    while (true)
    {
      try
      {
        destinationServerCI.setHeadingMessage(INFO_INITIALIZE_DESTINATION_CONNECTION_PARAMETERS.get());
        destinationServerCI.run();
        hostDestination = destinationServerCI.getHostName();
        portDestination = destinationServerCI.getPortNumber();
        boolean error = false;
        if (hostSource.equalsIgnoreCase(hostDestination)
            && portSource == portDestination)
        final String hostSource = sourceServerCI.getHostName();
        final int portSource = sourceServerCI.getPortNumber();
        if (hostSource.equalsIgnoreCase(destinationServerCI.getHostName())
            && portSource == destinationServerCI.getPortNumber())
        {
          portDestination = -1;
          errPrintln();
          errPrintln(ERR_SOURCE_DESTINATION_INITIALIZE_SAME_SERVER_PORT.get(hostSource, portSource));
          errPrintln();
          error = true;
          return null;
        }
        if (!error)
        {
          connDestination = createConnectionInteracting(destinationServerCI, true);
          if (connDestination == null)
          {
            cancelled = true;
          }
        }
        return createConnectionInteracting(destinationServerCI, true);
      }
      catch (ClientException ce)
      {
@@ -3129,29 +3030,9 @@
      {
        logger.warn(LocalizableMessage.raw("Argument exception "+ae));
        argParser.displayMessageAndUsageReference(getErrStream(), ae.getMessageObject());
        cancelled = true;
        return null;
      }
    }
    if (!cancelled)
    {
      uData.setHostNameDestination(hostDestination);
      uData.setPortDestination(portDestination);
      List<DN> suffixes = toDNs(argParser.getBaseDNs());
      cancelled = serversOperations.continueAfterUserInput(suffixes, connSource, connDestination, true);
      uData.setBaseDNs(suffixes);
      if (!cancelled)
      {
        println();
        cancelled = serversOperations.confirmOperation(uData, connSource, connDestination, true);
        println();
      }
    }
    close(connSource, connDestination);
    return !cancelled;
  }
  private LocalizableMessage getInitializeReplicationPrompt(SourceDestinationServerUserData uData,
@@ -3373,8 +3254,8 @@
   * enable replication subcommand or the source server in the initialize server
   * subcommand.
   * @throws ReplicationCliException if a critical error occurred.
   * @return <CODE>true</CODE> if everything went fine and the user accepted
   * all the certificates and confirmed everything.  Returns <CODE>false</CODE>
   * @return {@code true} if everything went fine and the user accepted
   * all the certificates and confirmed everything.  Returns {@code false}
   * if the user did not accept a certificate or any of the confirmation
   * messages.
   */
@@ -3574,8 +3455,7 @@
      ADSContext adsContext = new ADSContext(conn);
      if (adsContext.hasAdminData())
      {
        Set<?> administrators = adsContext.readAdministratorRegistry();
        return !administrators.isEmpty();
        return !adsContext.readAdministratorRegistry().isEmpty();
      }
    }
    catch (Throwable t)
@@ -3591,8 +3471,7 @@
   * ReplicationUserData defined in the server for which the connection is provided.
   * @param conn the connection
   * @param uData the user data
   * @return <CODE>true</CODE> if we could find an administrator and
   * <CODE>false</CODE> otherwise.
   * @return {@code true} if we could find an administrator, {@code false} otherwise.
   */
  private boolean hasAdministrator(ConnectionWrapper conn, ReplicationUserData uData)
  {
@@ -3711,9 +3590,9 @@
   * make reference to the other replication server.
   * @param rep1 the first replica.
   * @param rep2 the second replica.
   * @return <CODE>true</CODE> if we can assure that the two replicas are
   * @return {@code true} if we can assure that the two replicas are
   * replicated using the replication server and replication port information
   * and <CODE>false</CODE> otherwise.
   * and {@code false} otherwise.
   */
  private boolean areFullyReplicated(ReplicaDescriptor rep1,
      ReplicaDescriptor rep2)
@@ -3738,8 +3617,8 @@
   * have at least one common replication server referenced.
   * @param rep1 the first replica.
   * @param rep2 the second replica.
   * @return <CODE>true</CODE> if we can assure that the two replicas are
   * replicated and <CODE>false</CODE> otherwise.
   * @return {@code true} if we can assure that the two replicas are
   * replicated and {@code false} otherwise.
   */
  private boolean areReplicated(ReplicaDescriptor rep1, ReplicaDescriptor rep2)
  {
@@ -4454,7 +4333,7 @@
      ConnectionWrapper conn, boolean interactive, boolean displayErrors)
  {
    // whether the user must provide base DNs or not
    // (if it is <CODE>false</CODE> the user will be proposed the suffixes only once)
    // (if it is {@code false} the user will be proposed the suffixes only once)
    final boolean areSuffixRequired = displayErrors;
    TreeSet<DN> availableSuffixes = new TreeSet<>();
@@ -7613,8 +7492,8 @@
   * another set of replication servers.
   * @param s1 the first set of replication servers.
   * @param s2 the second set of replication servers.
   * @return <CODE>true</CODE> if the two sets represent the same replication
   * servers and <CODE>false</CODE> otherwise.
   * @return {@code true} if the two sets represent the same replication
   * servers and {@code false} otherwise.
   */
  private boolean areReplicationServersEqual(Set<String> s1, Set<String> s2)
  {
@@ -7808,8 +7687,7 @@
   * Method used to compare two server registries.
   * @param registry1 the first registry to compare.
   * @param registry2 the second registry to compare.
   * @return <CODE>true</CODE> if the registries are equal and
   * <CODE>false</CODE> otherwise.
   * @return {@code true} if the registries are equal and {@code false} otherwise.
   */
  private boolean areEqual(Set<Map<ServerProperty, Object>> registry1, Set<Map<ServerProperty, Object>> registry2)
  {
@@ -7872,8 +7750,8 @@
  /**
   * Tells whether we are trying to disable all the replicated suffixes.
   * @param uData the disable replication data provided by the user.
   * @return <CODE>true</CODE> if we want to disable all the replicated suffixes
   * and <CODE>false</CODE> otherwise.
   * @return {@code true} if we want to disable all the replicated suffixes
   * and {@code false} otherwise.
   */
  private boolean disableAllBaseDns(ConnectionWrapper conn, DisableReplicationUserData uData)
  {
@@ -7992,19 +7870,14 @@
      {
        // Write to the file.
        String file = argParser.equivalentCommandFileArgument.getValue();
        try
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)))
        {
          BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
          writer.write(SHELL_COMMENT_SEPARATOR+getCurrentOperationDateMessage());
          writer.newLine();
          writer.write(commandBuilder.toString());
          writer.newLine();
          writer.newLine();
          writer.flush();
          writer.close();
        }
        catch (IOException ioe)
        {
@@ -9013,8 +8886,8 @@
   *
   * @param adsCtx1 the ADSContext of the first registry.
   * @param adsCtx2 the ADSContext of the second registry.
   * @return <CODE>true</CODE> if the registry containing all the data is
   * the first registry and <CODE>false</CODE> otherwise.
   * @return {@code true} if the registry containing all the data is
   * the first registry and {@code false} otherwise.
   * @throws ReplicationCliException if there is a problem reading or updating
   * the registries.
   */
@@ -9306,12 +9179,12 @@
  }
  /**
   * Returns <CODE>true</CODE> if the provided baseDN is replicated in the
   * provided server, <CODE>false</CODE> otherwise.
   * Returns {@code true} if the provided baseDN is replicated in the
   * provided server, {@code false} otherwise.
   * @param server the server.
   * @param baseDN the base DN.
   * @return <CODE>true</CODE> if the provided baseDN is replicated in the
   * provided server, <CODE>false</CODE> otherwise.
   * @return {@code true} if the provided baseDN is replicated in the
   * provided server, {@code false} otherwise.
   */
  private boolean isBaseDNReplicated(ServerDescriptor server, DN baseDN)
  {
@@ -9319,13 +9192,13 @@
  }
  /**
   * Returns <CODE>true</CODE> if the provided baseDN is replicated between
   * both servers, <CODE>false</CODE> otherwise.
   * Returns {@code true} if the provided baseDN is replicated between
   * both servers, {@code false} otherwise.
   * @param server1 the first server.
   * @param server2 the second server.
   * @param baseDN the base DN.
   * @return <CODE>true</CODE> if the provided baseDN is replicated between
   * both servers, <CODE>false</CODE> otherwise.
   * @return {@code true} if the provided baseDN is replicated between
   * both servers, {@code false} otherwise.
   */
  private boolean isBaseDNReplicated(ServerDescriptor server1, ServerDescriptor server2, DN baseDN)
  {