org.italiangrid.voms.util
Class FilePermissionHelper

java.lang.Object
  extended by org.italiangrid.voms.util.FilePermissionHelper

public class FilePermissionHelper
extends Object

An 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
static class FilePermissionHelper.PosixFilePermission
           
 
Field Summary
static String CHMOD_CMD_TEMPLATE
          The command used to set file permissions on a given file
static String LS_CMD_TEMPLATE
          The command used to retrieve file permissions for a given file
 
Constructor Summary
FilePermissionHelper()
           
 
Method Summary
static void checkPKCS12Permissions(String pkcs12File)
          Chekcs whether a pkcs12 file has the 'right' permissions
static void checkPrivateKeyPermissions(String privateKeyFile)
          Checks whether a private key file has the 'right' permissions
static void checkProxyPermissions(String proxyFile)
          Checks whether a proxy file has the right permissions
static void matchesFilePermissions(String filename, FilePermissionHelper.PosixFilePermission p)
          Checks that a given file has the appropriate unix permissions.
static void setFilePermissions(String filename, FilePermissionHelper.PosixFilePermission perm)
           
static void setPKCS12Permissions(String filename)
           
static void setPrivateKeyPermissions(String filename)
           
static void setProxyPermissions(String filename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS_CMD_TEMPLATE

public static final 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 String CHMOD_CMD_TEMPLATE
The command used to set file permissions on a given file

See Also:
Constant Field Values
Constructor Detail

FilePermissionHelper

public FilePermissionHelper()
Method Detail

checkProxyPermissions

public static void checkProxyPermissions(String proxyFile)
                                  throws IOException
Checks whether a proxy file has the right permissions

Parameters:
proxyFile - the file to be checked
Throws:
IOException - if an error occurs checking file attributes
FilePermissionError - if permissions are not as expected

checkPrivateKeyPermissions

public static void checkPrivateKeyPermissions(String privateKeyFile)
                                       throws IOException
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 attributes
FilePermissionError - if the permissions are not correct

checkPKCS12Permissions

public static void checkPKCS12Permissions(String pkcs12File)
                                   throws IOException
Chekcs whether a pkcs12 file has the 'right' permissions

Parameters:
pkcs12File - the file to be checked
Throws:
IOException - if an error occurs checking file attributes
FilePermissionError - 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 checked
permissionString - the permission string that must be matched
Throws:
IOException - if an error occurs checking file attributes
FilePermissionError - if file permissions are not as requested

setProxyPermissions

public static void setProxyPermissions(String filename)

setPKCS12Permissions

public static void setPKCS12Permissions(String filename)

setPrivateKeyPermissions

public static void setPrivateKeyPermissions(String filename)

setFilePermissions

public static void setFilePermissions(String filename,
                                      FilePermissionHelper.PosixFilePermission perm)


Copyright © 2013. All Rights Reserved.