Package org.italiangrid.voms.util
Class FilePermissionHelper
- java.lang.Object
-
- org.italiangrid.voms.util.FilePermissionHelper
-
public class FilePermissionHelper extends java.lang.ObjectAn helper class that does simple unix file permissions checks (until we get proper support for this stuff in Java 7)- Author:
- Andrea Ceccanti
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFilePermissionHelper.PosixFilePermission
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHMOD_CMD_TEMPLATEThe command used to set file permissions on a given filestatic java.lang.StringLS_CMD_TEMPLATEThe command used to retrieve file permissions for a given filestatic java.util.EnumSet<FilePermissionHelper.PosixFilePermission>PRIVATE_KEY_PERMSRequired file permissions for the private key filestatic java.lang.StringPRIVATE_KEY_PERMS_STRString representation of private key required permissions.
-
Constructor Summary
Constructors Constructor Description FilePermissionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckPKCS12Permissions(java.lang.String pkcs12File)Chekcs whether a pkcs12 file has the 'right' permissionsstatic voidcheckPrivateKeyPermissions(java.lang.String privateKeyFile)Checks whether a private key file has the 'right' permissionsstatic voidcheckProxyPermissions(java.lang.String proxyFile)Checks whether a proxy file has the right permissionsstatic voidmatchesFilePermissions(java.lang.String filename, FilePermissionHelper.PosixFilePermission p)Checks that a given file has the appropriate unix permissions.static voidsetFilePermissions(java.lang.String filename, FilePermissionHelper.PosixFilePermission perm)static voidsetPKCS12Permissions(java.lang.String filename)static voidsetPrivateKeyPermissions(java.lang.String filename)static voidsetProxyPermissions(java.lang.String filename)
-
-
-
Field Detail
-
PRIVATE_KEY_PERMS
public static final java.util.EnumSet<FilePermissionHelper.PosixFilePermission> PRIVATE_KEY_PERMS
Required file permissions for the private key file
-
PRIVATE_KEY_PERMS_STR
public static final java.lang.String PRIVATE_KEY_PERMS_STR
String representation of private key required permissions.
-
LS_CMD_TEMPLATE
public static final java.lang.String LS_CMD_TEMPLATE
The command used to retrieve file permissions for a given file- See Also:
- Constant Field Values
-
CHMOD_CMD_TEMPLATE
public static final java.lang.String CHMOD_CMD_TEMPLATE
The command used to set file permissions on a given file- See Also:
- Constant Field Values
-
-
Method Detail
-
checkProxyPermissions
public static void checkProxyPermissions(java.lang.String proxyFile) throws java.io.IOExceptionChecks whether a proxy file has the right permissions- Parameters:
proxyFile- the file to be checked- Throws:
java.io.IOException- if an error occurs checking file attributesFilePermissionError- if permissions are not as expected
-
checkPrivateKeyPermissions
public static void checkPrivateKeyPermissions(java.lang.String privateKeyFile) throws java.io.IOExceptionChecks whether a private key file has the 'right' permissions- Parameters:
privateKeyFile- the file to be checked- Throws:
java.io.IOException- if an error occurs checking file attributesFilePermissionError- if the permissions are not correct
-
checkPKCS12Permissions
public static void checkPKCS12Permissions(java.lang.String pkcs12File) throws java.io.IOExceptionChekcs whether a pkcs12 file has the 'right' permissions- Parameters:
pkcs12File- the file to be checked- Throws:
java.io.IOException- if an error occurs checking file attributesFilePermissionError- if the permissions are not correct
-
matchesFilePermissions
public static void matchesFilePermissions(java.lang.String filename, FilePermissionHelper.PosixFilePermission p) throws java.io.IOExceptionChecks 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:
java.io.IOException- if an error occurs checking file attributesFilePermissionError- if file permissions are not as requested
-
setProxyPermissions
public static void setProxyPermissions(java.lang.String filename)
-
setPKCS12Permissions
public static void setPKCS12Permissions(java.lang.String filename)
-
setPrivateKeyPermissions
public static void setPrivateKeyPermissions(java.lang.String filename)
-
setFilePermissions
public static void setFilePermissions(java.lang.String filename, FilePermissionHelper.PosixFilePermission perm)
-
-