changeset 1085:540c7f47aadf

6738668: JFileChooser cannot be created under SecurityManager Reviewed-by: peterz
author rupashka
date Tue, 17 Mar 2009 16:06:14 +0300
parents 4f7dd74de2e3
children 4bf886c9df34
files src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java test/javax/swing/JFileChooser/6738668/bug6738668.java test/javax/swing/JFileChooser/6738668/security.policy
diffstat 5 files changed, 70 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Fri Mar 13 19:25:17 2009 +0300
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Tue Mar 17 16:06:14 2009 +0300
@@ -39,6 +39,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import sun.awt.shell.ShellFolder;
 import sun.awt.OSInfo;
@@ -1143,7 +1145,11 @@
 
             File[] baseFolders;
             if (useShellFolder) {
-                baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders");
+                baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+                    public File[] run() {
+                        return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
+                    }
+                });
             } else {
                 baseFolders = fsv.getRoots();
             }
--- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java	Fri Mar 13 19:25:17 2009 +0300
+++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java	Tue Mar 17 16:06:14 2009 +0300
@@ -38,6 +38,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import javax.accessibility.*;
 
 import sun.awt.shell.ShellFolder;
@@ -937,7 +939,11 @@
 
             File[] baseFolders;
             if (useShellFolder) {
-                baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders");
+                baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+                    public File[] run() {
+                        return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
+                    }
+                });
             } else {
                 baseFolders = fsv.getRoots();
             }
--- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Fri Mar 13 19:25:17 2009 +0300
+++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Tue Mar 17 16:06:14 2009 +0300
@@ -29,6 +29,8 @@
 import java.beans.*;
 import java.io.*;
 import java.util.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.swing.*;
 import javax.swing.event.*;
@@ -749,7 +751,11 @@
 
             File[] baseFolders;
             if (useShellFolder) {
-                baseFolders = (File[])ShellFolder.get("fileChooserComboBoxFolders");
+                baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+                    public File[] run() {
+                        return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
+                    }
+                });
             } else {
                 baseFolders = fsv.getRoots();
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JFileChooser/6738668/bug6738668.java	Tue Mar 17 16:06:14 2009 +0300
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 6738668
+   @summary JFileChooser cannot be created under SecurityManager
+   @author Pavel Porvatov
+   @run main/othervm/policy=security.policy bug6738668
+*/
+
+import javax.swing.*;
+import java.io.File;
+
+public class bug6738668 {
+    public static void main(String[] args) throws Exception {
+        for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {
+            UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
+
+            new JFileChooser(new File("c:/temp"));
+
+            System.out.println("Test passed for LookAndFeel " + lookAndFeelInfo.getClassName());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JFileChooser/6738668/security.policy	Tue Mar 17 16:06:14 2009 +0300
@@ -0,0 +1,5 @@
+grant {
+    permission java.io.FilePermission "C:\\temp\\*", "read";
+    permission java.io.FilePermission "C:\\temp", "read";
+    permission java.util.PropertyPermission "*", "read";
+};