0

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.

Sameer Sarmah
  • 1,052
  • 4
  • 15
  • 33
  • 1
    Please post your stacktrace. Why does your codebase include a `src` directory? It should consist of JAR files, or at worst of directories of .class files. The source directory won't be there at runtime. – user207421 Mar 06 '14 at 06:00
  • Thanks.There a security exception thrown now after using grant codebase "file://home/esamsar/NetBeansProjects/FilePermissionDemo/build/classes/*".I am using textFile.canWrite(); which leads to the same exception. – Sameer Sarmah Mar 06 '14 at 11:10
  • 1
    Unless and until you post your stack trace as requested your question cannot be answered. I would also like to see the relevant output when run with -Djava.security.debug=access,failure. – user207421 Mar 07 '14 at 22:23

1 Answers1

0

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 /-.

Anthony O.
  • 22,041
  • 18
  • 107
  • 163