You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/05/09 14:46:22 UTC

svn commit: r1336155 - in /karaf/cellar/trunk/bundle/src/main: java/org/apache/karaf/cellar/bundle/shell/ resources/OSGI-INF/blueprint/

Author: jbonofre
Date: Wed May  9 12:46:21 2012
New Revision: 1336155

URL: http://svn.apache.org/viewvc?rev=1336155&view=rev
Log:
[KARAF-1429] cluster:bundle-* commands check if the cluster event is allowed outbound

Modified:
    karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
    karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
    karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
    karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
    karaf/cellar/trunk/bundle/src/main/resources/OSGI-INF/blueprint/shell-bundle.xml

Modified: karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java?rev=1336155&r1=1336154&r2=1336155&view=diff
==============================================================================
--- karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java (original)
+++ karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java Wed May  9 12:46:21 2012
@@ -16,10 +16,12 @@ package org.apache.karaf.cellar.bundle.s
 import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.Constants;
 import org.apache.karaf.cellar.bundle.RemoteBundleEvent;
+import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
@@ -61,35 +63,46 @@ public class InstallBundleCommand extend
             return null;
         }
 
+        CellarSupport support = new CellarSupport();
+        support.setClusterManager(this.clusterManager);
+        support.setGroupManager(this.groupManager);
+        support.setConfigurationAdmin(this.configurationAdmin);
+
         for (String url : urls) {
-            // get the name and version in the location MANIFEST
-            JarInputStream jarInputStream = new JarInputStream(new URL(url).openStream());
-            Manifest manifest = jarInputStream.getManifest();
-            String name = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
-            String version = manifest.getMainAttributes().getValue("Bundle-Version");
-            jarInputStream.close();
-
-            ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
-            try {
-                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-                // populate the cluster map
-                Map<String, BundleState> bundles = clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
-                BundleState state = new BundleState();
-                state.setLocation(url);
-                if (start) {
-                    state.setStatus(BundleEvent.STARTED);
-                } else {
-                    state.setStatus(BundleEvent.INSTALLED);
+            // check if the bundle is allowed
+            if (support.isAllowed(group, Constants.CATEGORY, url, EventType.OUTBOUND)) {
+
+                // get the name and version in the location MANIFEST
+                JarInputStream jarInputStream = new JarInputStream(new URL(url).openStream());
+                Manifest manifest = jarInputStream.getManifest();
+                String name = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
+                String version = manifest.getMainAttributes().getValue("Bundle-Version");
+                jarInputStream.close();
+
+                ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+                try {
+                    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+                    // populate the cluster map
+                    Map<String, BundleState> bundles = clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
+                    BundleState state = new BundleState();
+                    state.setLocation(url);
+                    if (start) {
+                        state.setStatus(BundleEvent.STARTED);
+                    } else {
+                        state.setStatus(BundleEvent.INSTALLED);
+                    }
+                    bundles.put(name + "/" + version, state);
+                } finally {
+                    Thread.currentThread().setContextClassLoader(originalClassLoader);
                 }
-                bundles.put(name + "/" + version, state);
-            } finally {
-                Thread.currentThread().setContextClassLoader(originalClassLoader);
-            }
 
-            // broadcast the event
-            RemoteBundleEvent event = new RemoteBundleEvent(name, version, url, BundleEvent.INSTALLED);
-            event.setSourceGroup(group);
-            eventProducer.produce(event);
+                // broadcast the cluster event
+                RemoteBundleEvent event = new RemoteBundleEvent(name, version, url, BundleEvent.INSTALLED);
+                event.setSourceGroup(group);
+                eventProducer.produce(event);
+            } else {
+                System.err.println("Bundle from " + url + " is blocked outbound");
+            }
         }
 
         return null;

Modified: karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java?rev=1336155&r1=1336154&r2=1336155&view=diff
==============================================================================
--- karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java (original)
+++ karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java Wed May  9 12:46:21 2012
@@ -16,10 +16,12 @@ package org.apache.karaf.cellar.bundle.s
 import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.Constants;
 import org.apache.karaf.cellar.bundle.RemoteBundleEvent;
+import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
@@ -67,6 +69,18 @@ public class StartBundleCommand extends 
                 System.err.println("Bundle " + name + "/" + version + " not found in cluster group " + groupName);
                 return null;
             }
+            location = state.getLocation();
+
+            // check if the bundle is allowed
+            CellarSupport support = new CellarSupport();
+            support.setClusterManager(this.clusterManager);
+            support.setGroupManager(this.groupManager);
+            support.setConfigurationAdmin(this.configurationAdmin);
+            if (!support.isAllowed(group, Constants.CATEGORY, location, EventType.OUTBOUND)) {
+                System.err.println("Bundle on " + location + " is blocked outbound");
+                return null;
+            }
+
             state.setStatus(BundleEvent.STARTED);
             location = state.getLocation();
             bundles.put(name + "/" + version, state);

Modified: karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java?rev=1336155&r1=1336154&r2=1336155&view=diff
==============================================================================
--- karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java (original)
+++ karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java Wed May  9 12:46:21 2012
@@ -16,10 +16,12 @@ package org.apache.karaf.cellar.bundle.s
 import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.Constants;
 import org.apache.karaf.cellar.bundle.RemoteBundleEvent;
+import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
@@ -69,6 +71,17 @@ public class StopBundleCommand extends C
             }
             state.setStatus(BundleEvent.STOPPED);
             location = state.getLocation();
+
+            // check if the bundle is allowed
+            CellarSupport support = new CellarSupport();
+            support.setClusterManager(this.clusterManager);
+            support.setGroupManager(this.groupManager);
+            support.setConfigurationAdmin(this.configurationAdmin);
+            if (!support.isAllowed(group, Constants.CATEGORY, location, EventType.OUTBOUND)) {
+                System.err.println("Bundle on " + location + " is blocked outbound");
+                return null;
+            }
+
             bundles.put(name + "/" + version, state);
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);

Modified: karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java?rev=1336155&r1=1336154&r2=1336155&view=diff
==============================================================================
--- karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java (original)
+++ karaf/cellar/trunk/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java Wed May  9 12:46:21 2012
@@ -16,10 +16,12 @@ package org.apache.karaf.cellar.bundle.s
 import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.Constants;
 import org.apache.karaf.cellar.bundle.RemoteBundleEvent;
+import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
+import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
@@ -68,6 +70,17 @@ public class UninstallBundleCommand exte
                 return null;
             }
             location = state.getLocation();
+
+            // check if the bundle is allowed
+            CellarSupport support = new CellarSupport();
+            support.setClusterManager(this.clusterManager);
+            support.setGroupManager(this.groupManager);
+            support.setConfigurationAdmin(this.configurationAdmin);
+            if (!support.isAllowed(group, Constants.CATEGORY, location, EventType.OUTBOUND)) {
+                System.err.println("Bundle on " + location + " is blocked outbound");
+                return null;
+            }
+
             bundles.remove(name + "/" + version);
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);

Modified: karaf/cellar/trunk/bundle/src/main/resources/OSGI-INF/blueprint/shell-bundle.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/bundle/src/main/resources/OSGI-INF/blueprint/shell-bundle.xml?rev=1336155&r1=1336154&r2=1336155&view=diff
==============================================================================
--- karaf/cellar/trunk/bundle/src/main/resources/OSGI-INF/blueprint/shell-bundle.xml (original)
+++ karaf/cellar/trunk/bundle/src/main/resources/OSGI-INF/blueprint/shell-bundle.xml Wed May  9 12:46:21 2012
@@ -29,6 +29,7 @@
                 <property name="clusterManager" ref="clusterManager"/>
                 <property name="groupManager" ref="groupManager"/>
                 <property name="eventProducer" ref="eventProducer"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
             </action>
             <completers>
                 <ref component-id="allGroupCompleter"/>
@@ -39,6 +40,7 @@
                 <property name="clusterManager" ref="clusterManager"/>
                 <property name="groupManager" ref="groupManager"/>
                 <property name="eventProducer" ref="eventProducer"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
             </action>
             <completers>
                 <ref component-id="allGroupCompleter"/>
@@ -51,6 +53,7 @@
                 <property name="clusterManager" ref="clusterManager"/>
                 <property name="groupManager" ref="groupManager"/>
                 <property name="eventProducer" ref="eventProducer"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
             </action>
             <completers>
                 <ref component-id="allGroupCompleter"/>
@@ -63,6 +66,7 @@
                 <property name="clusterManager" ref="clusterManager"/>
                 <property name="groupManager" ref="groupManager"/>
                 <property name="eventProducer" ref="eventProducer"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
             </action>
             <completers>
                 <ref component-id="allGroupCompleter"/>