2

Operation Not Permitted Error.

Previously same code was working without any issues. I hope some recent changes on Mac OS is causing it.

Applet jars are perfectly signed. So I don't think signing is issue.

And I'm trying to create folder under current logged in user directory by using

    String userHomePath = System.getProperty("user.home");

    **new File(userHomePath +" path ").mkdirs() returns false**

since it doesn't have permissions to create file / folder under it.

Tried the following way to set permission but it fails with same "Operation not permitted error"

//using PosixFilePermission to set file permissions 777
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
//add owners permission
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
//add group permissions
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
//add others permissions
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);


Files.setPosixFilePermissions(Paths.get(path, ""), perms);

If I run the same folder creating code on Main method of a Java class on Mac, it works perfectly. And also If I make runnable jar using export option on eclipse IDE for that applet, it works fine. it was able to create folders in both the cases.

And Also Its works on Windows Operating system.

I googled for setting permission on MAC using Java applets, but I was not able to locate any working solution.

I also tried setting permissions like the below, it also results in the same error "operation not permitted" .

private static void createParent(File directory){
        String folderName = directory.getAbsolutePath();
        if(directory.exists()){
            String [] cmdArray = new String[2]; 
            cmdArray[0] = "chmod -R 4777 "+folderName; 
            Runtime rt = Runtime.getRuntime(); 
            try {
                Process proc = rt.exec(cmdArray);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            folderName = folderName.substring(0,folderName.lastIndexOf(File.separator));
            File file = new File(folderName);
            createParent(file);
            directory.mkdir();
            createParent(file);
        }
    }
Sedhu
  • 723
  • 1
  • 11
  • 36

2 Answers2

4

I found a Workaround. Basically browser settings needs to be changed.

Safari >Preferences > Security > Manage Website Settings > Java > Choose the website > Choose "Run in Unsafe Mode" instead of "Allow".

it will say "Java is set to run in unsafe mode for some websites. Plugins in unsafe mode can access your documents and data."

It will work charm.

Sedhu
  • 723
  • 1
  • 11
  • 36
-1

"Operation is not permitted" That's pretty much explaining it. Applets are not allowed to change anything on the Client PC. Also they are not allowed to connect to other Hosts except the one they are started from.

Chase
  • 88
  • 1
  • 8
  • 1
    But the same code used to work previously. And also the same code is working Now in windows OS. – Sedhu Jul 23 '14 at 05:37