java 库中的权限

发布于 2024-12-02 18:43:13 字数 1279 浏览 1 评论 0原文

我有一个使用 JNA 库(由 Maven 管理)的程序。程序本身拥有所有权限(我遇到了FilePermission错误,更改了策略文件,现在我可以随意读/写)。但是,当我使用 JNA 时,出现以下错误:

Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission jna.encoding read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
    at java.security.AccessController.checkPermission(AccessController.java:553)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1302)
    at java.lang.System.getProperty(System.java:669)
    at com.sun.jna.Pointer.getString(Pointer.java:682)
    at com.sun.jna.Function.invokeString(Function.java:598)
    at com.sun.jna.Function.invoke(Function.java:356)
    at com.sun.jna.Function.invoke(Function.java:276)
    at com.sun.jna.Library$Handler.invoke(Library.java:216)

我的策略文件是(最后的授权显然不起作用):

grant codeBase "file:/home/tm/workspace/-" {
  permission java.security.AllPermission;
};
grant codeBase "file:/home/tm/.m2/repository/net/java/dev/jna/jna/-" {
  permission java.util.PropertyPermission "jna.encoding", "read";
};

我正在 eclipse 中从工作区目录中的项目运行该程序。有什么想法我需要将哪些权限分配给什么?

I have a program that uses the JNA library (managed with maven). The program itself has all permissions (I got a FilePermission error, changed the policy file, and now I can read/write at will). However, when I use JNA, I get the following error:

Exception in thread "main" java.security.AccessControlException: access denied (java.util.PropertyPermission jna.encoding read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
    at java.security.AccessController.checkPermission(AccessController.java:553)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1302)
    at java.lang.System.getProperty(System.java:669)
    at com.sun.jna.Pointer.getString(Pointer.java:682)
    at com.sun.jna.Function.invokeString(Function.java:598)
    at com.sun.jna.Function.invoke(Function.java:356)
    at com.sun.jna.Function.invoke(Function.java:276)
    at com.sun.jna.Library$Handler.invoke(Library.java:216)

My policy file is (that last grant obvioulsy doesn't work):

grant codeBase "file:/home/tm/workspace/-" {
  permission java.security.AllPermission;
};
grant codeBase "file:/home/tm/.m2/repository/net/java/dev/jna/jna/-" {
  permission java.util.PropertyPermission "jna.encoding", "read";
};

I'm running the program in eclipse, from a project in the workspace directory. Any ideas which permissions I need to assign to what?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙气飘飘 2024-12-09 18:43:13

因为它是一个分布式程序,所以我有 RMISecurityManager。当我删除对 setSecurityManager 的所有调用时,问题就停止了。我认为 System.setSecurityManager(new RMISecurityManager()); 没有获取策略文件。

I had RMISecurityManagers in place since it was a distributed program. When I removed all calls to setSecurityManager, the problem stopped. I presume System.setSecurityManager(new RMISecurityManager()); doesn't pick up the policy file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文