Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-02-01 20:51:12 +0000
committerThomas Watson2011-02-01 20:51:12 +0000
commit65a6b6ce374167a53f19e50f68517a46887cbac9 (patch)
tree8c72824d3cc5293d3eb47c8fd21ec027834f08a3
parent4a83192ba95b3d7fb2454eeaedf34ee145572c26 (diff)
downloadrt.equinox.framework-65a6b6ce374167a53f19e50f68517a46887cbac9.tar.gz
rt.equinox.framework-65a6b6ce374167a53f19e50f68517a46887cbac9.tar.xz
rt.equinox.framework-65a6b6ce374167a53f19e50f68517a46887cbac9.zip
Bug 334553 - OSGi added weave action to AdminPermission
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/DynamicImportList.java11
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java15
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/AdminPermission.java115
3 files changed, 91 insertions, 50 deletions
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/DynamicImportList.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/DynamicImportList.java
index 81787029f..789beae53 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/DynamicImportList.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/DynamicImportList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 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
@@ -24,6 +24,12 @@ import org.osgi.framework.Constants;
public class DynamicImportList extends AbstractList<String> implements RandomAccess {
// the collection of valid DynamicImport-Package statments.
private final List<String> imports = new ArrayList<String>(0);
+ private final WovenClassImpl wovenClass;
+
+ public DynamicImportList(WovenClassImpl wovenClass) {
+ super();
+ this.wovenClass = wovenClass;
+ }
@Override
public String get(int index) {
@@ -37,18 +43,21 @@ public class DynamicImportList extends AbstractList<String> implements RandomAcc
@Override
public String set(int index, String element) {
+ wovenClass.checkPermission();
validateSyntax(element);
return imports.set(index, element);
}
@Override
public void add(int index, String element) {
+ wovenClass.checkPermission();
validateSyntax(element);
imports.add(index, element);
}
@Override
public String remove(int index) {
+ wovenClass.checkPermission();
return imports.remove(index);
}
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java
index 8786973e2..9198e8f29 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/weaving/WovenClassImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2011 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
@@ -40,7 +40,7 @@ public final class WovenClassImpl implements WovenClass, HookContext {
super();
this.className = className;
this.bytes = bytes;
- this.dynamicImports = new DynamicImportList();
+ this.dynamicImports = new DynamicImportList(this);
this.domain = domain;
this.loader = loader;
this.registry = registry;
@@ -48,8 +48,10 @@ public final class WovenClassImpl implements WovenClass, HookContext {
}
public byte[] getBytes() {
- if ((hookFlags & FLAG_HOOKSCOMPLETE) == 0)
+ if ((hookFlags & FLAG_HOOKSCOMPLETE) == 0) {
+ checkPermission();
return bytes; // return raw bytes until complete
+ }
// we have called all hooks; someone is calling outside of weave call
// need to be safe and copy the bytes.
byte[] current = bytes;
@@ -59,6 +61,7 @@ public final class WovenClassImpl implements WovenClass, HookContext {
}
public void setBytes(byte[] newBytes) {
+ checkPermission();
if (newBytes == null)
throw new NullPointerException("newBytes cannot be null."); //$NON-NLS-1$
if ((hookFlags & FLAG_HOOKSCOMPLETE) != 0)
@@ -67,6 +70,12 @@ public final class WovenClassImpl implements WovenClass, HookContext {
this.bytes = newBytes;
}
+ void checkPermission() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AdminPermission(loader.getBundle(), AdminPermission.WEAVE));
+ }
+
public List<String> getDynamicImports() {
if ((hookFlags & FLAG_HOOKSCOMPLETE) == 0)
return dynamicImports;
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/AdminPermission.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/AdminPermission.java
index 85c5a8f4d..fc7b1f4aa 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/AdminPermission.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/AdminPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) OSGi Alliance (2000, 2010). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2000, 2011). All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ import java.util.Map;
* class Bundle.loadClass
* execute Bundle.start
* Bundle.stop
- * StartLevel.setBundleStartLevel
+ * BundleStartLevel.setStartLevel
* extensionLifecycle BundleContext.installBundle for extension bundles
* Bundle.update for extension bundles
* Bundle.uninstall for extension bundles
@@ -56,23 +56,25 @@ import java.util.Map;
* BundleContext.removeBundleListener for SynchronousBundleListener
* metadata Bundle.getHeaders
* Bundle.getLocation
- * resolve PackageAdmin.refreshPackages
- * PackageAdmin.resolveBundles
+ * resolve FrameworkWiring.refreshBundles
+ * FrameworkWiring.resolveBundles
* resource Bundle.getResource
* Bundle.getResources
* Bundle.getEntry
* Bundle.getEntryPaths
* Bundle.findEntries
* Bundle resource/entry URL creation
- * startlevel StartLevel.setStartLevel
- * StartLevel.setInitialBundleStartLevel
+ * startlevel FrameworkStartLevel.setStartLevel
+ * FrameworkStartLevel.setInitialBundleStartLevel
* context Bundle.getBundleContext
+ * weave WovenClass.setBytes
+ * WovenClass.getDynamicImports for modification
* </pre>
*
* <p>
* The special action &quot;*&quot; will represent all actions. The
- * {@code resolve} action is implied by the {@code class},
- * {@code execute} and {@code resource} actions.
+ * {@code resolve} action is implied by the {@code class}, {@code execute} and
+ * {@code resource} actions.
* <p>
* The name of this permission is a filter expression. The filter gives access
* to the following attributes:
@@ -87,7 +89,7 @@ import java.util.Map;
* Filter attribute names are processed in a case sensitive manner.
*
* @ThreadSafe
- * @version $Id: 8488ac114b71f92331d3a6739b878e4bd55fecdb $
+ * @version $Id: 43baf9a6d7ce5e6108507834e841e340fd91c513 $
*/
public final class AdminPermission extends BasicPermission {
@@ -160,6 +162,13 @@ public final class AdminPermission extends BasicPermission {
*/
public final static String CONTEXT = "context";
+ /**
+ * The action string {@code weave}.
+ *
+ * @since 1.6
+ */
+ public final static String WEAVE = "weave";
+
private final static int ACTION_CLASS = 0x00000001;
private final static int ACTION_EXECUTE = 0x00000002;
private final static int ACTION_LIFECYCLE = 0x00000004;
@@ -170,6 +179,7 @@ public final class AdminPermission extends BasicPermission {
private final static int ACTION_STARTLEVEL = 0x00000100;
private final static int ACTION_EXTENSIONLIFECYCLE = 0x00000200;
private final static int ACTION_CONTEXT = 0x00000400;
+ private final static int ACTION_WEAVE = 0x00000800;
private final static int ACTION_ALL = ACTION_CLASS
| ACTION_EXECUTE
| ACTION_LIFECYCLE
@@ -179,7 +189,8 @@ public final class AdminPermission extends BasicPermission {
| ACTION_RESOURCE
| ACTION_STARTLEVEL
| ACTION_EXTENSIONLIFECYCLE
- | ACTION_CONTEXT;
+ | ACTION_CONTEXT
+ | ACTION_WEAVE;
final static int ACTION_NONE = 0;
/**
@@ -247,14 +258,13 @@ public final class AdminPermission extends BasicPermission {
* Null arguments are equivalent to "*".
*
* @param filter A filter expression that can use signer, location, id, and
- * name keys. A value of &quot;*&quot; or {@code null} matches
- * all bundle. Filter attribute names are processed in a case
- * sensitive manner.
- * @param actions {@code class}, {@code execute},
- * {@code extensionLifecycle}, {@code lifecycle},
- * {@code listener}, {@code metadata}, {@code resolve}
- * , {@code resource}, {@code startlevel} or
- * {@code context}. A value of "*" or {@code null}
+ * name keys. A value of &quot;*&quot; or {@code null} matches all
+ * bundle. Filter attribute names are processed in a case sensitive
+ * manner.
+ * @param actions {@code class}, {@code execute}, {@code extensionLifecycle}
+ * , {@code lifecycle}, {@code listener}, {@code metadata},
+ * {@code resolve} , {@code resource}, {@code startlevel},
+ * {@code context} or {@code weave}. A value of "*" or {@code null}
* indicates all actions.
* @throws IllegalArgumentException If the filter has an invalid syntax.
*/
@@ -265,17 +275,16 @@ public final class AdminPermission extends BasicPermission {
}
/**
- * Creates a new requested {@code AdminPermission} object to be used by
- * the code that must perform {@code checkPermission}.
- * {@code AdminPermission} objects created with this constructor cannot
- * be added to an {@code AdminPermission} permission collection.
+ * Creates a new requested {@code AdminPermission} object to be used by the
+ * code that must perform {@code checkPermission}. {@code AdminPermission}
+ * objects created with this constructor cannot be added to an
+ * {@code AdminPermission} permission collection.
*
* @param bundle A bundle.
- * @param actions {@code class}, {@code execute},
- * {@code extensionLifecycle}, {@code lifecycle},
- * {@code listener}, {@code metadata}, {@code resolve}
- * , {@code resource}, {@code startlevel},
- * {@code context}. A value of "*" or {@code null}
+ * @param actions {@code class}, {@code execute}, {@code extensionLifecycle}
+ * , {@code lifecycle}, {@code listener}, {@code metadata},
+ * {@code resolve} , {@code resource}, {@code startlevel},
+ * {@code context}, {@code weave}. A value of "*" or {@code null}
* indicates all actions.
* @since 1.3
*/
@@ -503,19 +512,29 @@ public final class AdminPermission extends BasicPermission {
}
else
- if (i >= 0 &&
-
- (a[i] == '*')) {
- matchlen = 1;
- mask |= ACTION_ALL;
-
- }
- else {
- // parse error
- throw new IllegalArgumentException(
- "invalid permission: "
- + actions);
+ if (i >= 4
+ && (a[i - 4] == 'w' || a[i - 4] == 'W')
+ && (a[i - 3] == 'e' || a[i - 3] == 'E')
+ && (a[i - 2] == 'a' || a[i - 2] == 'A')
+ && (a[i - 1] == 'v' || a[i - 1] == 'V')
+ && (a[i] == 'e' || a[i] == 'E')) {
+ matchlen = 5;
+ mask |= ACTION_WEAVE;
+
}
+ else
+ if (i >= 0
+ && (a[i] == '*')) {
+ matchlen = 1;
+ mask |= ACTION_ALL;
+
+ }
+ else {
+ // parse error
+ throw new IllegalArgumentException(
+ "invalid permission: "
+ + actions);
+ }
// make sure we didn't just match the tail of a word
// like "ackbarfstartlevel". Also, skip to the comma.
@@ -668,14 +687,13 @@ public final class AdminPermission extends BasicPermission {
* {@code AdminPermission} actions.
*
* <p>
- * Always returns present {@code AdminPermission} actions in the
- * following order: {@code class}, {@code execute},
- * {@code extensionLifecycle}, {@code lifecycle},
- * {@code listener}, {@code metadata}, {@code resolve},
- * {@code resource}, {@code startlevel}, {@code context}.
+ * Always returns present {@code AdminPermission} actions in the following
+ * order: {@code class}, {@code execute}, {@code extensionLifecycle},
+ * {@code lifecycle}, {@code listener}, {@code metadata}, {@code resolve},
+ * {@code resource}, {@code startlevel}, {@code context}, {@code weave}.
*
- * @return Canonical string representation of the
- * {@code AdminPermission} actions.
+ * @return Canonical string representation of the {@code AdminPermission}
+ * actions.
*/
public String getActions() {
String result = actions;
@@ -732,6 +750,11 @@ public final class AdminPermission extends BasicPermission {
sb.append(CONTEXT);
sb.append(',');
}
+
+ if ((mask & ACTION_WEAVE) == ACTION_WEAVE) {
+ sb.append(WEAVE);
+ sb.append(',');
+ }
// remove trailing comma
if (sb.length() > 0) {

Back to the top