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

jvergara
02.10.2008 1a4f0d584bc5c40e316368190c16afb361438fbb
Fix for issue 3224 (uninstall raises execption if specified keystore does not exist)

The exception is displayed because the logger for SecureConnectionCliArgs sends output to the console. Appart from that the code checks that the provide truststore and keystore paths exist and are readable.
5 files modified
85 ■■■■ changed files
opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java 26 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java 1 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties 6 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java 48 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -254,9 +254,12 @@
    {
      LOG.log(Level.WARNING,
          "Error retrieving a valid LDAP URL in conf file: "+ce, ce);
      println();
      println(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
      println();
      if (!parser.isInteractive())
      {
        Message msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
            ce);
      }
    }
    userData.setReferencedHostName(referencedHostName);
@@ -748,9 +751,10 @@
   *  remote servers.  <CODE>false</CODE> otherwise.
   *  @throws UserDataException if there is a problem with the information
   *  provided by the user.
   *  @throws ApplicationException if there is an error processing data.
   */
  private boolean askForAuthenticationIfNeeded(UninstallUserData userData)
  throws UserDataException
  throws UserDataException, ApplicationException
  {
    boolean accepted = true;
    String uid = userData.getAdminUID();
@@ -883,11 +887,12 @@
      }
      catch (ConfigException ce)
      {
        // This is unexpected
        LOG.log(Level.WARNING,
            "Error retrieving a valid LDAP URL in conf file: "+ce, ce);
        println();
        println(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
        println();
        Message msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
            ce);
      }
      finally
      {
@@ -1133,11 +1138,12 @@
    }
    catch (ConfigException ce)
    {
      // This is unexpected, when calling this code this should already been
      // checked.
      LOG.log(Level.WARNING,
          "Error retrieving a valid LDAP URL in conf file: "+ce, ce);
      println();
      println(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
      userData.setLocalServerUrl("ldap://localhost:389");
      Message msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
      throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg, ce);
    }
    catch (NamingException ne)
    {
opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -410,6 +410,7 @@
        }
      }
    }
    super.validateGlobalOptions(buf);
    if (buf.length() > 0)
    {
      returnValue = CONFLICTING_ARGS.getReturnCode();
opends/src/messages/messages/tools.properties
@@ -2348,3 +2348,9 @@
INFO_TASK_TOOL_TASK_SUCESSFULL_1608=%s task %s has been successfully completed
INFO_TASK_TOOL_TASK_NOT_SUCESSFULL_1609=%s task %s has not complete \
 successfully
SEVERE_ERR_CANNOT_READ_TRUSTSTORE_1610=Cannot access trust store '%s'.  Verify \
 that the provided trust store exists and that you have read access rights to it
SEVERE_ERR_CANNOT_READ_KEYSTORE_1611=Cannot access key store '%s'.  Verify \
 that the provided key store exists and that you have read access rights to it
opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java
@@ -62,6 +62,8 @@
      logger.addHandler(fileHandler);
      logger = Logger.getLogger("org.opends.admin.ads");
      logger.addHandler(fileHandler);
      logger = Logger.getLogger("org.opends.server.admin.client.cli");
      logger.addHandler(fileHandler);
      disableConsoleLogging();
      logger = Logger.getLogger("org.opends.quicksetup");
      logger.log(Level.INFO, getInitialLogRecord());
@@ -95,6 +97,8 @@
    logger.setUseParentHandlers(false);
    logger = Logger.getLogger("org.opends.server.tools");
    logger.setUseParentHandlers(false);
    logger = Logger.getLogger("org.opends.server.admin.client.cli");
    logger.setUseParentHandlers(false);
  }
  /**
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -38,6 +38,7 @@
import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
import static org.opends.server.util.StaticUtils.wrapText;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -625,6 +626,30 @@
      errors.add(message);
    }
    if (trustStorePathArg.isPresent())
    {
      // Check that the path exists and is readable
      String value = trustStorePathArg.getValue();
      if (!canRead(trustStorePathArg.getValue()))
      {
        Message message = ERR_CANNOT_READ_TRUSTSTORE.get(
            value);
        errors.add(message);
      }
    }
    if (keyStorePathArg.isPresent())
    {
      // Check that the path exists and is readable
      String value = keyStorePathArg.getValue();
      if (!canRead(trustStorePathArg.getValue()))
      {
        Message message = ERR_CANNOT_READ_KEYSTORE.get(
            value);
        errors.add(message);
      }
    }
    // Couldn't have at the same time startTLSArg and
    // useSSLArg
    if (useStartTLSArg.isPresent()
@@ -634,7 +659,6 @@
                      .getLongIdentifier(), useSSLArg.getLongIdentifier());
      errors.add(message);
    }
    if (errors.size() > 0)
    {
      for (Message error : errors)
@@ -876,4 +900,26 @@
      return null;
    }
  }
  /**
   * Returns <CODE>true</CODE> if we can read on the provided path and
   * <CODE>false</CODE> otherwise.
   * @param path the path.
   * @return <CODE>true</CODE> if we can read on the provided path and
   * <CODE>false</CODE> otherwise.
   */
  private boolean canRead(String path)
  {
    boolean canRead;
    File file = new File(path);
    if (file.exists())
    {
      canRead = file.canRead();
    }
    else
    {
      canRead = false;
    }
    return canRead;
  }
}