Package java.io

Examples of java.io.FilePermission


    }

    public static boolean isSecure(String root, File file) throws IOException {
        PermissionCollection rootDirectory;
        if( root.endsWith( File.separator ) ) {
            FilePermission fp = new FilePermission( root + "-", "read" );
            rootDirectory = fp.newPermissionCollection();
            rootDirectory.add( fp );
            rootDirectory.add( new FilePermission( root.substring( 0, root.length() - 1 ), "read" ) );
        } else {
            FilePermission fp = new FilePermission( root, "read" );
            rootDirectory = fp.newPermissionCollection();
            rootDirectory.add( fp );
            rootDirectory.add( new FilePermission( root + File.separator + "-", "read" ) );
        }
        return ( rootDirectory.implies( new FilePermission( file.getCanonicalPath(), "read" ) ) );
    }
View Full Code Here


                perms.add(new SocketPermission(host, SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
              }
              else if ( "file".equals(codesource.getLocation().getProtocol()) ) {
                // if running locally add file permission
                String path = codesource.getLocation().getFile().replace('/', File.separatorChar);
                  perms.add(new FilePermission(path, SecurityConstants.FILE_READ_ACTION));
              }

            } catch (Exception e) {
          e.printStackTrace();
        }
View Full Code Here

        final LocalFile localFile = (LocalFile) fileObject;
        final File file = localFile.getLocalFile();
        final SecurityManager sm = System.getSecurityManager();
        if (sm != null)
        {
            final FilePermission requiredPerm = new FilePermission(file.getAbsolutePath(), "read");
            sm.checkPermission(requiredPerm);
        }
        return file;
    }
View Full Code Here

      // it means the codebase is a directory, and we need
      // to add an additional permission to read recursively
      String path = p.getName();
      if (path.endsWith(File.separator)) {
    path += "-";
    p = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
      }
  } else if ((p == null) && (url.getProtocol().equals("file"))) {
      String path = url.getFile().replace('/', File.separatorChar);
            path = ParseUtil.decode(path);
      if (path.endsWith(File.separator))
    path += "-";
      p =  new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
  } else {
      URL locUrl = url;
      if (urlConnection instanceof JarURLConnection) {
    locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
      }
View Full Code Here

     * @see     #checkPermission(java.security.Permission) checkPermission
     */
    public void checkExec(String cmd) {
  File f = new File(cmd);
  if (f.isAbsolute()) {
      checkPermission(new FilePermission(cmd,
    SecurityConstants.FILE_EXECUTE_ACTION));
  } else {
      checkPermission(new FilePermission("<<ALL FILES>>",
    SecurityConstants.FILE_EXECUTE_ACTION));
  }
    }
View Full Code Here

     * @exception  NullPointerException if the <code>file</code> argument is
     *             <code>null</code>.
     * @see        #checkPermission(java.security.Permission) checkPermission
     */
    public void checkRead(String file) {
  checkPermission(new FilePermission(file,
      SecurityConstants.FILE_READ_ACTION));
    }
View Full Code Here

     * @see        java.lang.SecurityManager#getSecurityContext()
     * @see        java.security.AccessControlContext#checkPermission(java.security.Permission)
     */
    public void checkRead(String file, Object context) {
  checkPermission(
      new FilePermission(file, SecurityConstants.FILE_READ_ACTION),
      context);
    }
View Full Code Here

     * @exception  NullPointerException if the <code>file</code> argument is
     *             <code>null</code>.
     * @see        #checkPermission(java.security.Permission) checkPermission
     */
    public void checkWrite(String file) {
  checkPermission(new FilePermission(file,
      SecurityConstants.FILE_WRITE_ACTION));
    }
View Full Code Here

     *             <code>null</code>.
     * @see        java.io.File#delete()
     * @see        #checkPermission(java.security.Permission) checkPermission
     */
    public void checkDelete(String file) {
  checkPermission(new FilePermission(file,
      SecurityConstants.FILE_DELETE_ACTION));
    }
View Full Code Here

    //*-- create the Linux script
    if (Constants.OSNAME.endsWith("x"))
    {
     String tfile = outfile + ".sh";
     fos = new FileOutputStream(new File(tfile));
     new FilePermission(tfile, permissions);
     pw = new PrintWriter(fos);
     pw.println("#!/bin/sh");
     pw.println("#*-- Generated Linux script to run ps2txt");
     pw.println("export HOME=\"" + Constants.PS2TXTDIR + "\"");
     pw.println("cd $HOME");
     pw.println("ps2txt -dvi \"" + ifile + "\"");
    }
    //*-- create the windows script
    else
    {
     String tfile = outfile + ".bat";
     fos = new FileOutputStream(new File(tfile));
     new FilePermission(tfile, permissions);
     pw = new PrintWriter(fos);
     pw.println("@ECHO OFF");
     pw.println("REM *-- Generated Windows script to run ps2txt");
     pw.println("set HOME=" + Constants.PS2TXTDIR);
     pw.println("set PATH=" + Constants.CYGWINDIR + ";%PATH%");
View Full Code Here

TOP

Related Classes of java.io.FilePermission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.