db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r794112 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/tests/tools/ testing/org/apache/derbyTesting/functionTests/util/ tools/org/apache/derby/impl/tools/ij/
Date Tue, 14 Jul 2009 23:11:22 GMT
Author: kmarsden
Date: Tue Jul 14 23:11:22 2009
New Revision: 794112

URL: http://svn.apache.org/viewvc?rev=794112&view=rev
Log:
DERBY-4292 creation of FileInputStream in org.apache.derby.impl.tools.ij.Main not wrapped
in privilege block which can cause problems running under SecurityManager

Contributed by Tiago R. Espinha (tiago at espinhas dot net)


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.sql
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.java?rev=794112&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.java
Tue Jul 14 23:11:22 2009
@@ -0,0 +1,89 @@
+/*
+
+   Derby - Class 
+   org.apache.derbyTesting.functionTests.tests.tools.IjSecurityManager
+
+   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.functionTests.tests.tools;
+
+import java.io.PrintStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.functionTests.util.TestNullOutputStream;
+import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public class IjSecurityManagerTest extends BaseTestCase {
+
+	public IjSecurityManagerTest(String name) {
+		super(name);
+	}
+
+	public void testRunIJ() throws Exception {
+	    /* Save the original out stream */
+	    final PrintStream out = System.out;
+	    
+	    /* Mute the test */
+	    AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                System.setOut(new PrintStream(new TestNullOutputStream()));
+                return null;
+            }
+        });
+	    
+	    try {
+	        /* Run ij */
+	        ij.main(new String[]{"extinout/IjSecurityManagerTest.sql"});
+	    } catch (Exception e) { /* Should NEVER happen */
+	        fail("Failed to run ij under security manager.",e);
+	    } finally {
+	        /* Restore the original out stream */
+	        AccessController.doPrivileged(new PrivilegedAction() {
+	            public Object run() {
+	                System.setOut(out);
+	                return null;
+	            }
+	        });
+	    }
+	}
+	
+	private static Test decorateTest() {	    
+	    Test test = TestConfiguration.embeddedSuite(IjSecurityManagerTest.class);
+        test = new SupportFilesSetup
+         (
+          test,
+          null,
+          new String[] { "functionTests/tests/tools/IjSecurityManagerTest.sql"  },
+          null,
+          new String[] { "IjSecurityManagerTest.sql"}
+          );
+        return test;
+	}
+	public static Test suite() {		
+		TestSuite suite = new TestSuite("IjSecurityManagerTest");
+		suite.addTest(decorateTest());
+		return suite;
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.sql?rev=794112&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.sql
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/IjSecurityManagerTest.sql
Tue Jul 14 23:11:22 2009
@@ -0,0 +1,21 @@
+--
+--   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.
+--
+
+-- Regular database creation test for ij
+
+connect 'jdbc:derby:wombat;create=true';
+values(1);

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java?rev=794112&r1=794111&r2=794112&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
Tue Jul 14 23:11:22 2009
@@ -54,7 +54,8 @@
         suite.addTest(ToolScripts.suite());
         suite.addTest(SysinfoCPCheckTest.suite());
         suite.addTest(SysinfoLocaleTest.suite());
-
+        suite.addTest(IjSecurityManagerTest.suite());
+        
         // SysinfoAPITest currently fails when run against jars, so is
         // disabled. Only the first jar file on the classpath properly
         // returns its information through the sysinfo API.

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java?rev=794112&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java
Tue Jul 14 23:11:22 2009
@@ -0,0 +1,60 @@
+/*
+
+   Derby - Class 
+   org.apache.derbyTesting.functionTests.util.TestNullOutputStream
+
+   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.functionTests.util;
+
+import java.io.OutputStream;
+
+/**
+An OutputStream that simply discards all data written to it.
+*/
+
+public class TestNullOutputStream extends OutputStream {
+
+    /*
+    ** Methods of OutputStream
+    */
+
+    /**
+        Discard the data.
+
+        @see OutputStream#write
+    */
+    public  void write(int b)  {
+    }
+
+    /**
+        Discard the data.
+
+        @see OutputStream#write
+    */
+    public void write(byte b[]) {
+    }
+
+    /**
+        Discard the data.
+
+        @see OutputStream#write
+    */
+    public void write(byte b[], int off, int len)  {
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestNullOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java?rev=794112&r1=794111&r2=794112&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Main.java Tue Jul 14 23:11:22
2009
@@ -39,6 +39,8 @@
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.sql.Connection;
 import java.sql.SQLException;
 
@@ -114,12 +116,17 @@
                         out.flush();
     	        } else {
                     try {
-                        in1 = new FileInputStream(file);
+                    	final String inFile1 = file;
+                    	in1 = (FileInputStream) AccessController.doPrivileged(new PrivilegedExceptionAction()
{
+            				public Object run() throws FileNotFoundException {
+        						return new FileInputStream(inFile1);
+            				}
+            			});
                         if (in1 != null) {
                             in1 = new BufferedInputStream(in1, utilMain.BUFFEREDFILESIZE);
                             in = langUtil.getNewInput(in1);
                         }
-                    } catch (FileNotFoundException e) {
+                    } catch (PrivilegedActionException e) {
                         if (Boolean.getBoolean("ij.searchClassPath")) {
                             in = langUtil.getNewInput(util.getResourceAsStream(file));
                         }



Mime
View raw message