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

neil_a_wilson
16.45.2006 9f04857f46200f98cfe4d57e6a874822bfff8616
Add a getFileForPath method to the StaticUtils class, and update several server
components to use it. This can help ensure that relative paths are evaluated
relative to the server root rather than whatever happened to be the current
working directory when the start script was launched.

OpenDS Issue Number: 586
9 files modified
126 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/backends/BackupBackend.java 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java 18 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskScheduler.java 8 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/extensions/FileBasedKeyManagerProvider.java 15 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/extensions/FileBasedTrustManagerProvider.java 15 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/extensions/PKCS11KeyManagerProvider.java 6 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/plugins/profiler/ProfilerPlugin.java 9 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java 47 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/BackupBackend.java
@@ -217,7 +217,7 @@
        backupDirectories = new LinkedHashSet<File>(values.size());
        for (String s : values)
        {
          backupDirectories.add(new File(s));
          backupDirectories.add(getFileForPath(s));
        }
      }
    }
@@ -1447,7 +1447,7 @@
        backupDirectories = new LinkedHashSet<File>(values.size());
        for (String s : values)
        {
          backupDirectories.add(new File(s));
          backupDirectories.add(getFileForPath(s));
        }
      }
    }
opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskBackend.java
@@ -1342,11 +1342,7 @@
        String tmpBackingFile = backingAttr.pendingValue();
        if (! taskBackingFile.equals(tmpBackingFile))
        {
          File f = new File(tmpBackingFile);
          if (!f.isAbsolute())
          {
            f = new File(DirectoryServer.getServerRoot(), tmpBackingFile);
          }
          File f = getFileForPath(tmpBackingFile);
          if (f.exists())
          {
            int msgID = MSGID_TASKBE_BACKING_FILE_EXISTS;
@@ -1475,11 +1471,7 @@
        tmpBackingFile = backingAttr.pendingValue();
        if (! taskBackingFile.equals(tmpBackingFile))
        {
          File f = new File(tmpBackingFile);
          if (!f.isAbsolute())
          {
            f = new File(DirectoryServer.getServerRoot(), tmpBackingFile);
          }
          File f = getFileForPath(tmpBackingFile);
          if (f.exists())
          {
            int msgID = MSGID_TASKBE_BACKING_FILE_EXISTS;
@@ -1617,11 +1609,7 @@
  {
    assert debugEnter(CLASS_NAME, "getTaskBackingFile");
    File f = new File(taskBackingFile);
    if (!f.isAbsolute())
    {
      f = new File(DirectoryServer.getServerRoot(), taskBackingFile);
    }
    File f = getFileForPath(taskBackingFile);
    return f.getPath();
  }
opendj-sdk/opends/src/server/org/opends/server/backends/task/TaskScheduler.java
@@ -932,7 +932,7 @@
    try
    {
      File backingFile = new File(backingFilePath);
      File backingFile = getFileForPath(backingFilePath);
      if (! backingFile.exists())
      {
        createNewTaskBackingFile();
@@ -1205,7 +1205,7 @@
      // See if there is a ".save" file.  If so, then delete it.
      File saveFile = new File(backingFilePath + ".save");
      File saveFile = getFileForPath(backingFilePath + ".save");
      try
      {
        if (saveFile.exists())
@@ -1220,7 +1220,7 @@
      // If there is an existing backing file, then rename it to ".save".
      File backingFile = new File(backingFilePath);
      File backingFile = getFileForPath(backingFilePath);
      try
      {
        if (backingFile.exists())
@@ -1246,7 +1246,7 @@
      // Rename the ".tmp" file into place.
      File tmpFile = new File(tmpFilePath);
      File tmpFile = getFileForPath(tmpFilePath);
      try
      {
        tmpFile.renameTo(backingFile);
opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java
@@ -121,7 +121,7 @@
      // We don't hold a lock on the file so we need to create it.  First,
      // create the file only if it doesn't already exist.
      File f = new File(lockFile);
      File f = getFileForPath(lockFile);
      try
      {
        if (! f.exists())
@@ -240,7 +240,7 @@
      // We don't hold a lock on the file so we need to create it.  First,
      // create the file only if it doesn't already exist.
      File f = new File(lockFile);
      File f = getFileForPath(lockFile);
      try
      {
        if (! f.exists())
opendj-sdk/opends/src/server/org/opends/server/extensions/FileBasedKeyManagerProvider.java
@@ -159,7 +159,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(keyStoreFile);
      File f = getFileForPath(keyStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_KEYMANAGER_NO_SUCH_FILE;
@@ -356,7 +356,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_KEYMANAGER_PIN_NO_SUCH_FILE;
@@ -489,7 +489,8 @@
    {
      keyStore = KeyStore.getInstance(keyStoreType);
      FileInputStream inputStream = new FileInputStream(keyStoreFile);
      FileInputStream inputStream =
           new FileInputStream(getFileForPath(keyStoreFile));
      keyStore.load(inputStream, keyStorePIN);
      inputStream.close();
    }
@@ -657,7 +658,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(newKeyStoreFile);
      File f = getFileForPath(newKeyStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_KEYMANAGER_NO_SUCH_FILE;
@@ -824,7 +825,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_KEYMANAGER_PIN_NO_SUCH_FILE;
@@ -966,7 +967,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(newKeyStoreFile);
      File f = getFileForPath(newKeyStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_KEYMANAGER_NO_SUCH_FILE;
@@ -1176,7 +1177,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_KEYMANAGER_PIN_NO_SUCH_FILE;
opendj-sdk/opends/src/server/org/opends/server/extensions/FileBasedTrustManagerProvider.java
@@ -158,7 +158,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(trustStoreFile);
      File f = getFileForPath(trustStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_TRUSTMANAGER_NO_SUCH_FILE;
@@ -358,7 +358,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_TRUSTMANAGER_PIN_NO_SUCH_FILE;
@@ -483,7 +483,8 @@
    {
      trustStore = KeyStore.getInstance(trustStoreType);
      FileInputStream inputStream = new FileInputStream(trustStoreFile);
      FileInputStream inputStream =
           new FileInputStream(getFileForPath(trustStoreFile));
      trustStore.load(inputStream, trustStorePIN);
      inputStream.close();
    }
@@ -651,7 +652,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(newTrustStoreFile);
      File f = getFileForPath(newTrustStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_TRUSTMANAGER_NO_SUCH_FILE;
@@ -818,7 +819,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_TRUSTMANAGER_PIN_NO_SUCH_FILE;
@@ -952,7 +953,7 @@
        throw new ConfigException(msgID, message);
      }
      File f = new File(newTrustStoreFile);
      File f = getFileForPath(newTrustStoreFile);
      if (! (f.exists() && f.isFile()))
      {
        msgID = MSGID_FILE_TRUSTMANAGER_NO_SUCH_FILE;
@@ -1162,7 +1163,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_FILE_TRUSTMANAGER_PIN_NO_SUCH_FILE;
opendj-sdk/opends/src/server/org/opends/server/extensions/PKCS11KeyManagerProvider.java
@@ -257,7 +257,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_PKCS11_KEYMANAGER_PIN_NO_SUCH_FILE;
@@ -612,7 +612,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_PKCS11_KEYMANAGER_PIN_NO_SUCH_FILE;
@@ -858,7 +858,7 @@
        {
          String fileName = pinFileAttr.activeValue();
          File pinFile = new File(fileName);
          File pinFile = getFileForPath(fileName);
          if (! pinFile.exists())
          {
            msgID = MSGID_PKCS11_KEYMANAGER_PIN_NO_SUCH_FILE;
opendj-sdk/opends/src/server/org/opends/server/plugins/profiler/ProfilerPlugin.java
@@ -256,7 +256,8 @@
           configEntry.getConfigAttribute(profileDirStub);
      if (profileDirAttr != null)
      {
        profileDirectory = profileDirAttr.activeValue();
        profileDirectory =
             getFileForPath(profileDirAttr.activeValue()).getAbsolutePath();
      }
    }
    catch (Exception e)
@@ -539,7 +540,7 @@
           configEntry.getConfigAttribute(profileDirStub);
      if (profileDirAttr != null)
      {
        File dirFile = new File(profileDirAttr.activeValue());
        File dirFile = getFileForPath(profileDirAttr.activeValue());
        if (! (dirFile.exists() && dirFile.isDirectory()))
        {
          msgID = MSGID_PLUGIN_PROFILER_INVALID_PROFILE_DIR;
@@ -696,7 +697,7 @@
        String dirString = profileDirAttr.pendingValue();
        if (! dirString.equals(profileDirectory))
        {
          File dirFile = new File(dirString);
          File dirFile = getFileForPath(dirString);
          if (! (dirFile.exists() && dirFile.isDirectory()))
          {
            msgID = MSGID_PLUGIN_PROFILER_INVALID_PROFILE_DIR;
@@ -707,7 +708,7 @@
          }
          else
          {
            profileDirectory = dirString;
            profileDirectory = dirFile.getAbsolutePath();
            if (detailedResults)
            {
opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -3180,6 +3180,53 @@
  /**
   * Indicates whether the provided path refers to a relative path rather than
   * an absolute path.
   *
   * @param  path  The path string for which to make the determination.
   *
   * @return  <CODE>true</CODE> if the provided path is relative, or
   *          <CODE>false</CODE> if it is absolute.
   */
  public static boolean isRelativePath(String path)
  {
    assert debugEnter(CLASS_NAME, "isRelativePath", String.valueOf(path));
    File f = new File(path);
    return (! f.isAbsolute());
  }
  /**
   * Retrieves a <CODE>File</CODE> object corresponding to the specified path.
   * If the given path is an absolute path, then it will be used.  If the path
   * is relative, then it will be interpreted as if it were relative to the
   * Directory Server root.
   *
   * @param  path  The path string to be retrieved as a <CODE>File</CODE>
   *
   * @return  A <CODE>File</CODE> object that corresponds to the specified path.
   */
  public static File getFileForPath(String path)
  {
    assert debugEnter(CLASS_NAME, "getFileForPath", String.valueOf(path));
    File f = new File (path);
    if (f.isAbsolute())
    {
      return f;
    }
    else
    {
      return new File(DirectoryServer.getServerRoot() + File.separator + path);
    }
  }
  /**
   * Creates a new, blank entry with the given DN.  It will contain only the
   * attributes contained in the RDN, and it will be based on the untypedObject
   * objectclass.  If the entry contains one or more attributes that are not