简体   繁体   English

授予对特定目录的权限,以避免java.security.AccessControlException

[英]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. 它工作正常,但是当我向其添加代码库时,每次都会遇到java.security.AccessControlException。 My OS is Ubuntu and I have tried the following and all are encountering the same exception. 我的操作系统是Ubuntu,我尝试了以下操作,并且都遇到了相同的异常。

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 /- . 这里的要点是允许您的IDE在其中输出已编译类的文件夹(在这里我假设为<your_project_path>/classes ),以/-结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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