avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject cvs commit: avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components TestComponent.java TestService.java
Date Tue, 20 Jan 2004 00:10:29 GMT
niclas      2004/01/19 16:10:29

  Modified:    merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl
                        DefaultAppliance.java
               merlin/activation/impl/src/test/conf secure.xml
               merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant
                        CodeSecurityDisabledTestCase.java
                        CodeSecurityEnabledTestCase.java
               merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components
                        TestComponent.java TestService.java
  Log:
  Fixed a bug concerning SecurityException was not properly forwarded to the caller through
the Proxy.
  
  Revision  Changes    Path
  1.21      +42 -24    avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java
  
  Index: DefaultAppliance.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DefaultAppliance.java	19 Jan 2004 21:45:06 -0000	1.20
  +++ DefaultAppliance.java	20 Jan 2004 00:10:29 -0000	1.21
  @@ -58,6 +58,7 @@
   import java.security.AccessControlContext;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
  +import java.security.PrivilegedActionException;
   import java.security.PrivilegedExceptionAction;
   import java.util.Hashtable;
   import java.util.ArrayList;
  @@ -1250,31 +1251,10 @@
               {
                   return secureInvocation( method, m_instance, args );
               }
  -            catch( UndeclaredThrowableException e )
  -            {
  -                Throwable cause = e.getUndeclaredThrowable();
  -                if( cause != null ) throw cause;
  -                final String error = 
  -                  "Delegation error raised by component: " + m_model.getQualifiedName();
  -                throw new ApplianceException( error, e );
  -            }
  -            catch( InvocationTargetException e )
  -            {
  -                Throwable cause = e.getTargetException();
  -                if( cause != null ) 
  -                    throw cause;
  -                final String error = 
  -                  "Delegation error raised by component: " + m_model.getQualifiedName();
  -                throw new ApplianceException( error, e );
  -            }
               catch( Throwable e )
               {
  -                final String error =
  -                  "Service resolution failure for the component: '" 
  -                  + method.getDeclaringClass()
  -                  + "' for operation: '" + method.getName()
  -                  + "' in appliance: " + m_model.getQualifiedName();
  -                throw new ApplianceException( error, e );
  +                e = handleInvocationThrowable( e );
  +                throw e;
               }
           }
   
  @@ -1324,6 +1304,44 @@
                   }, m_accessControlContext );
                   return result;
               }
  +        }
  +        
  +        private Throwable handleInvocationThrowable( Throwable e )
  +        {
  +            final String error = 
  +            "Delegation error raised by component: " + m_model.getQualifiedName();
  +            while( true )
  +            {
  +                if( e instanceof UndeclaredThrowableException )
  +                {
  +                    Throwable cause = 
  +                      ((UndeclaredThrowableException) e).getUndeclaredThrowable();
  +                    if( cause == null )
  +                        return new ApplianceException( error, e );
  +                    e = cause;
  +                }
  +                else if( e instanceof InvocationTargetException )
  +                {
  +                    Throwable cause = 
  +                      ((InvocationTargetException) e).getTargetException();
  +                    if( cause == null )
  +                        return new ApplianceException( error, e );
  +                    e = cause;
  +                }
  +                else if( e instanceof PrivilegedActionException )
  +                {
  +                    Throwable cause = 
  +                      ((PrivilegedActionException) e).getException();
  +                    if( cause == null )
  +                        return new ApplianceException( error, e );
  +                    e = cause;
  +                }
  +                else
  +                {
  +                    break;
  +                }
  +            }
  +            return e;
           }
       }
   
  
  
  
  1.2       +4 -1      avalon/merlin/activation/impl/src/test/conf/secure.xml
  
  Index: secure.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/conf/secure.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- secure.xml	19 Jan 2004 18:12:43 -0000	1.1
  +++ secure.xml	20 Jan 2004 00:10:29 -0000	1.2
  @@ -15,7 +15,10 @@
        </classpath>
   
        <grant>
  -       <permission class="java.util.PropertyPermission" name="org.apache" >
  +       <permission class="java.util.PropertyPermission" name="java.*" >
  +         <action>read</action>
  +       </permission>
  +       <permission class="java.util.PropertyPermission" name="org.apache.*" >
            <action>read</action>
            <action>write</action>
          </permission>
  
  
  
  1.2       +14 -2     avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/CodeSecurityDisabledTestCase.java
  
  Index: CodeSecurityDisabledTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/CodeSecurityDisabledTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CodeSecurityDisabledTestCase.java	19 Jan 2004 21:47:45 -0000	1.1
  +++ CodeSecurityDisabledTestCase.java	20 Jan 2004 00:10:29 -0000	1.2
  @@ -102,7 +102,7 @@
   
           try
           {
  -            test.doPrimary(); // test something in component
  +            test.createDirectory(); 
           }
           catch( Throwable e )
           {
  @@ -114,7 +114,19 @@
   
           try
           {
  -            test.doSecondary(); // test something in component
  +            test.deleteDirectory(); 
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "CodeSecurityTest secondary failure.";
  +            final String message = ExceptionHelper.packException( error, e, true );
  +            getLogger().error( message );
  +            throw new Exception( message );
  +        }
  +
  +        try
  +        {
  +            String ver = test.getJavaVersion();
           }
           catch( Throwable e )
           {
  
  
  
  1.2       +32 -4     avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/CodeSecurityEnabledTestCase.java
  
  Index: CodeSecurityEnabledTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/CodeSecurityEnabledTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CodeSecurityEnabledTestCase.java	19 Jan 2004 21:47:45 -0000	1.1
  +++ CodeSecurityEnabledTestCase.java	20 Jan 2004 00:10:29 -0000	1.2
  @@ -101,22 +101,50 @@
           TestService test = setupTestService();
           try
           {
  -            test.doPrimary(); // test something in component
  +            test.createDirectory(); 
               fail( "CodeSecurityTest primary failure: This operation should not be allowed."
);
           }
  -        catch( Exception e )
  +        catch( SecurityException e )
           {
               // ignore, expected
           }
  +        catch( Throwable e )
  +        {
  +            final String error = "CodeSecurityTest primary failure.";
  +            final String message = ExceptionHelper.packException( error, e, true );
  +            getLogger().error( message );
  +            throw new Exception( message );
  +        }
   
           try
           {
  -            test.doSecondary(); // test something in component
  +            test.deleteDirectory(); 
               fail( "CodeSecurityTest secondary failure: This operation should not be allowed."
);
           }
  -        catch( Exception e )
  +        catch( SecurityException e )
           {
               // ignore, expected
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "CodeSecurityTest primary failure.";
  +            final String message = ExceptionHelper.packException( error, e, true );
  +            getLogger().error( message );
  +            throw new Exception( message );
  +        }
  +        
  +        try
  +        {
  +            // This should succeed since there is a read permission for
  +            // system properties in the security policy.
  +            String ver = test.getJavaVersion();
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "CodeSecurityTest secondary failure.";
  +            final String message = ExceptionHelper.packException( error, e, true );
  +            getLogger().error( message );
  +            throw new Exception( message );
           }
       }
   
  
  
  
  1.2       +7 -2      avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestComponent.java
  
  Index: TestComponent.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestComponent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestComponent.java	19 Jan 2004 18:12:43 -0000	1.1
  +++ TestComponent.java	20 Jan 2004 00:10:29 -0000	1.2
  @@ -98,7 +98,7 @@
       /**
        * Does something trivial.
        */
  -    public void doPrimary()
  +    public void createDirectory()
       {
           m_home.mkdirs();
       }
  @@ -106,8 +106,13 @@
       /**
        * Does something trivial.
        */
  -    public void doSecondary()
  +    public void deleteDirectory()
       {
           m_home.delete();
  +    }
  +    
  +    public String getJavaVersion()
  +    {
  +        return System.getProperty( "java.version" );
       }
   }
  
  
  
  1.2       +9 -4      avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestService.java
  
  Index: TestService.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestService.java	19 Jan 2004 18:12:43 -0000	1.1
  +++ TestService.java	20 Jan 2004 00:10:29 -0000	1.2
  @@ -72,12 +72,17 @@
   public interface TestService
   {
       /**
  -     * Does something trivial.
  +     * Create a test directory
        */
  -    public void doPrimary();
  +    void createDirectory();
   
       /**
  -     * Does something trivial.
  +     * Delete a test directory
        */
  -    public void doSecondary();
  +    void deleteDirectory();
  +    
  +    /** 
  +    * Returns the version of the Java Virtual Machine.
  +    **/
  +    String getJavaVersion();
   }
  
  
  

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


Mime
View raw message