You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2012/02/15 20:22:59 UTC

svn commit: r1244666 - in /db/derby/code/trunk: ./ java/engine/org/apache/derby/impl/store/raw/data/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ java/testing/org/apache/derbyTesting/functionTests/util/ java/testing/org/apache/derbyTe...

Author: rhillegas
Date: Wed Feb 15 19:22:58 2012
New Revision: 1244666

URL: http://svn.apache.org/viewvc?rev=1244666&view=rev
Log:
DERBY-866: Add tests for NATIVE/LOCAL authentication in databases accessed via the jar and classpath subprotocols.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast1.jar   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java   (with props)
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NativeAuthenticationServiceTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Wed Feb 15 19:22:58 2012
@@ -651,6 +651,12 @@
     <ant dir="${derby.testing.src.dir}"/>
   </target>
 	
+  <target name="build-test-jars" description="Build jar files used in tests." depends="buildsource" >
+
+    <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/lang" target="build-test-jars" />
+
+  </target>
+
   <!-- Build the package private tests -->
   <target name="pptesting" depends="testing">
     <ant dir="${derby.testing.src.dir}/org/apache/derby"/>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java Wed Feb 15 19:22:58 2012
@@ -540,7 +540,7 @@ public class BaseDataFileFactory
 
 		releaseJBMSLockOnDB();
         
-        writableStorageFactory.shutdown();
+        if ( writableStorageFactory != null ) { writableStorageFactory.shutdown(); }
 	} // end of stop
 
 	/*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NativeAuthenticationServiceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NativeAuthenticationServiceTest.java?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NativeAuthenticationServiceTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NativeAuthenticationServiceTest.java Wed Feb 15 19:22:58 2012
@@ -31,11 +31,14 @@ import javax.sql.DataSource;
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.ClasspathSetup;
 import org.apache.derbyTesting.junit.DatabaseChangeSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
-import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
  * <p>
@@ -56,6 +59,7 @@ public class NativeAuthenticationService
     private static  final   String  PEAR_USER = "PEAR";   
     private static  final   String  ORANGE_USER = "ORANGE";   
     private static  final   String  BANANA_USER = "BANANA";   
+    private static  final   String  GRAPE_USER = "GRAPE";   
 
     private static  final   String  WALNUT_USER = "WALNUT";
 
@@ -69,6 +73,20 @@ public class NativeAuthenticationService
     private static  final   String  SIXTH_DB = "sixthDB";
     private static  final   String  SEVENTH_DB = "seventhDB";
     private static  final   String  EIGHTH_DB = "eighthDB";
+    private static  final   String  NINTH_DB = "ninthDB";
+
+    private static  final   String  NAST1_JAR_FILE = "nast1.jar";
+    private static  final   String  NAST2_JAR_FILE = "nast2.jar";
+    private static  final   String[]    SUPPORT_FILES_SOURCE =
+    {
+        "functionTests/tests/lang/" + NAST1_JAR_FILE,
+        "functionTests/tests/lang/" + NAST1_JAR_FILE,
+    };
+    private static  final   String[]    SUPPORT_FILES_TARGET =
+    {
+        NAST1_JAR_FILE,
+        NAST2_JAR_FILE,
+    };
 
     private static  final   String  PROVIDER_PROPERTY = "derby.authentication.provider";
     private static  final   String  REQUIRE_AUTHENTICATION_PROPERTY = "derby.connection.requireAuthentication";
@@ -93,6 +111,7 @@ public class NativeAuthenticationService
     private final   boolean _nativeAuthentication;
     private final   boolean _localAuthentication;
     private final   boolean _turnOffAuthenticationAndAuthorization;
+    private final   boolean _disableSecurityManager;
 
     private String  _credentialsDBPhysicalName;
 
@@ -101,6 +120,7 @@ public class NativeAuthenticationService
     private DatabaseChangeSetup _sixthDBSetup;
     private DatabaseChangeSetup _seventhDBSetup;
     private DatabaseChangeSetup _eighthDBSetup;
+    private DatabaseChangeSetup _ninthDBSetup;
 
     private String  _derbySystemHome;
     private String  _fullBackupDir;
@@ -115,7 +135,8 @@ public class NativeAuthenticationService
         (
          boolean    nativeAuthentication,
          boolean    localAuthentication,
-         boolean    turnOffAuthenticationAndAuthorization
+         boolean    turnOffAuthenticationAndAuthorization,
+         boolean    disableSecurityManager
          )
     {
         super( "testAll" );
@@ -123,6 +144,7 @@ public class NativeAuthenticationService
         _nativeAuthentication = nativeAuthentication;
         _localAuthentication = localAuthentication;
         _turnOffAuthenticationAndAuthorization = turnOffAuthenticationAndAuthorization;
+        _disableSecurityManager = disableSecurityManager;
     }
 
     ///////////////////////////////////////////////////////////////////////////////////
@@ -192,11 +214,14 @@ public class NativeAuthenticationService
         String  authOverrides = _turnOffAuthenticationAndAuthorization ?
             "Authentication/Authorization turned OFF, " :
             "Authentication/Authorization DEFAULT, ";
+        String  securityManager = _disableSecurityManager ?
+            "SecurityManager OFF, " :
+            "SecurityManager ON, ";
         String  embedded = isEmbedded() ?
             "Embedded" :
             "Client/Server";
 
-        return "[ " + authType + local + authOverrides + embedded + " ]";
+        return "[ " + authType + local + authOverrides + securityManager + embedded + " ]";
     }
 
     /** Return true if the test is running embedded */
@@ -216,11 +241,22 @@ public class NativeAuthenticationService
     {
         TestSuite suite = new TestSuite();
 
+        //
+        // Special version of the test which disables the security manager in order
+        // to use the classpath subprotocol. We may be able to remove this special
+        // case after DERBY-5615 is fixed.
+        //
+        suite.addTest( (new NativeAuthenticationServiceTest( false, false, false, true ) ).decorate( false ) );
+        
         suite.addTest( allConfigurations( false ) );
         if ( !JDBC.vmSupportsJSR169() ) { suite.addTest( allConfigurations( true ) ); }
 
         return suite;
     }
+    private boolean onWindows()
+    {
+        return getSystemProperty("os.name").startsWith("Windows");
+    }
 
     /**
      * <p>
@@ -231,11 +267,11 @@ public class NativeAuthenticationService
     {
         TestSuite suite = new TestSuite();
 
-        suite.addTest( (new NativeAuthenticationServiceTest( false, false, false ) ).decorate( clientServer ) );
-        suite.addTest( ( new NativeAuthenticationServiceTest( true, true, true ) ).decorate( clientServer ) );
-        suite.addTest( ( new NativeAuthenticationServiceTest( true, true, false ) ).decorate( clientServer ) );
-        suite.addTest( ( new NativeAuthenticationServiceTest( true, false, true ) ).decorate( clientServer ) );
-        suite.addTest( ( new NativeAuthenticationServiceTest( true, false, false ) ).decorate( clientServer ) );
+        suite.addTest( (new NativeAuthenticationServiceTest( false, false, false, false ) ).decorate( clientServer ) );
+        suite.addTest( ( new NativeAuthenticationServiceTest( true, true, true, false ) ).decorate( clientServer ) );
+        suite.addTest( ( new NativeAuthenticationServiceTest( true, true, false, false ) ).decorate( clientServer ) );
+        suite.addTest( ( new NativeAuthenticationServiceTest( true, false, true, false ) ).decorate( clientServer ) );
+        suite.addTest( ( new NativeAuthenticationServiceTest( true, false, false, false ) ).decorate( clientServer ) );
 
         return suite;
     }
@@ -253,6 +289,8 @@ public class NativeAuthenticationService
         
         Test        result = this;
 
+        if ( _disableSecurityManager ) { result = SecurityManagerSetup.noSecurityManager( result ); }
+
         //
         // Putting the clientServer decorator on the inside allows the server-side
         // embedded driver to be re-registered after engine shutdown. If you put
@@ -281,6 +319,27 @@ public class NativeAuthenticationService
         //    };
         
         //
+        // For testing subprotocols. Cleanup of support files is blocked by DERBY-5618.
+        //
+        if ( !onWindows() )
+        {
+            // Add the jar files needed for testing jar and classpath subprotocols.
+            result = new SupportFilesSetup( result, SUPPORT_FILES_SOURCE, null, SUPPORT_FILES_TARGET, null );
+
+            //
+            // Add a jar file to the classpath so that we can test the classpath subprotocol.
+            //
+            File        currentDirectory = currentDirectory();
+            File        readOnlyDirectory = new File( currentDirectory, SupportFilesSetup.EXTIN );
+            File        nast2Jar = new File( readOnlyDirectory, NAST2_JAR_FILE );
+
+            try {
+                result = new ClasspathSetup( result, nast2Jar.toURL() );
+            }
+            catch (Exception e) { printStackTrace( e ); }
+        }
+        
+        //
         // Register temporary databases, where the test will do its work.
         // We can't use the default, re-usable database because NATIVE authentication stores
         // persistent properties which cannot be turned off.
@@ -294,6 +353,7 @@ public class NativeAuthenticationService
         result = _sixthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown( result, SIXTH_DB, true );
         result = _seventhDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown( result, SEVENTH_DB, true );
         result = _eighthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown( result, EIGHTH_DB, true );
+        result = _ninthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown( result, NINTH_DB, true );
 
         result = TestConfiguration.changeUserDecorator( result, DBO, getPassword( DBO ) );
         
@@ -338,10 +398,10 @@ public class NativeAuthenticationService
     {
         // can't create any database until the credentials db has been created
         Connection  secondDBConn = getConnection
-            ( _nativeAuthentication, SECOND_DB, APPLE_USER, CREDENTIALS_DB_DOES_NOT_EXIST );
+            ( _nativeAuthentication, true, SECOND_DB, APPLE_USER, CREDENTIALS_DB_DOES_NOT_EXIST );
 
         // create the credentials database
-        Connection  sysadminConn = openConnection( CREDENTIALS_DB, DBO );
+        Connection  sysadminConn = openConnection( CREDENTIALS_DB, DBO, true );
 
         // add another legal user
         addUser( sysadminConn, APPLE_USER );
@@ -395,12 +455,12 @@ public class NativeAuthenticationService
 
         // Databases can't be created by users who don't have credentials stored in the credentials database
         Connection  thirdDBConn = getConnection
-            ( _nativeAuthentication, THIRD_DB, WALNUT_USER, INVALID_AUTHENTICATION );
+            ( _nativeAuthentication, true, THIRD_DB, WALNUT_USER, INVALID_AUTHENTICATION );
 
         // Now let the other valid user create a database
         if ( secondDBConn == null )
         {
-            secondDBConn = getConnection( false, SECOND_DB, APPLE_USER, null );
+            secondDBConn = getConnection( false, true, SECOND_DB, APPLE_USER, null );
         }
 
         // verify that the other valid user is the dbo in the database he just created
@@ -452,7 +512,7 @@ public class NativeAuthenticationService
         //
         ///////////////////////////////////////////////////////////////////////////////////
 
-        Connection  seventhDBOConn = openConnection( SEVENTH_DB, DBO );
+        Connection  seventhDBOConn = openConnection( SEVENTH_DB, DBO, true );
 
         addUser( seventhDBOConn, APPLE_USER );
         goodStatement( seventhDBOConn, "create table t1( a int )" );
@@ -472,12 +532,12 @@ public class NativeAuthenticationService
         _seventhDBSetup.getTestConfiguration().shutdownDatabase();
 
         // if NATIVE authentication is set in the database, then sql authorization prevents this legal user from viewing private data
-        Connection  seventhAppleConn = openConnection( SEVENTH_DB, APPLE_USER );
+        Connection  seventhAppleConn = openConnection( SEVENTH_DB, APPLE_USER, true );
         vetStatement( _localAuthentication, seventhAppleConn, "select * from " + DBO + ".t1", NO_COLUMN_PERMISSION );
 
         // if NATIVE authentication is set in the database, then authentication still prevents this user from logging in
         Connection  seventhWalnutConn = getConnection
-            ( _localAuthentication, SEVENTH_DB, WALNUT_USER, INVALID_AUTHENTICATION );
+            ( _localAuthentication, true, SEVENTH_DB, WALNUT_USER, INVALID_AUTHENTICATION );
         
         ///////////////////////////////////////////////////////////////////////////////////
         //
@@ -487,7 +547,7 @@ public class NativeAuthenticationService
         //
         ///////////////////////////////////////////////////////////////////////////////////
 
-        Connection  eighthDBOConn = openConnection( EIGHTH_DB, DBO );
+        Connection  eighthDBOConn = openConnection( EIGHTH_DB, DBO, true );
 
         addUser( eighthDBOConn, APPLE_USER );
 
@@ -504,12 +564,37 @@ public class NativeAuthenticationService
 
         // succeeds unless LOCAL authentication overrides database-specified BUILTIN authentication
         Connection  builtinConn = getConnection
-            ( _localAuthentication, EIGHTH_DB, BUILTIN_USER, INVALID_AUTHENTICATION );
+            ( _localAuthentication, true, EIGHTH_DB, BUILTIN_USER, INVALID_AUTHENTICATION );
 
         // fails if we are using BUILTIN authentication because this user wasn't given BUILTIN credentials
         Connection  eightAppleConn = getConnection
-            ( !_localAuthentication, EIGHTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
+            ( !_localAuthentication, true, EIGHTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
+        
+        ///////////////////////////////////////////////////////////////////////////////////
+        //
+        // Vet databases accessed via subprotocols. Not run on Windows machines
+        // because of DERBY-5618.
+        //
+        ///////////////////////////////////////////////////////////////////////////////////
+
+        if ( !onWindows() )
+        {
+            // database accessed via jar subprotocol
+            vetProtocol( jarDBName() );
+        
+            //
+            // We only use the classpath subprotocol if we are not running under a security manager.
+            // We may be able to remove that restriction after DERBY-5615 is fixed.
+            //
+            if ( _disableSecurityManager ) { vetProtocol( classpathDBName() ); }
+        }
+    }
+    private String  jarDBName() throws Exception
+    {
+        return "jar:(" + SupportFilesSetup.getReadOnlyFileName( NAST1_JAR_FILE  ) + ")nast";
     }
+    private String  classpathDBName()   { return "classpath:nast"; }
+    
     private void    addBuiltinUser( Connection conn, String user )  throws Exception
     {
         String  key = "derby.user." + user;
@@ -520,6 +605,28 @@ public class NativeAuthenticationService
 
     /**
      * <p>
+     * Verify that databases in jar files and on the classpath can be opened
+     * and respect NATIVE/LOCAL settings.
+     * </p>
+     */
+    private void    vetProtocol( String protocolDBName ) throws Exception
+    {
+        ///////////////////////////////////////////////////////////////////////////////////
+        //
+        // Verify that regardless of any other settings, NATIVE authentication is on in the
+        // database stored in a jar file or accessed over the classpath
+        //
+        ///////////////////////////////////////////////////////////////////////////////////
+
+        Connection  grapeConn = getConnection( false, false, protocolDBName, GRAPE_USER, null );
+
+        vetStatement( true, grapeConn, "select * from " + DBO + ".t", NO_COLUMN_PERMISSION );
+        
+        getConnection( true, false, protocolDBName, WALNUT_USER, INVALID_AUTHENTICATION );
+    }
+
+    /**
+     * <p>
      * The vetCoreBehavior() method verifies credentials-checking for the
      * following system-wide operations:
      * </p>
@@ -543,7 +650,7 @@ public class NativeAuthenticationService
     private void    vetSystemWideOperations()   throws Exception
     {
         // create a database which we will backup and restore
-        Connection  dboConn = openConnection( SIXTH_DB, DBO );
+        Connection  dboConn = openConnection( SIXTH_DB, DBO, true );
 
         // add another user who can perform restores successfully
         addUser( dboConn, BANANA_USER );
@@ -633,7 +740,7 @@ public class NativeAuthenticationService
     {
         // create an empty database without authentication turned on
         String          dbo = ORANGE_USER;
-        Connection  dboConn = openConnection( FOURTH_DB, dbo );
+        Connection  dboConn = openConnection( FOURTH_DB, dbo, true );
 
         addUser( dboConn, PEAR_USER );
 
@@ -715,10 +822,10 @@ public class NativeAuthenticationService
         _fourthDBSetup.getTestConfiguration().shutdownDatabase();
         
         // can't connect to the database with credentials which aren't stored in it.
-        Connection  appleConn = getConnection( true, FOURTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
+        Connection  appleConn = getConnection( true, true, FOURTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
 
         // ...but these credentials work
-        Connection  pearConn = openConnection( FOURTH_DB, PEAR_USER );
+        Connection  pearConn = openConnection( FOURTH_DB, PEAR_USER, true );
 
         // should get authorization errors trying to select from a table private to the DBO
         // and from trying to view the credentials table
@@ -735,7 +842,7 @@ public class NativeAuthenticationService
     private void    vetPasswordLifetime()   throws Exception
     {
         // create another database
-        Connection  dboConn = openConnection( FIFTH_DB, DBO );
+        Connection  dboConn = openConnection( FIFTH_DB, DBO, true );
 
         // add another legal user
         addUser( dboConn, APPLE_USER );
@@ -761,10 +868,10 @@ public class NativeAuthenticationService
         _fifthDBSetup.getTestConfiguration().shutdownDatabase();
 
         // the DBO's password does not expire
-        dboConn = openConnection( FIFTH_DB, DBO );
+        dboConn = openConnection( FIFTH_DB, DBO, true );
 
         // but the other user's password has expired
-        appleConn = getConnection( true, FIFTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
+        appleConn = getConnection( true, true, FIFTH_DB, APPLE_USER, INVALID_AUTHENTICATION );
         
         // setup so that passwords don't expire after we reboot the database.
         // shutdown the database so that the new property settings take effect.
@@ -791,7 +898,7 @@ public class NativeAuthenticationService
 
     private void    vetSQLAuthorizationOn() throws Exception
     {
-        Connection  nonDBOConn = openConnection( CREDENTIALS_DB, APPLE_USER );
+        Connection  nonDBOConn = openConnection( CREDENTIALS_DB, APPLE_USER, true );
         String          query = "select username from sys.sysusers" ;
 
         try {
@@ -812,22 +919,27 @@ public class NativeAuthenticationService
         }
     }
     
-    private Connection  getConnection( boolean shouldFail, String dbName, String user, String expectedSQLState )
+    private Connection  getConnection
+        ( boolean shouldFail, boolean isLogicalName, String dbName, String user, String expectedSQLState )
         throws Exception
     {
         Connection  conn = null;
 
-        reportConnectionAttempt( dbName, user );
+        reportConnectionAttempt( dbName, user, isLogicalName );
 
         try {
-            conn = openConnection( dbName, user );
+            conn = openConnection( dbName, user, isLogicalName );
 
             if ( shouldFail )   { fail( tagError( "Connection to " + dbName + " should have failed." ) ); }
         }
-        catch (SQLException se)
+        catch (Throwable t)
         {
-            if ( shouldFail )   { assertSQLState( expectedSQLState, se ); }
-            else    { fail( tagError( "Connection to " + dbName + " unexpectedly failed." ) );}
+            if ( shouldFail && (t instanceof SQLException) )   { assertSQLState( expectedSQLState, (SQLException) t ); }
+            else
+            {
+                printStackTrace( t );
+                fail( tagError( "Connection to " + dbName + " unexpectedly failed." ) );
+            }
         }
 
         return conn;
@@ -839,9 +951,9 @@ public class NativeAuthenticationService
     {
         Connection  conn = null;
 
-        reportConnectionAttempt( dbName, user );
+        reportConnectionAttempt( dbName, user, true );
 
-        conn = openConnection( dbName, user );
+        conn = openConnection( dbName, user, true );
 
         SQLWarning  warning = conn.getWarnings();
 
@@ -858,11 +970,11 @@ public class NativeAuthenticationService
 
         return conn;
     }
-    private void    reportConnectionAttempt( String dbName, String user )
+    private void    reportConnectionAttempt( String dbName, String user, boolean isLogicalName )
     {
-        println
-            ( user + " attempting to get connection to database " + dbName +
-              " aka " + getTestConfiguration().getPhysicalDatabaseName( dbName ) );
+        String  message = user + " attempting to get connection to database " + dbName;
+        if ( isLogicalName ) { message = message + " aka " + getTestConfiguration().getPhysicalDatabaseName( dbName ) ; }
+        println( message );
     }
 
     private void    addUser( Connection conn, String user ) throws Exception
@@ -914,10 +1026,18 @@ public class NativeAuthenticationService
     ///////////////////////////////////////////////////////////////////////////////////
 
     /** Open a connection to a database using the supplied credentials */
-    private Connection  openConnection( String logicalDBName, String user )
+    private Connection  openConnection( String dbName, String user, boolean isLogicalName )
         throws SQLException
     {
-        return getTestConfiguration().openConnection( logicalDBName, user, getPassword( user ) );
+        String  password = getPassword( user );
+        if ( isLogicalName )
+        {
+            return getTestConfiguration().openConnection( dbName, user, password );
+        }
+        else
+        {
+            return getTestConfiguration().openPhysicalConnection( dbName, user, password );
+        }
     }
     
     /** Get the password for a user */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml Wed Feb 15 19:22:58 2012
@@ -176,6 +176,36 @@
   </target> 
 
 
+  <target name="build-test-jars" description="Build jar files used in tests." depends="init" >
+
+    <property name="lang-test-dir" value="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/lang"/>
+
+    <delete dir="${lang-test-dir}/nast"/>
+    <mkdir dir="${lang-test-dir}/nast"/>
+
+    <echo level="info" message="Running script to create the nast database"/>
+    <java classname="org.apache.derby.tools.ij"
+          output="${lang-test-dir}/nast.out"
+          failonerror="true"
+          dir="${lang-test-dir}" fork="true">
+      <classpath>
+        <pathelement path="${out.dir}"/>
+        <pathelement path="${compile.classpath}"/>
+      </classpath>
+      <arg value="${lang-test-dir}/nast_init.sql"/>
+    </java>
+
+    <echo level="info" message="Putting the nast database into a jar file"/>
+    <jar destfile="${lang-test-dir}/nast1.jar"
+         basedir="${lang-test-dir}/nast" />
+
+    <!--  Comment out these lines if you have trouble generating the jar file  -->
+    <delete dir="${lang-test-dir}/nast"/>
+    <delete file="${lang-test-dir}/nast.out"/>
+    <delete file="${lang-test-dir}/derby.log"/>
+
+  </target>
+
 <!--             ============= End Targets ==============                -->
 
 <!--             ============= End Project ==============                -->

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast1.jar
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast1.jar?rev=1244666&view=auto
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql?rev=1244666&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql Wed Feb 15 19:22:58 2012
@@ -0,0 +1,34 @@
+--
+--   Licensed to the Apache Software Foundation (ASF) under one or more
+--   contributor license agreements.  See the NOTICE file distributed with
+--   this work for additional information regarding copyright ownership.
+--   The ASF licenses this file to You under the Apache License, Version 2.0
+--   (the "License"); you may not use this file except in compliance with
+--   the License.  You may obtain a copy of the License at
+--
+--      http://www.apache.org/licenses/LICENSE-2.0
+--
+--   Unless required by applicable law or agreed to in writing, software
+--   distributed under the License is distributed on an "AS IS" BASIS,
+--   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+--   See the License for the specific language governing permissions and
+--   limitations under the License.
+--
+-- This script creates a database with NATIVE credentials. The build-test-jars target in the nearby
+-- build.xml file creates this database, then puts the database in nast1.jar and nast2.jar for
+-- use by NativeAuthenticationServiceTest. The build-test-jars target is invoked by
+-- a target by the same name in the top build.xml file.
+--
+
+connect 'jdbc:derby:nast/nast;create=true;user=kiwi;password=kiwipassword';
+
+call syscs_util.syscs_create_user( 'KIWI', 'KIWI_password' );
+call syscs_util.syscs_create_user( 'GRAPE', 'GRAPE_password' );
+call syscs_util.syscs_set_database_property( 'derby.authentication.provider', 'NATIVE::LOCAL' );
+
+create table t( a int );
+insert into t( a ) values ( 100 ), ( 200 );
+
+connect 'jdbc:derby:;shutdown=true';
+
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nast_init.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy Wed Feb 15 19:22:58 2012
@@ -88,6 +88,9 @@ grant codeBase "${derbyTesting.codejar}d
   permission java.io.FilePermission "${user.dir}${/}extinout${/}-", "read,  write, delete";
   permission java.io.FilePermission "${user.dir}${/}extout${/}-", "read,write";
   permission java.io.FilePermission "${user.dir}${/}extinout", "read,write";
+
+  // needed to create a temp file in order to open a database in a jar file
+  permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete";
   
   // These permissions are needed to load the JCE for encryption with Sun and IBM JDK131.
   // JDK14 has the JCE  preloaded
@@ -245,6 +248,10 @@ grant codeBase "${derbyTesting.testjar}d
   permission java.security.SecurityPermission "getPolicy";
   permission java.lang.RuntimePermission "setIO";  
 
+  // Needed by ClasspathSetup to change the classloader
+  permission java.lang.RuntimePermission "createClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+
   // These permissions are needed to dump the thread stack
   // traces upon failure.
   permission java.lang.RuntimePermission "getStackTrace";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Wed Feb 15 19:22:58 2012
@@ -1,6 +1,6 @@
 /*
  *
- * Derby - Class BaseTestCase
+ * Derby - Class org.apache.derbyTesting.junit.BaseTestCase
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -602,6 +602,16 @@ public abstract class BaseTestCase
     }
 
     /**
+     * <p>
+     * Return the current directory.
+     * </p>
+     */
+    public  static  File    currentDirectory()
+    {
+        return new File( getSystemProperty( "user.dir" ) );
+    }
+
+    /**
      * @return true if this is a j9 VM
      */
     public static final boolean isJ9Platform() {

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java?rev=1244666&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java Wed Feb 15 19:22:58 2012
@@ -0,0 +1,116 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.ClasspathSetup
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, 
+ * software distributed under the License is distributed on an 
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
+ * either express or implied. See the License for the specific 
+ * language governing permissions and limitations under the License.
+ */
+package org.apache.derbyTesting.junit;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Assert;
+import junit.framework.Test;
+
+/**
+ * <p>
+ * This decorator adds another resource to the classpath, removing
+ * it at tearDown().
+ * </p>
+ */
+public class ClasspathSetup extends TestSetup
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private URL             _resource;
+    private ClassLoader _originalClassLoader;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTORS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Add the indicated URL to the classpath.
+     * </p>
+     */
+    public  ClasspathSetup( Test test, URL resource )  throws Exception
+    {
+        super( test );
+        
+        _resource = resource;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    protected void setUp() throws PrivilegedActionException
+    {
+        AccessController.doPrivileged
+            (
+             new java.security.PrivilegedExceptionAction()
+             {
+                 public Object run() throws PrivilegedActionException
+                 { 
+                     _originalClassLoader = Thread.currentThread().getContextClassLoader();
+
+                     URLClassLoader newClassLoader = new URLClassLoader( new URL[] { _resource }, _originalClassLoader );
+
+                     Thread.currentThread().setContextClassLoader( newClassLoader );
+                     
+                     return null;
+                 }
+             }
+             );
+    }
+    
+    protected void tearDown() throws PrivilegedActionException
+    {
+        AccessController.doPrivileged
+            (
+             new java.security.PrivilegedExceptionAction()
+             {
+                 public Object run() throws PrivilegedActionException
+                 { 
+                     Thread.currentThread().setContextClassLoader( _originalClassLoader );
+                     
+                     return null;
+                 }
+             }
+             );
+    }
+
+}
+
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClasspathSetup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java Wed Feb 15 19:22:58 2012
@@ -228,6 +228,28 @@ public class SupportFilesSetup extends T
     {
         return getFile(EXTIN, name);
     }
+    
+    /**
+     * Get the full name of the file.
+     * @param name Base name for the resouce.
+     */
+    public static String getReadOnlyFileName(String name)
+        throws Exception
+    {
+        final   String  finalName = name;
+        try {
+            return (String) AccessController.doPrivileged
+            (new java.security.PrivilegedExceptionAction(){
+
+                public Object run() throws MalformedURLException{
+                    return getReadOnly(  finalName ).getAbsolutePath();
+                }
+            }
+             );
+        } catch (PrivilegedActionException e) {
+            throw e.getException();
+        } 
+    }
     /**
      * Obtain a File for the local copy of a read-write resource.
      * @param name Base name for the resouce.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1244666&r1=1244665&r2=1244666&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Wed Feb 15 19:22:58 2012
@@ -1689,6 +1689,29 @@ public final class TestConfiguration {
     }
 
     /**
+     * Open connection to the specified database using the supplied username and password.
+     * Treat the database name as a physical database name rather than as a logical name
+     * which needs to be mapped.
+     * If the database does not exist, it will be created.
+     * Requires that the test has been decorated with
+     * additionalDatabaseDecorator with the matching name.
+     * @param physicalDatabaseName The real database name to use.
+     * @user name of user
+     * @password password of user
+     * @return connection to specified database.
+     */
+    public  Connection openPhysicalConnection( String physicalDatabaseName, String user, String password )
+        throws SQLException
+    {
+        return connector.openConnection
+            (
+             physicalDatabaseName,
+             user,
+             password
+             );
+    }
+
+    /**
      * Shutdown the database for this configuration
      * assuming it is booted.
      *