在 OSGi 中,我的权限在主线程中被拒绝,但在 EDT 线程中允许
我正在使用 Apache Felix 2.0.8
我已经实现了扩展 BasicPermission 的自定义权限,激活了安全管理器 (-Djava.security.manager) 并指定了我自己的策略文件 (- Djava.security.file="file:c:\blabla\myfile.policy")
通过简单的独立测试(OSGi 之外的简单主要方法),我断言当我更改时我的权限行为正确我的政策文件。一切都很好。
public static void main(String[] args) { 尝试 { AccessController.checkPermission(new MyPermission("foo")); System.out.println("确定"); } catch (SecurityException e) { System.out.println("NOK"); } }
在我的 OSGi 包中,我注意到相同的代码示例在主线程(在我的激活器的回调中)和我启动的其他线程中执行时都很好。但是,一旦从 AWT-EventQueue 线程执行,就始终允许相同的权限。
除了执行线程之外,我没有看到任何区别...
有人经历过类似的事情吗?
I'm using Apache Felix 2.0.8
I've implemented a custom Permission that extends BasicPermission, activated the security manager (-Djava.security.manager) and specified my own policy file (-Djava.security.file="file:c:\blabla\myfile.policy")
From simple standalone test (a simple main method outside OSGi) I've asserted that my permission behaves correctly when I change my policy file. Everything is fine.
public static void main(String[] args) { try { AccessController.checkPermission(new MyPermission("foo")); System.out.println("OK"); } catch (SecurityException e) { System.out.println("NOK"); } }
In my OSGi bundle, I've noticed that the same code sample is fine when executed in both the main thread (in the callback of my activator) and some other thread started by me. However, as soon as it is executed from the AWT-EventQueue thread, that very same permission is always allowed.
Except the executing thread, I don't see any difference...
Has anyone ever experienced something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 OSGi 中,框架不会查阅策略文件来获取包的权限。捆绑包的权限是通过 ConditionalPermissionAdmin(和旧版 PermissionAdmin)服务设置的。作为引导程序,所有捆绑包都被授予 AllPermission,直到某些捆绑包“断言”控制并为捆绑包设置权限。因此,在您通过 ConditionalPermissionAdmin 设置权限信息之前,所有捆绑包都将以 AllPermission 运行。
In OSGi, the framework does not consult the policy file for the permissions of bundles. The permissions of bundles are set via the ConditionalPermissionAdmin (and the older PermissionAdmin) service. As a bootstrap, all bundles are granted AllPermission until some bundle "asserts" control and sets permissions for bundles. So, until you set permission information via ConditionalPermissionAdmin, all the bundles are running with AllPermission.