You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/09/08 15:58:46 UTC

svn commit: r812513 - in /felix/trunk/webconsole: ./ src/main/java/org/apache/felix/webconsole/internal/servlet/ src/main/resources/OSGI-INF/ src/main/resources/res/ui/

Author: fmeschbe
Date: Tue Sep  8 13:58:45 2009
New Revision: 812513

URL: http://svn.apache.org/viewvc?rev=812513&view=rev
Log:
FELIX-1014 Support disabling select console plugins provided by the
Web Console bundle itself. The ConfigurationListener now also implements
the MetaTypeProvider interface to provide the ObjectClassDefinition for
the configurtion on demand based on the actual list of configured
plugin classes.

Removed:
    felix/trunk/webconsole/src/main/resources/OSGI-INF/
Modified:
    felix/trunk/webconsole/pom.xml
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
    felix/trunk/webconsole/src/main/resources/res/ui/admin.css
    felix/trunk/webconsole/src/main/resources/res/ui/configmanager.js

Modified: felix/trunk/webconsole/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/pom.xml?rev=812513&r1=812512&r2=812513&view=diff
==============================================================================
--- felix/trunk/webconsole/pom.xml (original)
+++ felix/trunk/webconsole/pom.xml Tue Sep  8 13:58:45 2009
@@ -47,19 +47,6 @@
         <plugins>
             <plugin>
                 <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
-                <version>1.0.8</version>
-                <executions>
-                    <execution>
-                        <id>generate-scr-scrdescriptor</id>
-                        <goals>
-                            <goal>scr</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <version>1.4.3</version>
                 <extensions>true</extensions>

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java?rev=812513&r1=812512&r2=812513&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java Tue Sep  8 13:58:45 2009
@@ -19,19 +19,30 @@
 package org.apache.felix.webconsole.internal.servlet;
 
 
+import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.LinkedHashMap;
 
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ManagedService;
+import org.osgi.service.metatype.AttributeDefinition;
+import org.osgi.service.metatype.MetaTypeProvider;
+import org.osgi.service.metatype.ObjectClassDefinition;
 
 
-class ConfigurationListener implements ManagedService
+class ConfigurationListener implements ManagedService, MetaTypeProvider
 {
 
+    private final String pid;
+
     private final OsgiManager osgiManager;
 
+    private ObjectClassDefinition ocd;
+
 
     static ServiceRegistration create( OsgiManager osgiManager )
     {
@@ -40,20 +51,218 @@
         Dictionary props = new Hashtable();
         props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
         props.put( Constants.SERVICE_DESCRIPTION, "OSGi Management Console Configuration Receiver" );
-        props.put( Constants.SERVICE_PID, osgiManager.getClass().getName() );
+        props.put( Constants.SERVICE_PID, cl.pid );
 
-        return osgiManager.getBundleContext().registerService( ManagedService.class.getName(), cl, props );
+        return osgiManager.getBundleContext().registerService( new String[]
+            { ManagedService.class.getName(), MetaTypeProvider.class.getName() }, cl, props );
     }
 
 
     private ConfigurationListener( OsgiManager osgiManager )
     {
         this.osgiManager = osgiManager;
+        this.pid = osgiManager.getClass().getName();
     }
 
 
+    //---------- ManagedService
+
     public void updated( Dictionary config )
     {
         osgiManager.updateConfiguration( config );
     }
+
+
+    //---------- MetaTypeProvider
+
+    public String[] getLocales()
+    {
+        // there is no locale support here
+        return null;
+    }
+
+
+    public ObjectClassDefinition getObjectClassDefinition( String id, String locale )
+    {
+        if ( !pid.equals( id ) )
+        {
+            return null;
+        }
+
+        if ( ocd == null )
+        {
+
+            final ArrayList adList = new ArrayList();
+            adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_MANAGER_ROOT, "Root URI",
+                "The root path to the OSGi Management Console.", OsgiManager.DEFAULT_MANAGER_ROOT ) );
+            adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_DEFAULT_RENDER, "Default Page",
+                "The name of the default configuration page when invoking the OSGi Management console.",
+                OsgiManager.DEFAULT_PAGE ) );
+            adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_REALM, "Realm",
+                "The name of the HTTP Authentication Realm.", OsgiManager.DEFAULT_REALM ) );
+            adList
+                .add( new AttributeDefinitionImpl(
+                    OsgiManager.PROP_USER_NAME,
+                    "User Name",
+                    "The name of the user allowed to access the OSGi Management Console. To disable authentication clear this value.",
+                    OsgiManager.DEFAULT_USER_NAME ) );
+            adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_PASSWORD, "Password",
+                "The password for the user allowed to access the OSGi Management Console.",
+                OsgiManager.DEFAULT_PASSWORD ) );
+
+            final LinkedHashMap namesByClassName = new LinkedHashMap();
+            final ClassLoader loader = getClass().getClassLoader();
+            final String[] defaultPluginsClasses = OsgiManager.PLUGIN_CLASSES;
+            for ( int i = 0; i < defaultPluginsClasses.length; i++ )
+            {
+                try
+                {
+                    final Object plugin = loader.loadClass( defaultPluginsClasses[i] ).newInstance();
+                    if ( plugin instanceof AbstractWebConsolePlugin )
+                    {
+                        final String name = ( ( AbstractWebConsolePlugin ) plugin ).getTitle();
+                        namesByClassName.put( defaultPluginsClasses[i], name );
+                    }
+                }
+                catch ( Throwable t )
+                {
+                    // ignore
+                }
+            }
+            final String[] classes = ( String[] ) namesByClassName.keySet().toArray(
+                new String[namesByClassName.size()] );
+            final String[] names = ( String[] ) namesByClassName.values().toArray( new String[namesByClassName.size()] );
+
+            adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_ENABLED_PLUGINS, "Plugins",
+                "Select active plugins", AttributeDefinition.STRING, classes, Integer.MIN_VALUE, names, classes ) );
+
+            ocd = new ObjectClassDefinition()
+            {
+
+                private final AttributeDefinition[] attrs = ( AttributeDefinition[] ) adList
+                    .toArray( new AttributeDefinition[adList.size()] );
+
+
+                public String getName()
+                {
+                    return "Apache Felix OSGi Management Console";
+                }
+
+
+                public InputStream getIcon( int arg0 )
+                {
+                    return null;
+                }
+
+
+                public String getID()
+                {
+                    return pid;
+                }
+
+
+                public String getDescription()
+                {
+                    return "Configuration of the Apache Felix OSGi Management Console.";
+                }
+
+
+                public AttributeDefinition[] getAttributeDefinitions( int filter )
+                {
+                    return ( filter == OPTIONAL ) ? null : attrs;
+                }
+            };
+        }
+
+        return ocd;
+    }
+
+    private static class AttributeDefinitionImpl implements AttributeDefinition
+    {
+
+        private final String id;
+        private final String name;
+        private final String description;
+        private final int type;
+        private final String[] defaultValues;
+        private final int cardinality;
+        private final String[] optionLabels;
+        private final String[] optionValues;
+
+
+        AttributeDefinitionImpl( final String id, final String name, final String description, final String defaultValue )
+        {
+            this( id, name, description, STRING, new String[]
+                { defaultValue }, 0, null, null );
+        }
+
+
+        AttributeDefinitionImpl( final String id, final String name, final String description, final int type,
+            final String[] defaultValues, final int cardinality, final String[] optionLabels,
+            final String[] optionValues )
+        {
+            this.id = id;
+            this.name = name;
+            this.description = description;
+            this.type = type;
+            this.defaultValues = defaultValues;
+            this.cardinality = cardinality;
+            this.optionLabels = optionLabels;
+            this.optionValues = optionValues;
+        }
+
+
+        public int getCardinality()
+        {
+            return cardinality;
+        }
+
+
+        public String[] getDefaultValue()
+        {
+            return defaultValues;
+        }
+
+
+        public String getDescription()
+        {
+            return description;
+        }
+
+
+        public String getID()
+        {
+            return id;
+        }
+
+
+        public String getName()
+        {
+            return name;
+        }
+
+
+        public String[] getOptionLabels()
+        {
+            return optionLabels;
+        }
+
+
+        public String[] getOptionValues()
+        {
+            return optionValues;
+        }
+
+
+        public int getType()
+        {
+            return type;
+        }
+
+
+        public String validate( String arg0 )
+        {
+            return null;
+        }
+    }
 }
\ No newline at end of file

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=812513&r1=812512&r2=812513&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java Tue Sep  8 13:58:45 2009
@@ -18,12 +18,15 @@
 
 
 import java.io.IOException;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.GenericServlet;
 import javax.servlet.Servlet;
@@ -54,9 +57,6 @@
 
 /**
  * The <code>OSGi Manager</code> TODO
- *
- * @scr.component ds="no" label="%manager.name"
- *                description="%manager.description"
  */
 public class OsgiManager extends GenericServlet
 {
@@ -89,46 +89,33 @@
      */
     public static final String PARAM_NO_REDIRECT_AFTER_ACTION = "_noredir_";
 
-    /**
-     * @scr.property valueRef="DEFAULT_MANAGER_ROOT"
-     */
-    private static final String PROP_MANAGER_ROOT = "manager.root";
+    static final String PROP_MANAGER_ROOT = "manager.root";
 
-    /**
-     * @scr.property valueRef="DEFAULT_PAGE"
-     */
-    private static final String PROP_DEFAULT_RENDER = "default.render";
+    static final String PROP_DEFAULT_RENDER = "default.render";
 
-    /**
-     * @scr.property valueRef="DEFAULT_REALM"
-     */
-    private static final String PROP_REALM = "realm";
+    static final String PROP_REALM = "realm";
 
-    /**
-     * @scr.property valueRef="DEFAULT_USER_NAME"
-     */
-    private static final String PROP_USER_NAME = "username";
+    static final String PROP_USER_NAME = "username";
 
-    /**
-     * @scr.property valueRef="DEFAULT_PASSWORD"
-     */
-    private static final String PROP_PASSWORD = "password";
+    static final String PROP_PASSWORD = "password";
 
-    private static final String DEFAULT_PAGE = BundlesServlet.NAME;
+    static final String PROP_ENABLED_PLUGINS = "plugins";
 
-    private static final String DEFAULT_REALM = "OSGi Management Console";
+    static final String DEFAULT_PAGE = BundlesServlet.NAME;
 
-    private static final String DEFAULT_USER_NAME = "admin";
+    static final String DEFAULT_REALM = "OSGi Management Console";
 
-    private static final String DEFAULT_PASSWORD = "admin";
+    static final String DEFAULT_USER_NAME = "admin";
+
+    static final String DEFAULT_PASSWORD = "admin";
 
     /**
      * The default value for the {@link #PROP_MANAGER_ROOT} configuration
      * property (value is "/system/console").
      */
-    private static final String DEFAULT_MANAGER_ROOT = "/system/console";
+    static final String DEFAULT_MANAGER_ROOT = "/system/console";
 
-    private static final String[] PLUGIN_CLASSES =
+    static final String[] PLUGIN_CLASSES =
         { "org.apache.felix.webconsole.internal.compendium.ComponentConfigurationPrinter",
             "org.apache.felix.webconsole.internal.compendium.ComponentsServlet",
             "org.apache.felix.webconsole.internal.compendium.ConfigManager",
@@ -183,6 +170,8 @@
 
     private Dictionary configuration;
 
+    private Set enabledPlugins;
+
 
     public OsgiManager( BundleContext bundleContext )
     {
@@ -246,10 +235,19 @@
         for ( int i = 0; i < PLUGIN_CLASSES.length; i++ )
         {
             String pluginClassName = PLUGIN_CLASSES[i];
+
             try
             {
                 Class pluginClass = classLoader.loadClass( pluginClassName );
                 Object plugin = pluginClass.newInstance();
+
+                // check whether enabled by configuration
+                if ( isPluginDisabled( pluginClassName, plugin ) )
+                {
+                    log.log( LogService.LOG_INFO, "Ignoring plugin " + pluginClassName + ": Disabled by configuration" );
+                    continue;
+                }
+
                 if ( plugin instanceof OsgiManagerPlugin )
                 {
                     ( ( OsgiManagerPlugin ) plugin ).activate( bundleContext );
@@ -785,6 +783,27 @@
             webManagerRoot = "/" + webManagerRoot;
         }
 
+        // get enabled plugins
+        Object pluginValue = config.get( PROP_ENABLED_PLUGINS );
+        if ( pluginValue == null )
+        {
+            enabledPlugins = null;
+        }
+        else if ( pluginValue.getClass().isArray() )
+        {
+            final Object[] names = ( Object[] ) pluginValue;
+            enabledPlugins = new HashSet();
+            for ( int i = 0; i < names.length; i++ )
+            {
+                enabledPlugins.add( String.valueOf( names[i] ) );
+            }
+        }
+        else if ( pluginValue instanceof Collection )
+        {
+            enabledPlugins = new HashSet();
+            enabledPlugins.addAll( ( Collection ) pluginValue );
+        }
+
         // might update http service registration
         HttpService httpService = this.httpService;
         if ( httpService != null )
@@ -825,6 +844,22 @@
     }
 
 
+    /**
+     * Returns <code>true</code> if the plugin is an
+     * {@link AbstractWebConsolePlugin} and a list of enabled plugins is
+     * configured but the plugin is not contained in that list.
+     * <p>
+     * This method is intended to be used only for plugins contained in the
+     * web console bundle itself, namely plugins listed in the
+     * {@value #PLUGIN_CLASSES} list.
+     */
+    private boolean isPluginDisabled( String pluginClass, Object plugin )
+    {
+        return enabledPlugins != null && !enabledPlugins.contains( pluginClass )
+            && ( plugin instanceof AbstractWebConsolePlugin );
+    }
+
+
     private Dictionary toStringConfig( Dictionary config )
     {
         Dictionary stringConfig = new Hashtable();

Modified: felix/trunk/webconsole/src/main/resources/res/ui/admin.css
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/admin.css?rev=812513&r1=812512&r2=812513&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/admin.css (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/admin.css Tue Sep  8 13:58:45 2009
@@ -375,6 +375,10 @@
     border-right: 1px solid #cccccc;
 }
 
+.multiselect {
+    display: block;
+}
+
 .fileinput {
     font-family: Verdana, Arial, Helvetica, san-serif;
     font-size: 9px;

Modified: felix/trunk/webconsole/src/main/resources/res/ui/configmanager.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/configmanager.js?rev=812513&r1=812512&r2=812513&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/configmanager.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/configmanager.js Tue Sep  8 13:58:45 2009
@@ -407,7 +407,7 @@
             inputEl.setAttribute( "checked", true );
         }
         
-        var labelEl = createElement( "label" );
+        var labelEl = createElement( "label", "multiselect" );
         labelEl.appendChild( inputEl );
         addText( labelEl, labels[idx] );