Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2012-01-03 10:31:54 -0500
committerThomas Watson2012-01-03 10:31:54 -0500
commit179cd3fe810fd5ad086c82c4d8fd5cc61c09e1e3 (patch)
tree0be78013d02b0069bcbd0f6b8725019652fa694b
parent3d7afed2a4603de7f56fbee90c4c89400abb3a8f (diff)
downloadrt.equinox.framework-179cd3fe810fd5ad086c82c4d8fd5cc61c09e1e3.tar.gz
rt.equinox.framework-179cd3fe810fd5ad086c82c4d8fd5cc61c09e1e3.tar.xz
rt.equinox.framework-179cd3fe810fd5ad086c82c4d8fd5cc61c09e1e3.zip
Bug 367614 - SecurityAdmin allows duplicate ConditionalPermissionInfo's
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java88
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java3
2 files changed, 89 insertions, 2 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java
index 0098a0e6e..c03037c88 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -573,4 +573,90 @@ public class SecurityManagerTests extends AbstractBundleTests {
assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$
}
+ public void testBug367614() {
+ File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$
+ Properties configuration = new Properties();
+ configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
+ configuration.put(Constants.FRAMEWORK_SECURITY, Framework.SECURITY_OSGI);
+ Equinox equinox = new Equinox(configuration);
+ try {
+ equinox.init();
+ } catch (BundleException e) {
+ fail("Unexpected exception on init()", e); //$NON-NLS-1$
+ }
+ assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$
+ // should be in the STARTING state
+ assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$
+ try {
+ equinox.start();
+ } catch (BundleException e) {
+ fail("Failed to start the framework", e); //$NON-NLS-1$
+ }
+ assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$
+
+ 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));
+ assertTrue("Cannot commit rows", update.commit()); //$NON-NLS-1$
+
+ 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) {
+ fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$
+ }
+ try {
+ equinox.waitForStop(10000);
+ } catch (InterruptedException e) {
+ fail("Unexpected interrupted exception", e); //$NON-NLS-1$
+ }
+
+ // try again from a cached state
+ try {
+ equinox.start();
+ } catch (BundleException e) {
+ fail("Failed to start the framework", e); //$NON-NLS-1$
+ }
+
+ 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) {
+ fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$
+ }
+ try {
+ equinox.waitForStop(10000);
+ } catch (InterruptedException e) {
+ 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()); //$NON-NLS-1$
+ }
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java
index 356c4cee2..d59644242 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -337,6 +337,7 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi
name = generateName();
if (names.contains(name))
throw new IllegalStateException("Duplicate name \"" + name + "\" at row: " + i); //$NON-NLS-1$//$NON-NLS-2$
+ names.add(name);
newRows[i] = new SecurityRow(this, name, infoBaseRow.getConditionInfos(), infoBaseRow.getPermissionInfos(), infoBaseRow.getAccessDecision());
}
condAdminTable = new SecurityTable(this, newRows);

Back to the top