Package org.italiangrid.voms.util
Class FilePermissionHelper
java.lang.Object
org.italiangrid.voms.util.FilePermissionHelper
An helper class that does simple unix file permissions checks (until we get
proper support for this stuff in Java 7)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe command used to set file permissions on a given filestatic final StringThe command used to retrieve file permissions for a given filestatic final EnumSet<FilePermissionHelper.PosixFilePermission> Required file permissions for the private key filestatic final StringString representation of private key required permissions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckPKCS12Permissions(String pkcs12File) Chekcs whether a pkcs12 file has the 'right' permissionsstatic voidcheckPrivateKeyPermissions(String privateKeyFile) Checks whether a private key file has the 'right' permissionsstatic voidcheckProxyPermissions(String proxyFile) Checks whether a proxy file has the right permissionsprivate static voidfilenameSanityChecks(String filename) private static StringgetFilePermissions(String filename) static voidChecks that a given file has the appropriate unix permissions.static voidsetFilePermissions(String filename, FilePermissionHelper.PosixFilePermission perm) static voidsetPKCS12Permissions(String filename) static voidsetPrivateKeyPermissions(String filename) static voidsetProxyPermissions(String filename)
-
Field Details
-
PRIVATE_KEY_PERMS
Required file permissions for the private key file -
PRIVATE_KEY_PERMS_STR
String representation of private key required permissions. -
LS_CMD_TEMPLATE
The command used to retrieve file permissions for a given file- See Also:
-
CHMOD_CMD_TEMPLATE
The command used to set file permissions on a given file- See Also:
-
-
Constructor Details
-
FilePermissionHelper
public FilePermissionHelper()
-
-
Method Details
-
checkProxyPermissions
Checks whether a proxy file has the right permissions- Parameters:
proxyFile- the file to be checked- Throws:
IOException- if an error occurs checking file attributesFilePermissionError- if permissions are not as expected
-
checkPrivateKeyPermissions
Checks whether a private key file has the 'right' permissions- Parameters:
privateKeyFile- the file to be checked- Throws:
IOException- if an error occurs checking file attributesFilePermissionError- if the permissions are not correct
-
checkPKCS12Permissions
Chekcs whether a pkcs12 file has the 'right' permissions- Parameters:
pkcs12File- the file to be checked- Throws:
IOException- if an error occurs checking file attributesFilePermissionError- if the permissions are not correct
-
matchesFilePermissions
public static void matchesFilePermissions(String filename, FilePermissionHelper.PosixFilePermission p) throws IOException Checks that a given file has the appropriate unix permissions. This naive implementation just fetches the output of ls -al on a given file and matches the resulting string with the permissionString passed as argument. So the permissionString must be something like:-rw-------
- Parameters:
filename- the filename to be checkedp- the permission string that must be matched- Throws:
IOException- if an error occurs checking file attributesFilePermissionError- if file permissions are not as requested
-
filenameSanityChecks
-
getFilePermissions
-
setProxyPermissions
-
setPKCS12Permissions
-
setPrivateKeyPermissions
-
setFilePermissions
public static void setFilePermissions(String filename, FilePermissionHelper.PosixFilePermission perm)
-