ConditionalPermissionAdmin not working [message #907937] |
Tue, 04 September 2012 12:57 |
eugene rabii Messages: 13 Registered: February 2012 |
Junior Member |
|
|
Hello,
My question is actually pretty simple - how do you make the ConditionalPermissionAdmin add ALLPermissions to your bundle. And I did follow the advices given http://www.eclipse.org/forums/index.php/mv/msg/279813/784178/#msg_784178, nevertheless I still get errors.
First I followed OSGi in Action for this, and here is the code that they say must work(showing all the code, may be it is easier):
public void start(BundleContext context) throws Exception {
System.out.println("===== Starting Bundle PermissionsTest =====");
SecurityManager securityManager = System.getSecurityManager();
if(securityManager == null) throw new IllegalArgumentException("Security Manager is not defined!");
ServiceReference serviceReference =
(ServiceReference) context.getServiceReference(ConditionalPermissionAdmin.class.getName());
if(serviceReference == null) throw new IllegalArgumentException(ConditionalPermissionAdmin.class.getName() + " IS NULL");
else System.out.println("===== Good so far 1 =====");
ConditionalPermissionAdmin admin =
(ConditionalPermissionAdmin)context.getService(serviceReference);
if(admin == null) throw new IllegalArgumentException("ConditionalPermissionAdmin can not be found");
else System.out.println("===== Good so far 2 =====");
//------------------------------------------------------------------------------------------------------------------------
//give All Permission to this bundle
ConditionalPermissionInfo allPermissions = admin.newConditionalPermissionInfo("AllPermissions",
new ConditionInfo[]{new ConditionInfo(BundleLocationCondition.class.getName(),
new String[]{context.getBundle().getLocation()})},
new PermissionInfo[]{new PermissionInfo(AllPermission.class.getName(), "", "")},
ConditionalPermissionInfo.ALLOW);
ConditionalPermissionUpdate update = admin.newConditionalPermissionUpdate();
@SuppressWarnings("unchecked")
List<ConditionalPermissionInfo> listOfCurrentPermissions = update.getConditionalPermissionInfos();
listOfCurrentPermissions.clear();
listOfCurrentPermissions.add(allPermissions);
System.out.println("===== Before commiting ALL_PERMISSIONS =====");
boolean commited = update.commit();
System.out.println("===== After comitting ALL_PERMISSIONS : " + commited + " =====");
I can see the last Sysout, but immediatly after that the server crashes with:
2012-09-04 12:56:53.505] INFO iLogServiceListener@36e3ffdf org.osgi.service.log.LogService Bundle com.vivat.OSGi_0.0.1.SNAPSHOT, BundleEvent STARTED
[2012-09-04 12:56:54.147] ERROR Scanner-0 System.err Exception in thread "Scanner-0" java.security.AccessControlException: access denied (java.io.FilePermission /Users/eugenrabii/Downloads/virgo-jetty-server-3.5.0.RELEASE/jetty/contexts read)
[2012-09-04 12:56:54.148] ERROR Scanner-0 System.err at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
[2012-09-04 12:56:54.148] ERROR Scanner-0 System.err at org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager.internalCheckPermission(EquinoxSecurityManager.java:117)
[2012-09-04 12:56:54.148] ERROR Scanner-0 System.err at org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager$CheckPermissionAction.run(EquinoxSecurityManager.java:60)
[2012-09-04 12:56:54.148] ERROR Scanner-0 System.err at java.security.AccessController.doPrivileged(Native Method)
[2012-09-04 12:56:54.148] ERROR Scanner-0 System.err at org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager.checkPermission(EquinoxSecurityManager.java:88)
[2012-09-04 12:56:54.149] ERROR Scanner-0 System.err at org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager.checkPermission(EquinoxSecurityManager.java:186)
[2012-09-04 12:56:54.149] ERROR Scanner-0 System.err at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
[2012-09-04 12:56:54.149] ERROR Scanner-0 System.err at java.io.File.exists(File.java:731)
[2012-09-04 12:56:54.149] ERROR Scanner-0 System.err at org.eclipse.jetty.util.Scanner.scan(Scanner.java:397)
[2012-09-04 12:56:54.150] ERROR Scanner-0 System.err at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:348)
[2012-09-04 12:56:54.150] ERROR Scanner-0 System.err at java.util.TimerThread.mainLoop(Timer.java:512)
[2012-09-04 12:56:54.150] ERROR Scanner-0 System.err at java.util.TimerThread.run(Timer.java:462)
[2012-09-04 12:57:04.629] ERROR Task (Bundle 21) (Bundle 21) System.err Exception in thread "[Timer] - Periodical Task (Bundle 21) (Bundle 21)" java.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)
Well... this is weird. The book says it should work, right?
May be I am doing something stupid. I try the code from here: http://www.eclipse.org/forums/index.php/mv/msg/279813/784178/#msg_784178.
So replace, the relevant code above with this:
String star = " \"*\"";
ConditionalPermissionInfo allPermissions = admin.newConditionalPermissionInfo(ConditionalPermissionInfo.ALLOW + "{[" +
BundleLocationCondition.class.getName() + " \"" +
context.getBundle().getLocation() + "\"]("+AllPermission.class.getName() + star + star + ")}");
And the logs say the same thing.
[2012-09-04 13:00:15.832] INFO GiLogServiceListener@3a32ea4 org.osgi.service.log.LogService Bundle com.vivat.OSGi_0.0.1.SNAPSHOT, BundleEvent STARTED
[2012-09-04 13:00:16.076] ERROR Scanner-0 System.err Exception in thread "Scanner-0" java.security.AccessControlException: access denied (java.io.FilePermission /Users/eugenrabii/Downloads/virgo-jetty-server-3.5.0.RELEASE/jetty/contexts read)
This smells really fishy and buggy to me. is this like a know issue or something?
Thank You,
Eugene.
|
|
|
Powered by
FUDForum. Page generated in 0.03713 seconds