Package org.opends.server.types
Class FilePermission
- java.lang.Object
-
- org.opends.server.types.FilePermission
-
@PublicAPI(stability=VOLATILE, mayInstantiate=true, mayExtend=false, mayInvoke=true) public class FilePermission extends Object
This class provides a mechanism for setting file permissions in a more abstract manner than is provided by the underlying operating system and/or filesystem. It uses a traditional UNIX-style rwx/ugo representation for the permissions and converts them as necessary to the scheme used by the underlying platform. It does not provide any mechanism for getting file permissions, nor does it provide any way of dealing with file ownership or ACLs.
-
-
Constructor Summary
Constructors Constructor Description FilePermission(int encodedPermission)Creates a new file permission object with the provided encoded representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FilePermissiondecodeUNIXMode(String modeString)Decodes the provided string as a UNIX mode and retrieves the corresponding file permission.booleanisGroupExecutable()Indicates whether this file permission includes the group execute permission.booleanisGroupReadable()Indicates whether this file permission includes the group read permission.booleanisGroupWritable()Indicates whether this file permission includes the group write permission.booleanisOtherExecutable()Indicates whether this file permission includes the other execute permission.booleanisOtherReadable()Indicates whether this file permission includes the other read permission.booleanisOtherWritable()Indicates whether this file permission includes the other write permission.booleanisOwnerExecutable()Indicates whether this file permission includes the owner execute permission.booleanisOwnerReadable()Indicates whether this file permission includes the owner read permission.booleanisOwnerWritable()Indicates whether this file permission includes the owner write permission.static booleansetPermissions(File f, FilePermission p)Attempts to set the given permissions on the specified file.static booleansetSafePermissions(File f, Integer p)Attempts to set the given permissions on the specified file.StringtoString()Retrieves a string representation of this file permission.static StringtoUNIXMode(FilePermission p)Retrieves a three-character string that is the UNIX mode for the provided file permission.
-
-
-
Method Detail
-
isOwnerReadable
public boolean isOwnerReadable()
Indicates whether this file permission includes the owner read permission.- Returns:
trueif this file permission includes the owner read permission, orfalseif not.
-
isOwnerWritable
public boolean isOwnerWritable()
Indicates whether this file permission includes the owner write permission.- Returns:
trueif this file permission includes the owner write permission, orfalseif not.
-
isOwnerExecutable
public boolean isOwnerExecutable()
Indicates whether this file permission includes the owner execute permission.- Returns:
trueif this file permission includes the owner execute permission, orfalseif not.
-
isGroupReadable
public boolean isGroupReadable()
Indicates whether this file permission includes the group read permission.- Returns:
trueif this file permission includes the group read permission, orfalseif not.
-
isGroupWritable
public boolean isGroupWritable()
Indicates whether this file permission includes the group write permission.- Returns:
trueif this file permission includes the group write permission, orfalseif not.
-
isGroupExecutable
public boolean isGroupExecutable()
Indicates whether this file permission includes the group execute permission.- Returns:
trueif this file permission includes the group execute permission, orfalseif not.
-
isOtherReadable
public boolean isOtherReadable()
Indicates whether this file permission includes the other read permission.- Returns:
trueif this file permission includes the other read permission, orfalseif not.
-
isOtherWritable
public boolean isOtherWritable()
Indicates whether this file permission includes the other write permission.- Returns:
trueif this file permission includes the other write permission, orfalseif not.
-
isOtherExecutable
public boolean isOtherExecutable()
Indicates whether this file permission includes the other execute permission.- Returns:
trueif this file permission includes the other execute permission, orfalseif not.
-
setPermissions
public static boolean setPermissions(File f, FilePermission p) throws FileNotFoundException, DirectoryException
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 made to set them as closely as possible to the provided permissions, erring on the side of security.- Parameters:
f- The file to which the permissions should be applied.p- The permissions to apply to the file.- Returns:
trueif the permissions (or the nearest equivalent) were successfully applied to the specified file, orfalseif was not possible to set the permissions on the current platform.- Throws:
FileNotFoundException- If the specified file does not exist.DirectoryException- If a problem occurs while trying to set the file permissions.
-
setSafePermissions
public static boolean setSafePermissions(File f, Integer p)
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 made to set them as closely as possible to the provided permissions, erring on the side of security.- Parameters:
f- The file to which the permissions should be applied.p- The permissions to apply to the file.- Returns:
trueif the permissions (or the nearest equivalent) were successfully applied to the specified file, orfalseif was not possible to set the permissions on the current platform. The file is known to exist therefore there is no need for exists() checks.
-
toUNIXMode
public static String toUNIXMode(FilePermission p)
Retrieves a three-character string that is the UNIX mode for the provided file permission. Each character of the string will be a numeric digit from zero through seven.- Parameters:
p- The permission to retrieve as a UNIX mode string.- Returns:
- The UNIX mode string for the provided permission.
-
decodeUNIXMode
public static FilePermission decodeUNIXMode(String modeString) throws DirectoryException
Decodes the provided string as a UNIX mode and retrieves the corresponding file permission. The mode string must contain three digits between zero and seven.- Parameters:
modeString- The string representation of the UNIX mode to decode.- Returns:
- The file permission that is equivalent to the given UNIX mode.
- Throws:
DirectoryException- If the provided string is not a valid three-digit UNIX mode.
-
-