db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1488125 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ engine/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/functionTests/util/
Date Fri, 31 May 2013 08:08:37 GMT
Author: kahatlen
Date: Fri May 31 08:08:36 2013
New Revision: 1488125

URL: http://svn.apache.org/r1488125
Log:
DERBY-6224: Many test failures on latest JDK 8 EA build because of missing SQLPermission

Add the missing permission to the tests' policy files and wrap
AutoloadedDriver's calls to DriverManager.deregisterDriver() in a
privileged block.

Make the deregister=false attribute really prevent
DriverManager.deregisterDriver() from being called during system
shutdown, and make the network server shutdown logic use the attribute
to prevent the need for an extra permission in the default server
policy.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1488125&r1=1488124&r2=1488125&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Fri May 31 08:08:36 2013
@@ -925,7 +925,14 @@ public final class NetworkServerControlI
                         if (passwordArg != null) {
                             p.setProperty("password", passwordArg);
                         }
-                        cloudscapeDriver.connect("jdbc:derby:;shutdown=true", p);
+                        // DERBY-6224: DriverManager.deregisterDriver() requires
+                        // an extra permission in JDBC 4.2 and later. Invoke
+                        // system shutdown with deregister=false to avoid the
+                        // need for the extre permission in the default server
+                        // policy. Since the JVM is about to terminate, we don't
+                        // care whether the JDBC driver is deregistered.
+                        cloudscapeDriver.connect(
+                            "jdbc:derby:;shutdown=true;deregister=false", p);
                     }
                 } catch (SQLException sqle) {
                     // If we can't shutdown Derby, perhaps, authentication has

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java?rev=1488125&r1=1488124&r2=1488125&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java Fri May 31
08:08:36 2013
@@ -29,6 +29,9 @@ import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
 
 import java.io.PrintStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 import java.util.logging.Logger;
 
@@ -66,7 +69,7 @@ public class AutoloadedDriver implements
 	
 
     // This is the driver that memorizes the autoloadeddriver (DERBY-2905)
-    private static Driver _autoloadedDriver;
+    private static AutoloadedDriver _autoloadedDriver;
 
 	//
 	// This is the driver that's specific to the JDBC level we're running at.
@@ -260,20 +263,39 @@ public class AutoloadedDriver implements
         try {
             // deregister is false if user set deregister=false attribute (DERBY-2905)
             if (InternalDriver.getDeregister() && _autoloadedDriver != null) {
-                DriverManager.deregisterDriver(_autoloadedDriver);
+                deregisterDriver(_autoloadedDriver);
                 _autoloadedDriver = null;
-            } else {
-                DriverManager.deregisterDriver(_driverModule);
-                //DERBY 5085, need to restore the default value
-                InternalDriver.setDeregister(true);
             }
+
+            // DERBY-5085, need to restore the default value
+            InternalDriver.setDeregister(true);
+
             _driverModule = null;
         } catch (SQLException e) {
             if (SanityManager.DEBUG)
                 SanityManager.THROWASSERT(e);
         }
 	}
-	
+
+    private static void deregisterDriver(final AutoloadedDriver driver)
+            throws SQLException {
+        // DERBY-6224: DriverManager.deregisterDriver() requires a special
+        // permission in JDBC 4.2 and later. Call it in a privileged block
+        // so that the permission doesn't have to be granted to code that
+        // invokes engine shutdown.
+        try {
+            AccessController.doPrivileged(
+                    new PrivilegedExceptionAction<Void>() {
+                public Void run() throws SQLException {
+                    // Requires SQLPermission("deregisterDriver")
+                    DriverManager.deregisterDriver(driver);
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            throw (SQLException) pae.getCause();
+        }
+    }
 
 	/*
 	** Return true if the engine has been booted.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy?rev=1488125&r1=1488124&r2=1488125&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
Fri May 31 08:08:36 2013
@@ -91,6 +91,10 @@ grant codeBase "${derbyTesting.codejar}d
   // Needed by FileUtil#limitAccessToOwner
   permission java.lang.RuntimePermission "accessUserInformation";
   permission java.lang.RuntimePermission "getFileStoreAttributes";
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 //
@@ -240,6 +244,10 @@ grant codeBase "${derbyTesting.codeclass
   // Needed by FileUtil#limitAccessToOwner
   permission java.lang.RuntimePermission "accessUserInformation";
   permission java.lang.RuntimePermission "getFileStoreAttributes";
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 // JUnit jar file tries to read junit.properties in the user's

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=1488125&r1=1488124&r2=1488125&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
Fri May 31 08:08:36 2013
@@ -136,6 +136,10 @@ grant codeBase "${derbyTesting.codejar}d
 
   // This permission is needed to call the Connection.abort(Executor) method added by JDBC
4.1
   permission java.sql.SQLPermission "callAbort";
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 //
@@ -364,6 +368,9 @@ grant codeBase "${derbyTesting.codeclass
   permission java.lang.RuntimePermission "accessUserInformation";
   permission java.lang.RuntimePermission "getFileStoreAttributes";
 
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 // JUnit jar file tries to read junit.properties in the user's



Mime
View raw message