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 FilePermission
decodeUNIXMode(String modeString)
Decodes the provided string as a UNIX mode and retrieves the corresponding file permission.boolean
isGroupExecutable()
Indicates whether this file permission includes the group execute permission.boolean
isGroupReadable()
Indicates whether this file permission includes the group read permission.boolean
isGroupWritable()
Indicates whether this file permission includes the group write permission.boolean
isOtherExecutable()
Indicates whether this file permission includes the other execute permission.boolean
isOtherReadable()
Indicates whether this file permission includes the other read permission.boolean
isOtherWritable()
Indicates whether this file permission includes the other write permission.boolean
isOwnerExecutable()
Indicates whether this file permission includes the owner execute permission.boolean
isOwnerReadable()
Indicates whether this file permission includes the owner read permission.boolean
isOwnerWritable()
Indicates whether this file permission includes the owner write permission.static boolean
setPermissions(Path f, FilePermission p)
Attempts to set the given permissions on the specified file.static boolean
setSafePermissions(Path f, Integer p)
Attempts to set the given permissions on the specified file.String
toString()
Retrieves a string representation of this file permission.
-
-
-
Method Detail
-
isOwnerReadable
public boolean isOwnerReadable()
Indicates whether this file permission includes the owner read permission.- Returns:
true
if this file permission includes the owner read permission, orfalse
if not.
-
isOwnerWritable
public boolean isOwnerWritable()
Indicates whether this file permission includes the owner write permission.- Returns:
true
if this file permission includes the owner write permission, orfalse
if not.
-
isOwnerExecutable
public boolean isOwnerExecutable()
Indicates whether this file permission includes the owner execute permission.- Returns:
true
if this file permission includes the owner execute permission, orfalse
if not.
-
isGroupReadable
public boolean isGroupReadable()
Indicates whether this file permission includes the group read permission.- Returns:
true
if this file permission includes the group read permission, orfalse
if not.
-
isGroupWritable
public boolean isGroupWritable()
Indicates whether this file permission includes the group write permission.- Returns:
true
if this file permission includes the group write permission, orfalse
if not.
-
isGroupExecutable
public boolean isGroupExecutable()
Indicates whether this file permission includes the group execute permission.- Returns:
true
if this file permission includes the group execute permission, orfalse
if not.
-
isOtherReadable
public boolean isOtherReadable()
Indicates whether this file permission includes the other read permission.- Returns:
true
if this file permission includes the other read permission, orfalse
if not.
-
isOtherWritable
public boolean isOtherWritable()
Indicates whether this file permission includes the other write permission.- Returns:
true
if this file permission includes the other write permission, orfalse
if not.
-
isOtherExecutable
public boolean isOtherExecutable()
Indicates whether this file permission includes the other execute permission.- Returns:
true
if this file permission includes the other execute permission, orfalse
if not.
-
setPermissions
public static boolean setPermissions(Path f, FilePermission p) throws FileNotFoundException, LdapException
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:
true
if the permissions (or the nearest equivalent) were successfully applied to the specified file, orfalse
if was not possible to set the permissions on the current platform.- Throws:
FileNotFoundException
- If the specified file does not exist.LdapException
- If a problem occurs while trying to set the file permissions.
-
setSafePermissions
public static boolean setSafePermissions(Path 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:
true
if the permissions (or the nearest equivalent) were successfully applied to the specified file, orfalse
if 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.
-
decodeUNIXMode
public static FilePermission decodeUNIXMode(String modeString) throws LdapException
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:
LdapException
- If the provided string is not a valid three-digit UNIX mode.
-
-