db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r536677 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Date Wed, 09 May 2007 22:01:34 GMT
Author: kmarsden
Date: Wed May  9 15:01:34 2007
New Revision: 536677

URL: http://svn.apache.org/viewvc?view=rev&rev=536677
Log:
DERBY-2556 Code paths for db restore do not use doPrivileged-calls, causing SecurityException

Add priv blocks for File.exists() calls in restore.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?view=diff&rev=536677&r1=536676&r2=536677
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Wed May  9 15:01:34 2007
@@ -574,11 +574,11 @@
 		{
 			//First make sure backup service directory exists in the specified path
 			File backupRoot = new File(restoreFrom);
-			if(backupRoot.exists())
+			if(privExists(backupRoot))
 			{
 				//First make sure backup have service.properties
 				File bserviceProp = new File(restoreFrom, PersistentService.PROPERTIES_NAME);
-				if(bserviceProp.exists())
+				if(privExists(bserviceProp))
 				{
 					//create service root if required
 					if(createRoot)
@@ -909,4 +909,31 @@
             return null;
         } // end of run
     } // end of class DirectoryList
+    
+    /**
+     * Wrap File.exists() in a priv block to avoid Security exceptions
+     * @param fileToCheck
+	 * @return true if file exists, false if it does not
+	 * @throws SecurityException
+	 */
+    private boolean privExists(final File fileToCheck) throws SecurityException{
+        try {
+            
+            Boolean exist  = (Boolean) AccessController.doPrivileged(
+                    new PrivilegedExceptionAction()
+                    {
+                        public Object run()
+                        throws SecurityException
+                        {
+                            return new Boolean(fileToCheck.exists());
+                        }
+                    }); 
+            return exist.booleanValue();
+        }
+        catch( PrivilegedActionException pae)
+        {
+            throw (SecurityException) pae.getException();
+        }
+    }
+
 }



Mime
View raw message