use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testEnableSecurityManager04.
public void testEnableSecurityManager04() throws BundleException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testEnableSecurityManager04");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing a bundle to tests bug
// $NON-NLS-1$
String locationLinkA = installer.getBundleLocation("test.link.a");
// $NON-NLS-1$
String locationLinkAClient = installer.getBundleLocation("test.link.a.client");
// set the security for the bundles
ConditionInfo linkACondition = new ConditionInfo(BundleLocationCondition.class.getName(), new String[] { locationLinkA });
ConditionInfo linkAClientCondition = new ConditionInfo(BundleLocationCondition.class.getName(), new String[] { locationLinkAClient });
// $NON-NLS-1$ //$NON-NLS-2$
PermissionInfo filterPermission = new PermissionInfo(PackagePermission.class.getName(), "(&(name=test.link.a)(package.name=test.link.*))", "import");
ConditionalPermissionAdmin ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
ConditionalPermissionUpdate update = ca.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo(null, new ConditionInfo[] { linkACondition }, new PermissionInfo[] { hostFragmentProvidePermission, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
rows.add(ca.newConditionalPermissionInfo(null, new ConditionInfo[] { linkAClientCondition }, new PermissionInfo[] { importFrameworkPackagePermission, filterPermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
Bundle linkA = systemContext.installBundle(locationLinkA);
Bundle linkAClient = systemContext.installBundle(locationLinkAClient);
equinox.start();
PackageAdmin pa = (PackageAdmin) systemContext.getService(systemContext.getServiceReference(PackageAdmin.class.getName()));
try {
assertTrue(pa.resolveBundles(new Bundle[] { linkA, linkAClient }));
// change import permission to fail filter match
// $NON-NLS-1$ //$NON-NLS-2$
filterPermission = new PermissionInfo(PackagePermission.class.getName(), "(&(name=fail.match)(package.name=test.link.*))", "import");
update = ca.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.clear();
rows.add(ca.newConditionalPermissionInfo(null, new ConditionInfo[] { linkACondition }, new PermissionInfo[] { hostFragmentProvidePermission, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
rows.add(ca.newConditionalPermissionInfo(null, new ConditionInfo[] { linkAClientCondition }, new PermissionInfo[] { importFrameworkPackagePermission, filterPermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
pa.refreshPackages(new Bundle[] { linkA, linkAClient });
// hack to wait for refresh to end
Thread.sleep(2000);
// $NON-NLS-1$
assertEquals("linkA has wrong state", Bundle.RESOLVED, linkA.getState());
// $NON-NLS-1$
assertEquals("linkAClient has wrong state", Bundle.INSTALLED, linkAClient.getState());
} catch (InterruptedException e) {
// fail
// $NON-NLS-1$
fail("interrupted", e);
} finally {
// put the framework back to the RESOLVED state
equinox.stop();
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testBug254600.
public void testBug254600() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testBug254600");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
Bundle securityB = null;
long idB = -1;
try {
// $NON-NLS-1$
String locationSecurityA = installer.getBundleLocation("security.a");
// $NON-NLS-1$
String locationSecurityB = installer.getBundleLocation("security.b");
systemContext.installBundle(locationSecurityA);
securityB = systemContext.installBundle(locationSecurityB);
idB = securityB.getBundleId();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to install security test bundles", e);
}
try {
securityB.start();
securityB.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start security.b bundle", e);
}
// put the framework back to the RESOLVED state
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
securityB = systemContext.getBundle(idB);
try {
securityB.start();
securityB.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start security.b bundle", e);
}
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testEnableSecurityManager02.
public void testEnableSecurityManager02() throws BundleException {
// create/start/stop/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testEnableSecurityManager02");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing host and fragment to test bug 245678
// $NON-NLS-1$
String locationSecurityA = installer.getBundleLocation("security.a");
// $NON-NLS-1$
String locationSecurityAFragA = installer.getBundleLocation("security.a.frag.a");
// set the security for the host and fragment
ConditionalPermissionAdmin ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
ConditionalPermissionUpdate update = ca.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo(null, null, new PermissionInfo[] { hostFragmentPermission, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
Bundle securityA = systemContext.installBundle(locationSecurityA);
systemContext.installBundle(locationSecurityAFragA);
equinox.start();
try {
securityA.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start securityA", e);
} finally {
// put the framework back to the RESOLVED state
equinox.stop();
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testBug367614.
public void testBug367614() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
ConditionalPermissionAdmin ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
ConditionalPermissionUpdate update = ca.newConditionalPermissionUpdate();
List rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo("test", null, new PermissionInfo[] { allPackagePermission }, ConditionalPermissionInfo.ALLOW));
// $NON-NLS-1$
assertTrue("Cannot commit rows", update.commit());
update = ca.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo("test", null, new PermissionInfo[] { allPackagePermission }, ConditionalPermissionInfo.ALLOW));
try {
update.commit();
fail("Expected failure to commit duplicate named rows");
} catch (Throwable t) {
assertTrue("Wrong exception: " + t, t instanceof IllegalStateException);
// expected failure
}
// put the framework back to the RESOLVED state
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// try again from a cached state
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
systemContext = equinox.getBundleContext();
ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
update = ca.newConditionalPermissionUpdate();
rows = update.getConditionalPermissionInfos();
rows.add(ca.newConditionalPermissionInfo("test", null, new PermissionInfo[] { allPackagePermission }, ConditionalPermissionInfo.ALLOW));
try {
update.commit();
fail("Expected failure to commit duplicate named rows");
} catch (Throwable t) {
assertTrue("Wrong exception: " + t, t instanceof IllegalStateException);
// expected failure
}
// put the framework back to the RESOLVED state
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SecurityManagerTests method testBug287750.
public void testBug287750() {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception on init()", e);
}
// $NON-NLS-1$
assertNotNull("SecurityManager is null", System.getSecurityManager());
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
Bundle testBundle = null;
try {
// $NON-NLS-1$
String locationTestBundle = installer.getBundleLocation("test.bug287750");
testBundle = systemContext.installBundle(locationTestBundle);
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to install security test bundles", e);
}
try {
testBundle.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start security.b bundle", e);
}
StartLevel sl = (StartLevel) systemContext.getService(systemContext.getServiceReference(StartLevel.class.getName()));
if (sl.getStartLevel() != 10)
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// nothing
}
// $NON-NLS-1$
assertEquals("Wrong startlevel", 10, sl.getStartLevel());
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
// $NON-NLS-1$
assertNull("SecurityManager is not null", System.getSecurityManager());
}
Aggregations