You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/02/25 23:54:09 UTC

cvs commit: avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test TargetsTestCase.java

mcconnell    2004/02/25 14:54:09

  Modified:    merlin/composition/api/src/java/org/apache/avalon/composition/data
                        TargetDirective.java
               merlin/composition/api/src/java/org/apache/avalon/composition/model
                        ComponentModel.java ContainmentModel.java
                        DeploymentModel.java
               merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder
                        XMLTargetsCreator.java
               merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
                        DefaultContext.java DefaultDeploymentModel.java
                        DefaultSecurityModel.java OverrideEntryModel.java
               merlin/composition/impl/src/test/conf targets-config.xml
               merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl
                        SimpleDeploymentModel.java
               merlin/composition/impl/src/test/org/apache/avalon/composition/model/test
                        TargetsTestCase.java
  Log:
  Extend <target> to include GrantDirective.
  
  Revision  Changes    Path
  1.5       +40 -2     avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java
  
  Index: TargetDirective.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TargetDirective.java	24 Feb 2004 22:18:21 -0000	1.4
  +++ TargetDirective.java	25 Feb 2004 22:54:09 -0000	1.5
  @@ -19,6 +19,8 @@
   
   import java.io.Serializable;
   
  +import org.apache.avalon.composition.data.GrantDirective;
  +
   import org.apache.avalon.framework.configuration.Configuration;
   
   import org.apache.avalon.logging.data.CategoriesDirective;
  @@ -53,6 +55,11 @@
        */
       private final CategoriesDirective m_categories;
   
  +    /**
  +     * Supplimentary permissions assignable to a classloader.
  +     */
  +    private final GrantDirective m_grant;
  +
       //========================================================================
       // constructors
       //========================================================================
  @@ -93,6 +100,25 @@
           m_path = path;
           m_config = configuration;
           m_categories = categories;
  +        m_grant = null;
  +    }
  +
  +    /**
  +     * Create a new Target instance applyable to a container.
  +     *
  +     * @param path target container path
  +     * @param categories the logging category directives 
  +     * @param grant a grant directive
  +     */
  +    public TargetDirective( 
  +      final String path, 
  +      final CategoriesDirective categories, 
  +      final GrantDirective grant )
  +    {
  +        m_path = path;
  +        m_categories = categories;
  +        m_grant = grant;
  +        m_config = null;
       }
   
       //========================================================================
  @@ -120,6 +146,18 @@
       }
   
       /**
  +     * Return an optional grant directive that may be applied as 
  +     * a supplimentary security context during the establishment of 
  +     * a new container classloader.
  +     *
  +     * @return the grant directive (possibly null)
  +     */
  +    public GrantDirective getGrantDirective()
  +    {
  +        return m_grant;
  +    }
  +
  +    /**
        * Return the logging categories directive.
        *
        * @return the logging categories (possibly null)
  @@ -138,7 +176,7 @@
           return "[target: " + getPath() + ", " 
             + (getConfiguration() != null ) + ", " 
             + (getCategoriesDirective() != null ) + ", " 
  +          + (getGrantDirective() != null )
             + " ]";
       }
  -
   }
  
  
  
  1.5       +1 -13     avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ComponentModel.java
  
  Index: ComponentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ComponentModel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ComponentModel.java	10 Feb 2004 16:23:33 -0000	1.4
  +++ ComponentModel.java	25 Feb 2004 22:54:09 -0000	1.5
  @@ -70,18 +70,6 @@
       void setCollectionPolicy( int policy );
   
      /**
  -    * Return the logging categories. 
  -    * @return the logging categories
  -    */
  -    CategoriesDirective getCategories();
  -
  -   /**
  -    * Set categories. 
  -    * @param categories the logging categories
  -    */
  -    void setCategories( CategoriesDirective categories );
  -
  -   /**
       * Set the activation policy for the model. 
       * @param policy the activaltion policy
       */
  
  
  
  1.21      +1 -13     avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java
  
  Index: ContainmentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ContainmentModel.java	23 Feb 2004 15:03:22 -0000	1.20
  +++ ContainmentModel.java	25 Feb 2004 22:54:09 -0000	1.21
  @@ -53,18 +53,6 @@
       DeploymentModel[] getShutdownGraph();
   
      /**
  -    * Return the logging categories. 
  -    * @return the logging categories
  -    */
  -    CategoriesDirective getCategories();
  -
  -   /**
  -    * Set categories. 
  -    * @param categories the logging categories
  -    */
  -    void setCategories( CategoriesDirective categories );
  -
  -   /**
       * Return the partition established by the containment model.
       *
       * @return the partition name
  
  
  
  1.17      +16 -1     avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java
  
  Index: DeploymentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DeploymentModel.java	24 Feb 2004 22:18:21 -0000	1.16
  +++ DeploymentModel.java	25 Feb 2004 22:54:09 -0000	1.17
  @@ -30,6 +30,9 @@
   
   import org.apache.avalon.framework.logger.Logger;
   
  +import org.apache.avalon.logging.data.CategoriesDirective;
  +
  +
   /**
    * Model desribing a deployment scenario.
    *
  @@ -71,6 +74,18 @@
       * @return the logging channel
       */
       Logger getLogger();
  +
  +   /**
  +    * Return the logging categories. 
  +    * @return the logging categories
  +    */
  +    CategoriesDirective getCategories();
  +
  +   /**
  +    * Set categories. 
  +    * @param categories the logging categories
  +    */
  +    void setCategories( CategoriesDirective categories );
   
       //-----------------------------------------------------------
       // service production
  
  
  
  1.6       +127 -6    avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java
  
  Index: XMLTargetsCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLTargetsCreator.java	21 Feb 2004 13:27:03 -0000	1.5
  +++ XMLTargetsCreator.java	25 Feb 2004 22:54:09 -0000	1.6
  @@ -17,10 +17,22 @@
   
   package org.apache.avalon.composition.data.builder;
   
  -import org.apache.avalon.framework.configuration.Configuration;
  +import java.io.IOException;
  +import java.util.ArrayList;
  +import java.security.cert.CertificateException;
  +
   import org.apache.avalon.logging.data.CategoriesDirective;
  +
  +import org.apache.avalon.composition.data.GrantDirective;
  +import org.apache.avalon.composition.data.CertsDirective;
  +import org.apache.avalon.composition.data.PermissionDirective;
  +import org.apache.avalon.composition.data.PKCS7Directive;
   import org.apache.avalon.composition.data.TargetDirective;
   import org.apache.avalon.composition.data.Targets;
  +import org.apache.avalon.composition.data.X509Directive;
  +
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   
   /**
    * Handles internalization of an XML based description of a {@link Targets}
  @@ -57,14 +69,123 @@
       private TargetDirective createTargetDirective( Configuration config )
         throws Exception
       {
  +        //
  +        // get the address of the object we are overriding
  +        //
  +
           String name = config.getAttribute( "name", null ); // legacy
           if( name == null )
           {
               name = config.getAttribute( "path" );
           }
  -        final Configuration conf = config.getChild( "configuration", false );
  -        CategoriesDirective categories = 
  -           getCategoriesDirective( config.getChild( "categories", false ), name );
  -        return new TargetDirective( name, conf, categories );
  +
  +        if( null != config.getChild( "grant", false ) )
  +        {
  +            //
  +            // this is a target for a container which can include
  +            // a single categories and a single grant statement
  +            //
  +
  +            GrantDirective grants =
  +              createGrantDirective( config.getChild( "grant" ) );
  +            CategoriesDirective categories = 
  +              getCategoriesDirective( config.getChild( "categories", false ), name );
  +            return new TargetDirective( name, categories, grants );
  +        }
  +        else
  +        {
  +            //
  +            // this is potentially a component or containment target
  +            //
  +
  +            final Configuration conf = config.getChild( "configuration", false );
  +              CategoriesDirective categories = 
  +               getCategoriesDirective( config.getChild( "categories", false ), name );
  +            return new TargetDirective( name, conf, categories );
  +        }
       }
  +
  +    private GrantDirective createGrantDirective( Configuration config )
  +       throws ConfigurationException
  +    {
  +        ArrayList result = new ArrayList();
  +        Configuration[] permChildren = config.getChildren( "permission" );
  +        for( int i = 0; i < permChildren.length; i++ )
  +        {
  +            Configuration child = permChildren[i];
  +            PermissionDirective perm = createPermissionDirective( child );
  +            result.add( perm );
  +        }
  +
  +        PermissionDirective[] pd = new PermissionDirective[ result.size() ];
  +        result.toArray( pd );
  +        
  +        Configuration certChild = config.getChild( "certificates" );
  +        CertsDirective certs = createCertsDirective( certChild );
  +        return new GrantDirective( pd, certs );
  +    }
  +    
  +    private CertsDirective createCertsDirective( Configuration conf )
  +       throws ConfigurationException
  +    {
  +        Configuration[] x509conf = conf.getChildren( "x509" );
  +        X509Directive[] x509 = new X509Directive[ x509conf.length ];
  +        for( int i=0 ; i < x509conf.length ; i++ )
  +        {
  +            String href = x509conf[i].getAttribute( "href", "" );
  +            String data = x509conf[i].getValue();
  +            try
  +            {
  +                x509[i] = new X509Directive( href, data );
  +            } catch( CertificateException e )
  +            {
  +                throw new ConfigurationException( "Invalid Certificate in " + x509conf[i], e );
  +            } catch( IOException e )
  +            {
  +                throw new ConfigurationException( "Can't access: " + href, e );
  +            }
  +        }
  +        
  +        Configuration[] pkcs7conf = conf.getChildren( "pkcs7" );
  +        PKCS7Directive[] pkcs7 = new PKCS7Directive[ pkcs7conf.length ];
  +        for( int i=0 ; i < pkcs7conf.length ; i++ )
  +        {
  +            String href = pkcs7conf[i].getAttribute( "href" );
  +            try
  +            {
  +                pkcs7[i] = new PKCS7Directive( href );
  +            } catch( CertificateException e )
  +            {
  +                throw new ConfigurationException( "Invalid Certificate in " + pkcs7conf[i], e );
  +            } catch( IOException e )
  +            {
  +                throw new ConfigurationException( "Can't access: " + href, e );
  +            }
  +        }
  +        return new CertsDirective( x509, pkcs7 );
  +    }
  +    
  +    private PermissionDirective createPermissionDirective( Configuration config )
  +       throws ConfigurationException
  +    {
  +        String classname = config.getAttribute( "class" );
  +        String name = config.getAttribute( "name", null );
  +        String result = "";
  +        Configuration[] actions = config.getChildren( "action" );
  +        for( int i=0 ; i < actions.length ; i ++ )
  +        {
  +            if( i > 0 )
  +                result = result + "," + actions[i].getValue();
  +            else
  +                result = result + actions[i].getValue();
  +        }
  +        try
  +        {
  +            return new PermissionDirective( classname, name, result );
  +        } catch( Exception e )
  +        {
  +            throw new ConfigurationException( "Unable to create the Permission Directive.", e );
  +        }
  +    }
  +
   }
  
  
  
  1.7       +2 -2      avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContext.java
  
  Index: DefaultContext.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultContext.java	22 Feb 2004 16:12:58 -0000	1.6
  +++ DefaultContext.java	25 Feb 2004 22:54:09 -0000	1.7
  @@ -59,7 +59,7 @@
      /**
       * <p>Creation of a new default context.</p>
       *
  -    * @param context the deployment context
  +    * @param map a map of context entry handlers
       */
       public DefaultContext( Map map )
       {
  
  
  
  1.17      +16 -1     avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
  
  Index: DefaultDeploymentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DefaultDeploymentModel.java	12 Feb 2004 05:59:41 -0000	1.16
  +++ DefaultDeploymentModel.java	25 Feb 2004 22:54:09 -0000	1.17
  @@ -30,6 +30,8 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   
  +import org.apache.avalon.logging.data.CategoriesDirective;
  +
   
   /**
    * Abstract model base class.
  @@ -225,4 +227,17 @@
           SystemContext system = m_context.getSystemContext();
           return system.getDefaultDeploymentTimeout();
       }
  +
  +   /**
  +    * Return the logging categories. 
  +    * @return the logging categories
  +    */
  +    public abstract CategoriesDirective getCategories();
  +
  +   /**
  +    * Set categories. 
  +    * @param categories the logging categories
  +    */
  +    public abstract void setCategories( CategoriesDirective categories );
  +
   }
  
  
  
  1.3       +1 -0      avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSecurityModel.java
  
  Index: DefaultSecurityModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSecurityModel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultSecurityModel.java	25 Feb 2004 20:31:01 -0000	1.2
  +++ DefaultSecurityModel.java	25 Feb 2004 22:54:09 -0000	1.3
  @@ -36,6 +36,7 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   
  +import org.apache.avalon.logging.data.CategoriesDirective;
   
   /**
    * <p>Implementation of the default security model.</p>
  
  
  
  1.3       +2 -3      avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/OverrideEntryModel.java
  
  Index: OverrideEntryModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/OverrideEntryModel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OverrideEntryModel.java	22 Feb 2004 16:22:17 -0000	1.2
  +++ OverrideEntryModel.java	25 Feb 2004 22:54:09 -0000	1.3
  @@ -42,8 +42,7 @@
       * Creation of a new overriding context entry.
       *
       * @param descriptor the context entry descriptor
  -    * @param object the value to return for the entry
  -    * @param context the containment context
  +    * @param value the value to return for the entry
       */
       public OverrideEntryModel( 
         EntryDescriptor descriptor, Object value )
  
  
  
  1.2       +2 -2      avalon/merlin/composition/impl/src/test/conf/targets-config.xml
  
  Index: targets-config.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/conf/targets-config.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- targets-config.xml	24 Sep 2003 09:32:20 -0000	1.1
  +++ targets-config.xml	25 Feb 2004 22:54:09 -0000	1.2
  @@ -1,13 +1,13 @@
   
   <targets>
   
  -  <target name="/aaa">
  +  <target path="/aaa">
       <configuration>
         <source>External configuration target for AAA.</source>
       </configuration>
     </target>
   
  -  <target name="/ccc/sss/xxx">
  +  <target path="/ccc/sss/xxx">
       <configuration>
         <source>External configuration target for XXX.</source>
       </configuration>
  
  
  
  1.4       +20 -0     avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java
  
  Index: SimpleDeploymentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleDeploymentModel.java	21 Feb 2004 23:54:42 -0000	1.3
  +++ SimpleDeploymentModel.java	25 Feb 2004 22:54:09 -0000	1.4
  @@ -31,6 +31,8 @@
   
   import org.apache.avalon.framework.logger.Logger;
   
  +import org.apache.avalon.logging.data.CategoriesDirective;
  +
   
   public class SimpleDeploymentModel 
       implements DeploymentModel
  @@ -88,6 +90,24 @@
       {
           return null;
       }
  +
  +   /**
  +    * Return the logging categories. 
  +    * @return the logging categories
  +    */
  +    public CategoriesDirective getCategories()
  +    {
  +        return null;
  +    }
  +
  +   /**
  +    * Set categories. 
  +    * @param categories the logging categories
  +    */
  +    public void setCategories( CategoriesDirective categories ) 
  +    {
  +    }
  +
   
       //-----------------------------------------------------------
       // service production
  
  
  
  1.8       +16 -7     avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/TargetsTestCase.java
  
  Index: TargetsTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/TargetsTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TargetsTestCase.java	21 Feb 2004 23:54:42 -0000	1.7
  +++ TargetsTestCase.java	25 Feb 2004 22:54:09 -0000	1.8
  @@ -33,6 +33,9 @@
   
   import org.apache.excalibur.configuration.ConfigurationUtil;
   
  +import org.apache.avalon.logging.data.CategoriesDirective;
  +
  +
   public class TargetsTestCase extends AbstractTestCase
   {      
      //-------------------------------------------------------
  @@ -63,19 +66,25 @@
                   TargetDirective target = targets[i];
                   final String path = target.getPath();
                   DeploymentModel model = m_model.getModel( path );
  +
  +                CategoriesDirective categories = 
  +                  target.getCategoriesDirective();
  +                if( null != categories )
  +                {
  +                    model.setCategories( categories );
  +                }
  +
                   if( model instanceof ComponentModel )
                   {
                       ComponentModel deployment = (ComponentModel) model;
  -                    deployment.setConfiguration( target.getConfiguration() );
  +                    Configuration config = target.getConfiguration();
  +                    if( null != config )
  +                    { 
  +                        deployment.setConfiguration( config );
  +                    }
                       getLogger().debug( "model: " + deployment );
                       getLogger().debug( 
                         ConfigurationUtil.list( deployment.getConfiguration() ) );
  -                }
  -                else
  -                {
  -                    final String warning = 
  -                      "Cannot apply target: " + path + " to a containment model.";
  -                    getLogger().warn( warning );
                   }
               }
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org