avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/policy/runtime AbstractPolicy.java
Date Sun, 15 Sep 2002 13:24:40 GMT
donaldp     2002/09/15 06:24:40

  Modified:    loader/src/java/org/apache/excalibur/policy/runtime
                        AbstractPolicy.java
  Log:
  Added createPermission method to make it easier to create permissions
  
  Revision  Changes    Path
  1.3       +63 -0     jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/policy/runtime/AbstractPolicy.java
  
  Index: AbstractPolicy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/policy/runtime/AbstractPolicy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractPolicy.java	15 Sep 2002 13:18:40 -0000	1.2
  +++ AbstractPolicy.java	15 Sep 2002 13:24:40 -0000	1.3
  @@ -8,6 +8,7 @@
   package org.apache.excalibur.policy.runtime;
   
   import java.io.File;
  +import java.lang.reflect.Constructor;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.security.CodeSource;
  @@ -15,6 +16,7 @@
   import java.security.PermissionCollection;
   import java.security.Permissions;
   import java.security.Policy;
  +import java.security.UnresolvedPermission;
   import java.security.cert.Certificate;
   import java.util.ArrayList;
   import java.util.Enumeration;
  @@ -193,8 +195,69 @@
           return false;
       }
   
  +    /**
  +     * Create a permission of specified class and
  +     * with specified target, action and signers.
  +     *
  +     * @param type the classname of Permission object
  +     * @param target the target of permission
  +     * @param actions the actions allowed on permission (if any)
  +     * @param signers the signers (if any)
  +     * @return the created Permission object
  +     * @throws Exception if unable to create permission
  +     */
  +    protected final Permission createPermission( final String type,
  +                                                 final String target,
  +                                                 final String actions,
  +                                                 final Certificate[] signers )
  +        throws Exception
  +    {
  +        if( null != signers )
  +        {
  +            return new UnresolvedPermission( type, target, actions, signers );
  +        }
  +
  +        try
  +        {
  +            final Class clazz = Class.forName( type );
  +
  +            Class paramClasses[] = null;
  +            Object params[] = null;
  +
  +            if( null == actions && null == target )
  +            {
  +                paramClasses = new Class[ 0 ];
  +                params = new Object[ 0 ];
  +            }
  +            else if( null == actions )
  +            {
  +                paramClasses = new Class[ 1 ];
  +                paramClasses[ 0 ] = String.class;
  +                params = new Object[ 1 ];
  +                params[ 0 ] = target;
  +            }
  +            else
  +            {
  +                paramClasses = new Class[ 2 ];
  +                paramClasses[ 0 ] = String.class;
  +                paramClasses[ 1 ] = String.class;
  +                params = new Object[ 2 ];
  +                params[ 0 ] = target;
  +                params[ 1 ] = actions;
  +            }
  +
  +            final Constructor constructor = clazz.getConstructor( paramClasses );
  +            return (Permission)constructor.newInstance( params );
  +        }
  +        catch( final ClassNotFoundException cnfe )
  +        {
  +            return new UnresolvedPermission( type, target, actions, signers );
  +        }
  +    }
   
       /**
  +     * Note: This is copied from FileUtil.normalize();
  +     *
        * Normalize a path. That means:
        * <ul>
        *   <li>changes to unix style if under windows</li>
  
  
  

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


Mime
View raw message