From 8b6a544a11dee1f1b77151fb532fb1f06a7bbea6 Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Tue, 28 Apr 2015 13:01:03 +0000
Subject: [PATCH] OPENDJ-1972 CR-6777 Remove JDK6 compatibility layers
---
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java | 2
opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java | 42 +-
opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java | 128 ---------
opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java | 28 +
opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java | 5
opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java | 6
opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java | 19
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java | 16
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java | 19
opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java | 19
opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java | 520 +-----------------------------------
11 files changed, 99 insertions(+), 705 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java b/opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java
index ba266ee..d82e8fe 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java
@@ -571,23 +571,20 @@
}
// Change the password file permission if possible
- if (FilePermission.canSetPermissions())
+ try
{
- try
- {
- if (!FilePermission.setPermissions(new File(pinFilePath),
- new FilePermission(0600)))
- {
- // Log a warning that the permissions were not set.
- logger.warn(WARN_ADMIN_SET_PERMISSIONS_FAILED, pinFilePath);
- }
- }
- catch (DirectoryException e)
+ if (!FilePermission.setPermissions(new File(pinFilePath),
+ new FilePermission(0600)))
{
// Log a warning that the permissions were not set.
logger.warn(WARN_ADMIN_SET_PERMISSIONS_FAILED, pinFilePath);
}
}
+ catch (DirectoryException e)
+ {
+ // Log a warning that the permissions were not set.
+ logger.warn(WARN_ADMIN_SET_PERMISSIONS_FAILED, pinFilePath);
+ }
// Delete the exported certificate
File f = new File(tempCertPath);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
index ba33cbc..f22549d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
@@ -1478,18 +1478,16 @@
out.flush();
out.close();
- if(FilePermission.canSetPermissions()) {
- try {
- if (!FilePermission.setPermissions(new File(path),
- new FilePermission(0600)))
- {
- // Log a warning that the permissions were not set.
- logger.warn(WARN_TRUSTSTORE_SET_PERMISSIONS_FAILED, path);
- }
- } catch(DirectoryException e) {
+ try {
+ if (!FilePermission.setPermissions(new File(path),
+ new FilePermission(0600)))
+ {
// Log a warning that the permissions were not set.
logger.warn(WARN_TRUSTSTORE_SET_PERMISSIONS_FAILED, path);
}
+ } catch(DirectoryException e) {
+ // Log a warning that the permissions were not set.
+ logger.warn(WARN_TRUSTSTORE_SET_PERMISSIONS_FAILED, path);
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
index c7f2f91..aca298a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
@@ -165,20 +165,17 @@
}
// Get the backend database backendDirectory permissions and apply
- if(FilePermission.canSetPermissions())
+ try
{
- try
+ if(!FilePermission.setPermissions(backendDirectory, backendPermission))
{
- if(!FilePermission.setPermissions(backendDirectory, backendPermission))
- {
- logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDirectory);
- }
+ logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDirectory);
}
- catch(Exception e)
- {
- // Log an warning that the permissions were not set.
- logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
- }
+ }
+ catch(Exception e)
+ {
+ // Log an warning that the permissions were not set.
+ logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
}
// Open the database environment
@@ -830,22 +827,19 @@
}
// Get the backend database backendDirectory permissions and apply
- if(FilePermission.canSetPermissions())
+ File parentDirectory = getFileForPath(config.getDBDirectory());
+ File backendDirectory = new File(parentDirectory, config.getBackendId());
+ try
{
- File parentDirectory = getFileForPath(config.getDBDirectory());
- File backendDirectory = new File(parentDirectory, config.getBackendId());
- try
+ if (!FilePermission.setPermissions(backendDirectory, backendPermission))
{
- if (!FilePermission.setPermissions(backendDirectory, backendPermission))
- {
- logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDirectory);
- }
+ logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDirectory);
}
- catch(Exception e)
- {
- // Log an warning that the permissions were not set.
- logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
- }
+ }
+ catch(Exception e)
+ {
+ // Log an warning that the permissions were not set.
+ logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
index 7a9b8f7..ade7349 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -1026,20 +1026,17 @@
FilePermission backendPermission = decodeDBDirPermissions(curCfg);
// Get the backend database backendDirectory permissions and apply
- if(FilePermission.canSetPermissions())
+ try
{
- try
+ if(!FilePermission.setPermissions(backendDir, backendPermission))
{
- if(!FilePermission.setPermissions(backendDir, backendPermission))
- {
- logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDir);
- }
+ logger.warn(WARN_JEB_UNABLE_SET_PERMISSIONS, backendPermission, backendDir);
}
- catch(Exception e)
- {
- // Log an warning that the permissions were not set.
- logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDir, e);
- }
+ }
+ catch(Exception e)
+ {
+ // Log an warning that the permissions were not set.
+ logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDir, e);
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java
index cdfd581..41e2ea4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java
@@ -35,6 +35,9 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileStore;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -60,7 +63,6 @@
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
-import org.opends.server.util.Platform;
/**
* This class provides an application-wide disk space monitoring service.
@@ -270,7 +272,7 @@
File fsMountPoint;
try
{
- fsMountPoint = Platform.getFilesystem(directory);
+ fsMountPoint = getMountPoint(directory);
}
catch (IOException ioe)
{
@@ -307,6 +309,28 @@
}
}
+ private File getMountPoint(File directory) throws IOException
+ {
+ Path mountPoint = directory.getAbsoluteFile().toPath();
+ Path parentDir = mountPoint.getParent();
+ FileStore dirFileStore = Files.getFileStore(mountPoint);
+ /*
+ * Since there is no concept of mount point in the APIs, iterate on all parents of
+ * the given directory until the FileSystem Store changes (hint of a different
+ * device, hence a mount point) or we get to root, which works too.
+ */
+ while (parentDir != null)
+ {
+ if (!Files.getFileStore(parentDir).equals(dirFileStore))
+ {
+ return mountPoint.toFile();
+ }
+ mountPoint = mountPoint.getParent();
+ parentDir = parentDir.getParent();
+ }
+ return mountPoint.toFile();
+ }
+
/**
* Removes a directory from the set of monitored directories.
*
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java
index 10ce3e2..7bdafca 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java
@@ -194,20 +194,17 @@
// Try to apply file permissions.
- if(FilePermission.canSetPermissions())
+ try
{
- try
+ if(!FilePermission.setPermissions(file, filePermissions))
{
- if(!FilePermission.setPermissions(file, filePermissions))
- {
- logger.warn(WARN_LOGGER_UNABLE_SET_PERMISSIONS, filePermissions, file);
- }
+ logger.warn(WARN_LOGGER_UNABLE_SET_PERMISSIONS, filePermissions, file);
}
- catch(Exception e)
- {
- // Log an warning that the permissions were not set.
- logger.warn(WARN_LOGGER_SET_PERMISSION_FAILED, file, stackTraceToSingleLineString(e));
- }
+ }
+ catch(Exception e)
+ {
+ // Log an warning that the permissions were not set.
+ logger.warn(WARN_LOGGER_SET_PERMISSION_FAILED, file, stackTraceToSingleLineString(e));
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
index f0a3a61..8c556d2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
@@ -295,10 +295,7 @@
w.close();
- if (FilePermission.canSetPermissions())
- {
- FilePermission.setPermissions(f, FilePermission.decodeUNIXMode("755"));
- }
+ FilePermission.setPermissions(f, FilePermission.decodeUNIXMode("755"));
}
catch (Exception e)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java b/opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java
index 2b3f2f3..5b5601e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java
@@ -28,15 +28,17 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.AclFileAttributeView;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
-import org.opends.server.core.DirectoryServer;
-
-import com.forgerock.opendj.util.OperatingSystem;
import static org.opends.messages.UtilityMessages.*;
@@ -56,11 +58,6 @@
mayInvoke=true)
public class FilePermission
{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
-
-
-
/**
* The bitmask that should be used for indicating whether a file is
* readable by its owner.
@@ -133,175 +130,11 @@
- /**
- * Indicates if the Java 7 NIO features can be used, including
- * enhancements to Java 6 {@link java.io.File}.
- */
- private static boolean useNIO;
-
- /** The {@link java.io.File#toPath} method if it is available. */
- private static Method toPath;
-
- /**
- * The {@link java.nio.files.Files#setPosixFilePermissions} method if it is
- * available.
- */
- private static Method setPosixFilePermissions;
-
- /**
- * The {@link java.nio.file.Files#getFileAttributeView} method if it is
- * available.
- */
- private static Method getFileAttributeView;
-
- /**
- * The {@link java.nio.file.attribute.PosixFilePermissions#fromString} method
- * if it is available.
- */
- private static Method fromString;
-
- /**
- * The {@link java.nio.file.attribute.PosixFilePermissions#asFileAttribute}
- * method if is available.
- */
- private static Method asFileAttribute;
-
- /**
- * The {@link java.nio.file.attribute.PosixFileAttributeView} class if it is
- * available.
- */
- private static Class<?> posixView;
-
- /**
- * The {@link java.nio.file.attribute.AclFileAttributeView} class if it is
- * available.
- */
- private static Class<?> aclView;
-
- /** The {@link java.nio.file.LinkOption} class if it is available. */
- private static Class<?> linkOption;
-
/** The encoded representation for this file permission. */
private int encodedPermission;
- static
- {
- // Iterate through all the necessary methods and classes in Java 7
- // for dealing with permissions.
- try
- {
- useNIO = false;
- toPath = null;
- setPosixFilePermissions = null;
- getFileAttributeView = null;
- fromString = null;
- asFileAttribute = null;
- posixView = null;
- aclView = null;
- linkOption = null;
-
- Class<?> c = Class.forName("java.io.File");
- for (Method m : c.getMethods())
- {
- String name = m.getName();
- Class<?>[] argTypes = m.getParameterTypes();
- if (name.equals("toPath") && argTypes.length == 0)
- {
- toPath = m;
- }
- }
- if (toPath == null)
- {
- throw new NoSuchMethodException("java.io.File.toPath");
- }
-
- c = Class.forName("java.nio.file.attribute.PosixFilePermissions");
- for (Method m : c.getMethods())
- {
- String name = m.getName();
- Class<?>[] argTypes = m.getParameterTypes();
- if (name.equals("fromString") && argTypes.length == 1)
- {
- fromString = m;
- }
- if (name.equals("asFileAttribute") && argTypes.length == 1)
- {
- asFileAttribute = m;
- }
- }
- if (fromString == null)
- {
- throw new NoSuchMethodException(
- "java.nio.file.attribute.PosixFilePermissions.fromString");
- }
- if (asFileAttribute == null) {
- throw new NoSuchMethodException(
- "java.nio.file.attribute.PosixFilePermissions.asFileAttribute");
- }
-
- c = Class.forName("java.nio.file.Files");
- for (Method m : c.getMethods())
- {
- String name = m.getName();
- Class<?>[] argTypes = m.getParameterTypes();
- if (name.equals("setPosixFilePermissions") && argTypes.length == 2)
- {
- setPosixFilePermissions = m;
- }
- if (name.equals("getFileAttributeView") && argTypes.length == 3)
- {
- getFileAttributeView = m;
- }
- }
- if (setPosixFilePermissions == null)
- {
- throw new NoSuchMethodException(
- "java.nio.file.Files.setPosixFilePermissions");
- }
- if (getFileAttributeView == null)
- {
- throw new NoSuchMethodException(
- "java.nio.file.Files.getFileAttributeView");
- }
-
- posixView = Class.forName(
- "java.nio.file.attribute.PosixFileAttributeView");
- aclView = Class.forName("java.nio.file.attribute.AclFileAttributeView");
- linkOption = Class.forName("java.nio.file.LinkOption");
-
- // If we got here, then we have everything we need.
- useNIO = true;
- }
- catch (NoSuchMethodException e)
- {
- logger.traceException(e);
- }
- catch (ClassNotFoundException e)
- {
- logger.traceException(e);
- }
- finally
- {
- // Clean up if we only had partial success.
- if (useNIO == false)
- {
- toPath = null;
- setPosixFilePermissions = null;
- getFileAttributeView = null;
- fromString = null;
- asFileAttribute = null;
- posixView = null;
- aclView = null;
- linkOption = null;
- }
- }
-
- }
-
-
-
/**
* Creates a new file permission object with the provided encoded
* representation.
@@ -561,32 +394,6 @@
/**
- * Indicates whether the there is a mechanism available for setting
- * permissions in the underlying filesystem on the current platform.
- *
- * @return <CODE>true</CODE> if there is a mechanism available for
- * setting file permissions on the underlying system (e.g.,
- * if the server is running in a Java 6 environment, or if
- * this is a UNIX-based system and the use of exec is
- * allowed), or <CODE>false</CODE> if no such mechanism is
- * available.
- */
- public static boolean canSetPermissions()
- {
- if (useNIO)
- {
- // It's a Java 7 environment.
- return true;
- }
-
- // It's a Java 6 environment, so we can always use that
- // mechanism.
- return true;
- }
-
-
-
- /**
* Attempts to set the given permissions on the specified file. If
* the underlying platform does not allow the full level of
* granularity specified in the permissions, then an attempt will be
@@ -610,313 +417,28 @@
public static boolean setPermissions(File f, FilePermission p)
throws FileNotFoundException, DirectoryException
{
- if (! f.exists())
+ if (!f.exists())
{
- LocalizableMessage message =
- ERR_FILEPERM_SET_NO_SUCH_FILE.get(f.getAbsolutePath());
- throw new FileNotFoundException(message.toString());
+ throw new FileNotFoundException(ERR_FILEPERM_SET_NO_SUCH_FILE.get(f.getAbsolutePath()).toString());
}
-
- // If we're running Java 7 and have NIO available, use that.
- if (useNIO)
+ Path filePath = f.toPath();
+ PosixFileAttributeView posix = Files.getFileAttributeView(filePath, PosixFileAttributeView.class);
+ if (posix != null)
{
- return setUsingJava7(f, p);
- }
-
- // If we're running Java 6, then we'll use the methods that Java
- // provides.
- return setUsingJava6(f, p);
- }
-
-
-
- /**
- * Attempts to set the specified permissions for the given file or
- * directory using the Java 7 NIO API. This will set the full POSIX
- * permissions on systems supporting POSIX filesystem semantics.
- *
- * @param f The file or directory to which the permissions should be applied.
- * @param p The permissions to apply to the file or directory.
- *
- * @return <code>true</code> if the permissions were successfully updated, or
- * <code>false</code> if not.
- *
- */
- private static boolean setUsingJava7(File f, FilePermission p)
- {
- try
- {
- // path = f.toPath();
- Object path = toPath.invoke(f);
-
- // posix = Files.getFileAttributeView(path, posixFileAttributeView.class);
- Object posix = getFileAttributeView.invoke(null, path, posixView,
- Array.newInstance(linkOption, 0));
-
- // If a POSIX view is available, then set the permissions.
- // NOTE: Windows 2003, 2008 and 7 (and probably others) don't have POSIX
- // views.
- if (posix != null)
- {
- // Build a string like "rwxr-x-w-" from p.
- StringBuilder posixMode = new StringBuilder();
- toPOSIXString(p, posixMode, "", "", "");
- // perms = PosixFilePermissions.fromString(posixMode.toString());
- Object perms = fromString.invoke(null, posixMode.toString());
-
- // Files.setPosixFilePermissions(path, perms);
- setPosixFilePermissions.invoke(null, path, perms);
- return true;
- }
-
- // acl = Files.getFileAttributeView(path, aclFileAttributeView.class);
- Object acl = getFileAttributeView.invoke(null, path, aclView,
- Array.newInstance(linkOption, 0));
-
- // If an ACL view is available, then return successfully.
- // This is not ideal, but the intention is the administrator has set up
- // the inherited ACLs "appropriately" so we don't need to do anything.
- //
- // Also ideally we would check ACLs before checking POSIX, in case we have
- // a filesystem like ZFS that can support both.
- if (acl != null)
- {
- return true;
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- }
- return false;
- }
-
- /**
- * Attempts to set the specified permissions for the given file
- * using the Java 6 <CODE>FILE</CODE> API. Only the "owner" and
- * "other" permissions will be preserved, since Java 6 doesn't provide
- * a way to set the group permissions directly.
- *
- * @param f The file to which the permissions should be applied.
- * @param p The permissions to apply to the file.
- *
- * @return <CODE>true</CODE> if the permissions were successfully
- * updated, or <CODE>false</CODE> if not.
- *
- * @throws DirectoryException If a problem occurs while attempting
- * to update permissions.
- */
- private static boolean setUsingJava6(File f, FilePermission p)
- throws DirectoryException
- {
- // NOTE: Due to a very nasty behavior of the Java 6 API, if you
- // want to want to grant a permission for the owner but not
- // for anyone else, then you *must* remove it for everyone
- // first, and then add it only for the owner. Otherwise,
- // the other permissions will be left unchanged and if they
- // had it before then they will still have it.
-
- boolean anySuccessful = false;
- boolean anyFailed = false;
- boolean exceptionThrown = false;
-
- // Take away read permission from everyone if necessary.
- if (p.isOwnerReadable() && (! p.isOtherReadable()))
- {
+ StringBuilder posixMode = new StringBuilder();
+ toPOSIXString(p, posixMode, "", "", "");
+ Set<PosixFilePermission> perms = PosixFilePermissions.fromString(posixMode.toString());
try
{
- if (f.setReadable(false, false))
- {
- anySuccessful = true;
- }
- else
- {
- if(!DirectoryServer.getOperatingSystem().equals(
- OperatingSystem.WINDOWS))
- {
- // On Windows platforms, file readability permissions
- // cannot be set to false. Do not consider this case
- // a failure. http://java.sun.com/developer/
- // technicalArticles/J2SE/Desktop/javase6/enhancements/
- anyFailed = true;
- }
- }
+ Files.setPosixFilePermissions(filePath, perms);
}
- catch (Exception e)
+ catch (UnsupportedOperationException | ClassCastException | IOException | SecurityException ex)
{
- logger.traceException(e);
- exceptionThrown = true;
+ throw new DirectoryException(ResultCode.OTHER, ERR_FILEPERM_SET_JAVA_EXCEPTION.get(f.getAbsolutePath()), ex);
}
+ return true;
}
-
- // Grant the appropriate read permission.
- try
- {
- boolean ownerOnly =
- (p.isOwnerReadable() != p.isOtherReadable());
-
- if (f.setReadable(p.isOwnerReadable(), ownerOnly))
- {
- anySuccessful = true;
- }
- else
- {
- if(!DirectoryServer.getOperatingSystem().equals(
- OperatingSystem.WINDOWS) || p.isOwnerReadable())
- {
- // On Windows platforms, file readability permissions
- // cannot be set to false. Do not consider this case
- // a failure. http://java.sun.com/developer/
- // technicalArticles/J2SE/Desktop/javase6/enhancements/
- anyFailed = true;
- }
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- exceptionThrown = true;
- }
-
-
- // NOTE: On Windows platforms attempting to call setWritable on a
- // directory always fails, regardless of parameters. Ignore
- // these failures.
- boolean ignoreSetWritableFailures =
- (DirectoryServer.getOperatingSystem().equals(
- OperatingSystem.WINDOWS) && f.isDirectory());
-
- // Take away write permission from everyone if necessary.
- if (p.isOwnerWritable() && (! p.isOtherWritable()))
- {
- try
- {
- if (f.setWritable(false, false))
- {
- anySuccessful = true;
- }
- else if (!ignoreSetWritableFailures)
- {
- anyFailed = true;
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- exceptionThrown = true;
- }
- }
-
- // Grant the appropriate write permission.
- try
- {
- boolean ownerOnly =
- (p.isOwnerWritable() != p.isOtherWritable());
-
- if (f.setWritable(p.isOwnerWritable(), ownerOnly))
- {
- anySuccessful = true;
- }
- else if (!ignoreSetWritableFailures)
- {
- anyFailed = true;
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- exceptionThrown = true;
- }
-
-
- // Take away execute permission from everyone if necessary.
- if (p.isOwnerExecutable() && (! p.isOtherExecutable()))
- {
- try
- {
- if (f.setExecutable(false, false))
- {
- anySuccessful = true;
- }
- else
- {
- if(!DirectoryServer.getOperatingSystem().equals(
- OperatingSystem.WINDOWS))
- {
- // On Windows platforms, file execute permissions
- // cannot be set to false. Do not consider this case
- // a failure. http://java.sun.com/developer/
- // technicalArticles/J2SE/Desktop/javase6/enhancements/
- anyFailed = true;
- }
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- exceptionThrown = true;
- }
- }
-
- // Grant the appropriate execute permission.
- try
- {
- boolean ownerOnly =
- (p.isOwnerExecutable() != p.isOtherExecutable());
-
- if (f.setExecutable(p.isOwnerExecutable(), ownerOnly))
- {
- anySuccessful = true;
- }
- else
- {
- if(!DirectoryServer.getOperatingSystem().equals(
- OperatingSystem.WINDOWS) || p.isOwnerExecutable())
- {
- // On Windows platforms, file execute permissions
- // cannot be set to false. Do not consider this case
- // a failure. http://java.sun.com/developer/
- // technicalArticles/J2SE/Desktop/javase6/enhancements/
- anyFailed = true;
- }
- }
- }
- catch (Exception e)
- {
- logger.traceException(e);
- exceptionThrown = true;
- }
-
-
- if (exceptionThrown)
- {
- // If an exception was thrown, we can't be sure whether or not
- // any permissions were updated.
- LocalizableMessage message =
- ERR_FILEPERM_SET_JAVA_EXCEPTION.get(f.getAbsolutePath());
- throw new DirectoryException(ResultCode.OTHER, message);
- }
- else if (anyFailed)
- {
- if (anySuccessful)
- {
- // Some of the file permissions may have been altered.
- LocalizableMessage message = ERR_FILEPERM_SET_JAVA_FAILED_ALTERED.get(
- f.getAbsolutePath());
- throw new DirectoryException(ResultCode.OTHER, message);
- }
- else
- {
- // The file permissions should have been left intact.
- LocalizableMessage message = ERR_FILEPERM_SET_JAVA_FAILED_UNALTERED.get(
- f.getAbsolutePath());
- throw new DirectoryException(ResultCode.OTHER, message);
- }
- }
- else
- {
- return anySuccessful;
- }
+ return Files.getFileAttributeView(filePath, AclFileAttributeView.class) != null;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java b/opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java
index abe7988..b86e637 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java
@@ -36,10 +36,8 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.List;
-import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
@@ -48,7 +46,6 @@
import java.lang.reflect.Method;
import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.messages.UtilityMessages.*;
@@ -114,28 +111,10 @@
private static Constructor<?> certKeyGenCons, X500NameCons;
/** Filesystem APIs */
- private static Method FILESYSTEMS_GETSTORES;
- private static Method FILESYSTEMS_PATHSGET;
-
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
static
{
- try
- {
- // FileSystem and FileStores APIs were introduced in JDK 7.
- FILESYSTEMS_PATHSGET = Class.forName("java.nio.file.Paths").getMethod("get", String.class, String[].class);
- FILESYSTEMS_GETSTORES = Class.forName("java.nio.file.Files").getMethod(
- "getFileStore", Class.forName("java.nio.file.Path"));
- }
- catch (Exception e)
- {
- FILESYSTEMS_GETSTORES = null;
- FILESYSTEMS_PATHSGET = null;
- logger.warn(WARN_UNABLE_TO_USE_FILESYSTEM_API.get());
- }
-
String x509pkg = pkgPrefix + ".x509";
String certAndKeyGen;
if (pkgPrefix.equals(IBM_SEC)
@@ -331,16 +310,6 @@
- /**
- * Normalize the data in the specified buffer.
- *
- * @param buffer
- * The buffer to normalize.
- */
- public abstract void normalize(StringBuilder buffer);
-
-
-
private long getUsableMemoryForCaching()
{
long youngGenSize = 0;
@@ -397,40 +366,6 @@
.totalMemory())) * 40 / 100;
}
}
-
- private File getFilesystem(File directory) throws IOException
- {
- if (FILESYSTEMS_GETSTORES != null)
- {
- try
- {
- Object dirFStore = FILESYSTEMS_GETSTORES.invoke(null,
- FILESYSTEMS_PATHSGET.invoke(null, directory.getAbsolutePath(), new String[0]));
- File parentDir = directory.getParentFile();
- /*
- * Since there is no concept of mount point in the APIs, iterate on all parents of
- * the given directory until the FileSystem Store changes (hint of a different
- * device, hence a mount point) or we get to root, which works too.
- */
- while (parentDir != null)
- {
- Object parentFStore = FILESYSTEMS_GETSTORES.invoke(null,
- FILESYSTEMS_PATHSGET.invoke(null, parentDir.getAbsolutePath(), new String[0]));
- if (!parentFStore.equals(dirFStore))
- {
- return directory;
- }
- directory = directory.getParentFile();
- parentDir = directory.getParentFile();
- }
- }
- catch (Exception e)
- {
- throw new IOException(e);
- }
- }
- return directory;
- }
}
@@ -528,57 +463,6 @@
*/
private static class DefaultPlatformIMPL extends PlatformIMPL
{
- /** Normalize method. */
- private static final Method NORMALIZE;
- /** Normalized form method. */
- private static final Object FORM_NFKC;
-
- static
- {
- Method normalize = null;
- Object formNFKC = null;
- try
- {
- Class<?> normalizer = Class.forName("java.text.Normalizer");
- Class<?> normalizerForm = Class.forName("java.text.Normalizer$Form");
- normalize = normalizer.getMethod("normalize", CharSequence.class,
- normalizerForm);
- formNFKC = normalizerForm.getField("NFKD").get(null);
- }
- catch (Exception ex)
- {
- // Do not use Normalizer. The values are already set to null.
- }
- NORMALIZE = normalize;
- FORM_NFKC = formNFKC;
- }
-
-
-
- @Override
- public void normalize(StringBuilder buffer)
- {
- try
- {
- String normal = (String) NORMALIZE.invoke(null, buffer, FORM_NFKC);
- buffer.replace(0, buffer.length(), normal);
- }
- catch (Exception ex)
- {
- // Don't do anything. buffer should be used.
- }
- }
- }
-
- /**
- * Normalize the specified buffer.
- *
- * @param buffer
- * The buffer to normalize.
- */
- public static void normalize(StringBuilder buffer)
- {
- IMPL.normalize(buffer);
}
@@ -625,16 +509,4 @@
{
return IMPL.getUsableMemoryForCaching();
}
-
- /**
- * Returns the filesystem on which the given directory resides by its mountpoint.
- *
- * @param directory the directory whose filesystem is required
- * @return the filesystem on which the given directory resides
- * @throws IOException The exception in case information on filesystem/storage cannot be found
- */
- public static File getFilesystem(File directory) throws IOException
- {
- return IMPL.getFilesystem(directory);
- }
}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java b/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
index 843ab9a..896f9dd 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -394,7 +394,7 @@
}
// Make the shell scripts in the bin directory executable, if possible.
- if (OperatingSystem.isUnixBased() && FilePermission.canSetPermissions())
+ if (OperatingSystem.isUnixBased())
{
try
{
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
index 38821a4..f2a8dad 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
@@ -34,7 +34,6 @@
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.util.Platform;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -240,10 +239,7 @@
@Test(dataProvider = "testRDNs")
public void testNormalizationToSafeUrlString(String rawRDN, String normRDN, String stringRDN) throws Exception {
RDN rdn = RDN.decode(rawRDN);
- StringBuilder buffer = new StringBuilder();
- buffer.append(normRDN);
- Platform.normalize(buffer);
- assertEquals(rdn.toNormalizedUrlSafeString(), buffer.toString());
+ assertEquals(rdn.toNormalizedUrlSafeString(), normRDN);
}
--
Gitblit v1.10.0