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 km...@apache.org on 2009/04/10 19:38:23 UTC

svn commit: r763987 - in /db/derby/code/branches/10.5/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/functionTests/util/

Author: kmarsden
Date: Fri Apr 10 17:38:22 2009
New Revision: 763987

URL: http://svn.apache.org/viewvc?rev=763987&view=rev
Log:
DERBY-4128  Failure in ServerPropertiesTest due to java.security.AccessControlException on the server side, in 10.4 to 10.5.1. soft upgrade mode


Modified:
    db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DssTrace.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.policy
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy

Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DssTrace.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DssTrace.java?rev=763987&r1=763986&r2=763987&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DssTrace.java (original)
+++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/DssTrace.java Fri Apr 10 17:38:22 2009
@@ -21,6 +21,7 @@
 package org.apache.derby.impl.drda;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.security.AccessController;
@@ -173,33 +174,59 @@
     synchronized (comBufferSync) {
         // Only start the trace if it is off.
         if (comBufferTraceOn == false) {
-            try {
-                // Attempt to make the trace directory if it does not exist.
-                // If we can't create the directory the exception will occur 
-                // when trying to create the trace file.
-                final File traceDirectory = new File(fileName).getParentFile();
-                if (traceDirectory != null) {
-                    AccessController.doPrivileged(
-                            new PrivilegedAction() {
-                                public Object run() {
-                                    traceDirectory.mkdirs();
-                                    return null;
-                                }
-                            });
-
-                }
-                // The writer will be buffered for effeciency.
-                comBufferWriter =  ((PrintWriter)AccessController.doPrivileged(
+            // Make up to two attempts to create the trace file.
+            // First just try to make it. Then if we get a FileNotFoundException
+            // try making the directory and then retry the create.
+            // We don't try making the directory first because it would require
+            // extra permissions if the directory already exists. DERBY-4128
+            for (int attempt=0; attempt <2; attempt++) {
+                try {             	
+                    // The writer will be buffered for effeciency.
+                    comBufferWriter =  ((PrintWriter)AccessController.doPrivileged(
                             new PrivilegedExceptionAction() {
                                 public Object run() throws SecurityException, IOException {
                                     return new  PrintWriter (new java.io.BufferedWriter (new java.io.FileWriter (fileName), 4096));
                                 }
                             }));
-            } catch (PrivilegedActionException pae) {
-               throw  pae.getException();
-               
-            }
-          
+                    // If we successfully made the file. break out here and don't retry
+                    break;
+                } catch (PrivilegedActionException pae) {
+                    Exception e = pae.getException();
+                    // If we got a FileNotFoundException on the first attempt,
+                    // it is likely that the directory did not exist. 
+                    //We will try to make it.
+                    if (attempt == 0 && (e instanceof FileNotFoundException)) {
+                        final File traceDirectory = new File(fileName).getParentFile();
+                        if (traceDirectory != null) {
+                            AccessController.doPrivileged(
+                                    new PrivilegedAction() {
+                                        public Object run() {
+                                            // DERBY-4128: First try to create the
+                                            // directory with mkdir(), as that doesn't
+                                            // require read permission for the parent
+                                            // directory. It will only succeed if the
+                                            // parent directory exists. If mkdir()
+                                            // fails, retry with mkdirs(), which will
+                                            // create the parent directories as needed,
+                                            // but which also requires that read
+                                            // permission for the parent directory
+                                            // has been granted.
+                                            boolean created = traceDirectory.mkdir();
+                                            if (!created) {
+                                                traceDirectory.mkdirs();
+                                            }
+                                            return null;
+                                        }
+                                    });
+
+                        }
+                    } else {
+                        // This is our second attempt or we got some other exception besides
+                        // FileNotFoundException. Just throw the exception.
+                        throw e;
+                    }
+                }
+        	}
           // Turn on the trace flag.
           comBufferTraceOn = true;
           // initialize the codepoint name table if it is null.

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.policy?rev=763987&r1=763986&r2=763987&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.policy (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.policy Fri Apr 10 17:38:22 2009
@@ -98,8 +98,8 @@
   permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
 
   // For testPropertiesAfterConnection and testPropertiesTraceOn
-  permission java.io.FilePermission "${derby.system.home}", "read";
   permission java.io.FilePermission "${derby.system.home}${/}-", "write"; 
+
 };
 
 //

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy?rev=763987&r1=763986&r2=763987&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy Fri Apr 10 17:38:22 2009
@@ -93,8 +93,7 @@
   permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
   permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
     //tracing testing. NetworkServerControlApiTest
-    permission java.io.FilePermission "${derby.system.home}", "read";
-    permission java.io.FilePermission "${derby.system.home}${/}-", "read,write";
+    permission java.io.FilePermission "${derby.system.home}${/}-", "write";
 };
 
 //

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy?rev=763987&r1=763986&r2=763987&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy Fri Apr 10 17:38:22 2009
@@ -98,7 +98,6 @@
   permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
 
   // for testToggleTrace:
-  permission java.io.FilePermission "${derby.system.home}", "read,write";
   permission java.io.FilePermission "${derby.system.home}${/}-", "write"; 
 };
 

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=763987&r1=763986&r2=763987&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy Fri Apr 10 17:38:22 2009
@@ -142,8 +142,8 @@
   permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
   permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
   // Need to be able to write to trace file for NetworkServerControlApiTest
+  permission java.io.FilePermission "${user.dir}${/}system${/}trace", "write"; 
   permission java.io.FilePermission "${user.dir}${/}system${/}trace${/}-", "write"; 
-  permission java.io.FilePermission "${user.dir}${/}system${/}trace", "read,write";
     // Needed for NetworkServerMBean access (see JMX section above)
   permission org.apache.derby.security.SystemPermission "server", "control,monitor";