public final class FilePermissions
extends java.lang.Object
The permissions that can be set on a file are dependent on the capabilities of the underlying operating system. Therefore, a file access level (such as OWNER) will have a similar but slightly different implementation depending on the operating system. Two models of file permissions are supported:
For a description of the supported access levels see FilePermissions.FILE_ACCESS below.
For details on the specific operating system file permissions that get set
for each of these levels (for example, the read-write permissions), see the
setAccessLevel(FILE_ACCESS) and setAccessLevel(FILE_ACCESS, boolean) methods.
The default is OWNER level. That is, if setAccessLevel() is not
called, then OWNER level will be used.
This class can be used in two ways:
FilePermission(). This uses the default OWNER level.setFilePermissions(File filename)setFilePermissions(File file, FILE_ACCESS fileAccess, boolean overrideFilePermissionsSystemDefaultProperty, boolean writable)
Functionally, the two ways are similar. The first way lets you use the defaults without having to specify an
access level. (Additionally, the setAccessLevel() can still be called on the instance, to override
the default level: this is convenient if the decision of what access level to use
occurs at a different place in your code from when you actually create the file (and set the permission). The second
way is convenient if the determination of the access level and the creation of the file occur at the same place in
your code.
The system wide default can be changed to SYSTEM_DEFAULT by setting the following custom JVM boolean property that is supported by the Entrust Java Toolkit: com.entrust.toolkit.security.file.permissions.systemDefault. (For example, by configuring -Dcom.entrust.toolkit.security.file.permissions.systemDefault=true).
| Modifier and Type | Class and Description |
|---|---|
static class |
FilePermissions.FILE_ACCESS
Defines the different levels of access permissions that are supported.
|
| Constructor and Description |
|---|
FilePermissions() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isSystemDefaultLevel()
Indicates if the access level is set to SYSTEM_DEFAULT
|
boolean |
setAccessLevel(FilePermissions.FILE_ACCESS access)
Specify the level of access (and override the default).
|
boolean |
setAccessLevel(FilePermissions.FILE_ACCESS access,
boolean writable)
Specify the level of access (and override the default).
|
boolean |
setFilePermissions(java.io.File filename)
Set the file permissions on a file.
|
static boolean |
setFilePermissions(java.io.File file,
FilePermissions.FILE_ACCESS fileAccess,
boolean overrideFilePermissionsSystemDefaultProperty,
boolean writable)
Set the permissions on a file by specifying the required access level.
|
public boolean setAccessLevel(FilePermissions.FILE_ACCESS access)
access - The requested access level.public boolean setAccessLevel(FilePermissions.FILE_ACCESS access, boolean writable)
access - The requested access level.writable - Set write access for 'group' or 'all' levels. Supported only on POSIX.public boolean isSystemDefaultLevel()
public boolean setFilePermissions(java.io.File filename)
throws java.nio.file.FileSystemException
setAccessLevel(),
or the default level if setAccessLevel() was not called.)
If the underlying operating system platform could not be determined, then the
file permissions are not changed.filename - The file to set the file permissions on.java.nio.file.FileSystemException - If the permissions could not be changed.public static boolean setFilePermissions(java.io.File file,
FilePermissions.FILE_ACCESS fileAccess,
boolean overrideFilePermissionsSystemDefaultProperty,
boolean writable)
throws java.nio.file.FileSystemException
file - The file to set the file permissions on.fileAccess - The level of access to set on the fileoverrideFilePermissionsSystemDefaultProperty - If the specified access level should override
the JVM property 'com.entrust.toolkit.security.file.permissions.systemDefault'
if it is enabledwritable - Set write access for 'group' or 'all' levels. Supported only on POSIX (Ignored otherwise).java.nio.file.FileSystemException - If the permissions could not be changed.