Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0AC9E1054B for ; Fri, 31 May 2013 08:09:04 +0000 (UTC) Received: (qmail 58325 invoked by uid 500); 31 May 2013 08:09:03 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 58227 invoked by uid 500); 31 May 2013 08:09:02 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 58190 invoked by uid 99); 31 May 2013 08:09:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 May 2013 08:09:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 May 2013 08:08:57 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3F5592388900; Fri, 31 May 2013 08:08:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130531080837.3F5592388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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() { + 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