简体   繁体   中英

Grant permission to a particular directory to avoid java.security.AccessControlException

I am trying to read a text file after I have set the security manager with a policy file which is-

grant  
{
  permission java.io.FilePermission "/home/esamsar/NetBeansProjects/FilePermissionDemo/src/cheese.txt", "write";
};

It is working fine but when I add a codebase to it java.security.AccessControlException is encountered everytime. My OS is Ubuntu and I have tried the following and all are encountering the same exception.

grant codebase  "file:/home/esamsar/NetBeansProjects/FilePermissionDemo/src/*"
grant codebase  "file://home/esamsar/NetBeansProjects/FilePermissionDemo/src/*"
grant  codebase "/home/esamsar/NetBeansProjects/FilePermissionDemo/src/*"

Could someone point the proper way to add a codebase to grant permission to a particular directory. Thanks in advance.

Did you try this:

grant codebase "file:///home/esamsar/NetBeansProjects/FilePermissionDemo/classes/-" {
  permission java.io.FilePermission "/home/esamsar/NetBeansProjects/FilePermissionDemo/src/cheese.txt", "write";
};

The point here is to allow the folder where your IDE is outputing the compiled classes (here I supposed <your_project_path>/classes ), ending with /- .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM