简体   繁体   English

在OSGi中,我的权限在主线程中被拒绝,但在EDT线程中被允许

[英]In OSGi, my Permission is denied in Main thread but allowed in EDT thread

I'm using Apache Felix 2.0.8 我正在使用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" ) 我已经实现了扩展BasicPermission的自定义Permission,激活了安全管理器( -Djava.security.manager )并指定了我自己的策略文件( -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. 通过简单的独立测试(OSGi之外的一种简单的主方法),我断言在更改策略文件时我的权限行为正确。 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. 在我的OSGi包中,我注意到在主线程(在激活器的回调中)和我启动的其他一些线程中执行相同的代码示例是可以的。 However, as soon as it is executed from the AWT-EventQueue thread, that very same permission is always allowed. 但是,一旦从AWT-EventQueue线程执行了该权限,便始终允许相同的权限。

Except the executing thread, I don't see any difference... 除了执行线程外,我看不出任何区别。

Has anyone ever experienced something similar? 有没有人经历过类似的事情?

In OSGi, the framework does not consult the policy file for the permissions of bundles. 在OSGi中,框架不咨询策略文件以获取捆绑软件的权限。 The permissions of bundles are set via the ConditionalPermissionAdmin (and the older PermissionAdmin) service. 捆绑软件的权限是通过ConditionalPermissionAdmin(和较旧的PermissionAdmin)服务设置的。 As a bootstrap, all bundles are granted AllPermission until some bundle "asserts" control and sets permissions for bundles. 作为引导程序,所有捆绑软件均被授予AllPermission,直到某些捆绑软件“断言”控制并设置捆绑软件的权限为止。 So, until you set permission information via ConditionalPermissionAdmin, all the bundles are running with AllPermission. 因此,在您通过ConditionalPermissionAdmin设置权限信息之前,所有捆绑软件都将使用AllPermission运行。

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

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