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/24 23:32:46 UTC

cvs commit: avalon/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags TypeTag.java

mcconnell    2004/02/24 14:32:46

  Modified:    meta/api/src/java/org/apache/avalon/meta/info
                        PermissionDescriptor.java
               meta/impl/src/java/org/apache/avalon/meta/info/builder
                        XMLTypeCreator.java
               meta/impl/src/java/org/apache/avalon/meta/info/writer
                        XMLTypeWriter.java
               meta/tools/src/java/org/apache/avalon/meta/info/builder/tags
                        TypeTag.java
  Log:
  Addition of a security permission tag handler.
  
  Revision  Changes    Path
  1.3       +1 -13     avalon/meta/api/src/java/org/apache/avalon/meta/info/PermissionDescriptor.java
  
  Index: PermissionDescriptor.java
  ===================================================================
  RCS file: /home/cvs/avalon/meta/api/src/java/org/apache/avalon/meta/info/PermissionDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PermissionDescriptor.java	24 Feb 2004 21:35:31 -0000	1.2
  +++ PermissionDescriptor.java	24 Feb 2004 22:32:46 -0000	1.3
  @@ -170,18 +170,6 @@
           return hash;
       }
   
  -    private static String[] expandActions( String arg )
  -    {
  -        if( null == arg ) return new String[0];
  -        ArrayList list = new ArrayList();
  -        StringTokenizer tokenizer = new StringTokenizer( arg, "," );
  -        while( tokenizer.hasMoreTokens() )
  -        {
  -            list.add( tokenizer.nextToken() );
  -        }
  -        return (String[]) list.toArray( new String[0] );
  -    }
  -
       public String toString()
       {
           String list = "";
  
  
  
  1.10      +66 -4     avalon/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
  
  Index: XMLTypeCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLTypeCreator.java	10 Feb 2004 16:30:16 -0000	1.9
  +++ XMLTypeCreator.java	24 Feb 2004 22:32:46 -0000	1.10
  @@ -35,6 +35,8 @@
   import org.apache.avalon.meta.info.ReferenceDescriptor;
   import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.StageDescriptor;
  +import org.apache.avalon.meta.info.SecurityDescriptor;
  +import org.apache.avalon.meta.info.PermissionDescriptor;
   import org.apache.avalon.meta.info.Type;
   import org.apache.excalibur.configuration.ConfigurationUtil;
   import org.xml.sax.InputSource;
  @@ -115,10 +117,13 @@
           //
   
           configuration = info.getChild( "info", false );
  -
           final InfoDescriptor descriptor =
               buildInfoDescriptor( classname, configuration );
   
  +        configuration = info.getChild( "security", false );
  +        final SecurityDescriptor security =
  +            buildSecurityDescriptor( configuration );
  +
           configuration = info.getChild( "loggers" );
           final CategoryDescriptor[] loggers = buildLoggers( configuration );
   
  @@ -139,7 +144,7 @@
           final ExtensionDescriptor[] extensions = buildExtensions( configuration );
   
           return new Type(
  -          descriptor, loggers, context, services, dependencies, phases, 
  +          descriptor, security, loggers, context, services, dependencies, phases, 
             extensions, defaults );
       }
   
  @@ -345,7 +350,7 @@
   
       /**
        * A utility method to build a {@link ContextDescriptor}
  -     * object from specified configuraiton.
  +     * object from specified configuration.
        *
        * @param context the dependency configuration
        * @return the created ContextDescriptor
  @@ -435,6 +440,63 @@
             info.getChild( "collection" ).getValue( collectionLegacy );
           return new InfoDescriptor( 
             name, classname, version, lifestyle, collection, schema, attributes );
  +    }
  +
  +    /**
  +     * A utility method to build a {@link SecurityDescriptor}
  +     * object from specified configuration data.
  +     *
  +     * @param config the security configuration fragment
  +     * @return the created SecurityDescriptor
  +     * @throws ConfigurationException if an error occurs
  +     */
  +    public SecurityDescriptor buildSecurityDescriptor( final Configuration config )
  +      throws BuildException
  +    {
  +        if( null == config ) return new SecurityDescriptor( null, null );
  +
  +        try
  +        {
  +            final Properties attributes =
  +              buildAttributes( config.getChild( "attributes" ) );
  +            PermissionDescriptor[] permissions = buildPermissions( config );
  +            return new SecurityDescriptor( permissions, attributes );
  +        }
  +        catch( ConfigurationException e )
  +        {
  +            final String error = 
  +              "Cannot build secrity descriptor.";
  +            throw new BuildException( error, e );
  +        }
  +    }
  +
  +    private PermissionDescriptor[] buildPermissions( final Configuration config )
  +      throws ConfigurationException
  +    {
  +        ArrayList list = new ArrayList();
  +        Configuration[] children = config.getChildren( "permission" );
  +        for( int i = 0; i < children.length; i++ )
  +        {			
  +            list.add( buildPermission( children[i] ) );
  +        }
  +        return (PermissionDescriptor[])list.toArray( new PermissionDescriptor[ 0 ] );
  +    }
  +
  +    private PermissionDescriptor buildPermission( final Configuration config ) 
  +      throws ConfigurationException
  +    {
  +        final String classname = config.getAttribute( "class" );
  +        final String name = config.getAttribute( "name", null );
  +        ArrayList list = new ArrayList();
  +        Configuration[] children = config.getChildren( "action" );
  +        for( int i=0; i<children.length; i++ )
  +        {
  +            Configuration child = children[i];
  +            String action = child.getValue();
  +            list.add( action );
  +        }
  +        String[] actions = (String[])list.toArray( new String[0] );
  +        return new PermissionDescriptor( classname, name, actions );
       }
   
      /**
  
  
  
  1.10      +72 -1     avalon/meta/impl/src/java/org/apache/avalon/meta/info/writer/XMLTypeWriter.java
  
  Index: XMLTypeWriter.java
  ===================================================================
  RCS file: /home/cvs/avalon/meta/impl/src/java/org/apache/avalon/meta/info/writer/XMLTypeWriter.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLTypeWriter.java	21 Feb 2004 13:27:04 -0000	1.9
  +++ XMLTypeWriter.java	24 Feb 2004 22:32:46 -0000	1.10
  @@ -32,6 +32,8 @@
   import org.apache.avalon.meta.info.StageDescriptor;
   import org.apache.avalon.meta.info.ExtensionDescriptor;
   import org.apache.avalon.meta.info.Type;
  +import org.apache.avalon.meta.info.SecurityDescriptor;
  +import org.apache.avalon.meta.info.PermissionDescriptor;
   
   /**
    * Write {@link Type} objects to a stream as xml documents.
  @@ -62,6 +64,7 @@
           writeDoctype( writer, "type" );
           writer.write( "\n\n<type>" );
           writeInfo( writer, type.getInfo() );
  +        writeSecurity( writer, type.getSecurity() );
           writeLoggers( writer, type.getCategories() );
           writeContext( writer, type.getContext() );
           writeServices( writer, type.getServices() );
  @@ -144,6 +147,74 @@
           {
               writeAttributes( writer, info );
               writer.write( "\n  </info>" );
  +        }
  +    }
  +
  +    /**
  +     * Write out xml representation of the security criteria.
  +     *
  +     * @param writer the writer
  +     * @param security the security descriptor
  +     * @throws IOException if unable to write xml
  +     */
  +    private void writeSecurity( final Writer writer,
  +                               final SecurityDescriptor descriptor )
  +        throws IOException
  +    {
  +        PermissionDescriptor[] permissions = descriptor.getPermissions();
  +        if(
  +          ( 0 == descriptor.getAttributeNames().length )
  +          && ( 0 == permissions.length ) )
  +        {
  +            return;
  +        }
  +
  +        writer.write( "\n  <security>" );
  +        for( int i = 0; i < permissions.length; i++ )
  +        {
  +            writePermission( writer, permissions[ i ] );
  +        }
  +
  +        writer.write( "\n  </security>" );
  +    }
  +
  +
  +    /**
  +     * Write out xml representation of a logger.
  +     *
  +     * @param writer the writer
  +     * @param logger the logger
  +     * @throws IOException if unable to write xml
  +     */
  +    private void writePermission( final Writer writer,
  +                              final PermissionDescriptor permission )
  +        throws IOException
  +    {
  +        writer.write( "\n    <permission class=\"" );
  +        writer.write( permission.getClassname() );
  +        writer.write( "\" " );
  +        if( null != permission.getName() )
  +        {
  +            writer.write( " name=\"" );
  +            writer.write( permission.getName() );
  +            writer.write( "\"" );
  +        }
  +        if( 0 == permission.getActions().length )
  +        {
  +            writer.write( "/>" );
  +        }
  +        else
  +        {
  +            writer.write( ">" );
  +            String[] actions = permission.getActions();
  +            for( int i=0; i<actions.length; i++ )
  +            {
  +                String action = actions[i];
  +                writer.write( "\n      <action>" );
  +                writer.write( action );
  +                writer.write( "</action>" );
  +            }
  +            writer.write( "\n    </permission>" );
           }
       }
   
  
  
  
  1.6       +8 -2      avalon/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/TypeTag.java
  
  Index: TypeTag.java
  ===================================================================
  RCS file: /home/cvs/avalon/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/TypeTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TypeTag.java	21 Feb 2004 13:27:04 -0000	1.5
  +++ TypeTag.java	24 Feb 2004 22:32:46 -0000	1.6
  @@ -27,6 +27,8 @@
   import org.apache.avalon.meta.info.CategoryDescriptor;
   import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.StageDescriptor;
  +import org.apache.avalon.meta.info.SecurityDescriptor;
  +import org.apache.avalon.meta.info.PermissionDescriptor;
   import org.apache.avalon.meta.info.Type;
   
   import com.thoughtworks.qdox.model.DocletTag;
  @@ -118,6 +120,8 @@
           final InfoDescriptor info = 
             new InfoDescriptor( 
               name, type, version, lifestyle, collection, schema, properties );
  +        final SecurityDescriptor security = 
  +          new SecurityTag( getJavaClass() ).getSecurityDescriptor();
           final ServiceDescriptor[] services = new ServicesTag( getJavaClass() ).getServices();
           final CategoryDescriptor[] loggers = new LoggerTag( getJavaClass() ).getCategories();
           final DependencyDescriptor[] dependencies =
  @@ -126,7 +130,9 @@
           final ExtensionDescriptor[] extensions = new ExtensionTag( getJavaClass() ).getExtensions();
           final ContextDescriptor context = new ContextTag( getJavaClass() ).getContext();
   
  -        return new Type( info, loggers, context, services, dependencies, stages, extensions, null );
  +        return new Type( 
  +          info, security, loggers, context, services, dependencies, 
  +          stages, extensions, null );
       }
   
       private String getName(DocletTag tag)
  
  
  

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