Class RestrictedFileUtils


  • public final class RestrictedFileUtils
    extends java.lang.Object
    This class contains a method to create restricted files.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Logger LOG  
      private static java.util.List<java.lang.String> WIN_PRINCIPAL_SIDS  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void createFileOrDir​(java.io.File file, boolean isDir)  
      static void createRestrictedDirectory​(java.io.File directory)
      Creates a new directory with minimum permissions.
      static void createRestrictedFile​(java.io.File file)
      Creates a new file with minimum permissions.
      private static void createRestrictedFile​(java.io.File file, boolean isDir)
      Creates a new file or directory with minimum permissions.
      private static java.lang.reflect.Method findMethod​(java.lang.Class<?> clazz, java.lang.String methodName)  
      static java.lang.String getSIDForPrincipal​(java.security.Principal principal)  
      static boolean principalInWinSIDS​(java.security.Principal principal)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logger LOG
      • WIN_PRINCIPAL_SIDS

        private static final java.util.List<java.lang.String> WIN_PRINCIPAL_SIDS
    • Constructor Detail

      • RestrictedFileUtils

        public RestrictedFileUtils()
    • Method Detail

      • createRestrictedDirectory

        public static void createRestrictedDirectory​(java.io.File directory)
                                              throws java.io.IOException
        Creates a new directory with minimum permissions. The directory is not readable or writable by anyone other than the owner. The parent directories are not created; they must exist before this is called.
        Parameters:
        directory - directory to be created
        Throws:
        java.io.IOException - if IO fails
      • createRestrictedFile

        public static void createRestrictedFile​(java.io.File file)
                                         throws java.io.IOException
        Creates a new file with minimum permissions. The file is not readable or writable by anyone other than the owner. If writeableByOwner is false, even the owner can not write to it.
        Parameters:
        file - path to file
        Throws:
        java.io.IOException - if IO fails
      • createRestrictedFile

        private static void createRestrictedFile​(java.io.File file,
                                                 boolean isDir)
                                          throws java.io.IOException
        Creates a new file or directory with minimum permissions. The file is not readable or writable by anyone other than the owner. If writeableByOwner is false, even the owner can not write to it. If isDir is true, then the directory can be executed by the owner
        Throws:
        java.io.IOException
      • createFileOrDir

        private static void createFileOrDir​(java.io.File file,
                                            boolean isDir)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • principalInWinSIDS

        public static boolean principalInWinSIDS​(java.security.Principal principal)
      • getSIDForPrincipal

        public static java.lang.String getSIDForPrincipal​(java.security.Principal principal)
      • findMethod

        private static java.lang.reflect.Method findMethod​(java.lang.Class<?> clazz,
                                                           java.lang.String methodName)