Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JFileChooser needs write Permission ?

47 views
Skip to first unread message

Martin Lisowski

unread,
Apr 14, 1999, 3:00:00 AM4/14/99
to
Hi,

I want a (signed jdk1.2.1) applet to upload a file from the client to
the server. First step is to display a JFileChooser to select the file.
The problem is that I get an exception unless I add a "write" permission
to the .java.policy . I really don't want to give write permissions to
client harddisks just to display their directory.

The write permission I have to add depends on the initial directory
passed to the JFileChooser() call (see source code below).

As I said, the applet is signed and JFrames do display without the
yellow banner.

Does anybody know why I need the write permission ? Is it a bug ?


Martin


The minimum policy file that works (no exception) is:
------------------------------------------------------------------------
/* AUTOMATICALLY GENERATED ON Wed Apr 14 15:47:47 GMT+02:00 1999*/
/* DO NOT EDIT */

grant codeBase "http://oraweb02/doku/applets/test.jar" {
permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "D:/", "write";
};
------------------------------------------------------------------------
If I remove the last "permission" line, I get the following (the
JFileChooser is not displayed):

Java(TM) Plug-in
Using JRE version 1.2.1
User home directory = D:\WINNT\Profiles\Administrator
Proxy Configuration: no proxy

JAR cache disabled.
Opening http://oraweb02/doku/applets/test.jar no proxy
No holding
CacheHandler trying caching. http://oraweb02/doku/applets/test.jar
CacheHandler file name:
D:\Programme\Netscape\Users\martin\cache\M0N7FT2A.JAR
Got cached copy
java.security.AccessControlException: access denied
(java.io.FilePermission D:\ write)
at java.security.AccessControlContext.checkPermission(Compiled Code)
at java.security.AccessController.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkPermission(Compiled Code)
at java.lang.SecurityManager.checkWrite(SecurityManager.java:946)
at java.io.File.canWrite(File.java:526)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$3.propertyChange(WindowsFileChooserUI.java:505)
at
javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Compiled
Code)
at javax.swing.JComponent.firePropertyChange(Compiled Code)
at javax.swing.JFileChooser.setCurrentDirectory(Compiled Code)
at javax.swing.JFileChooser.<init>(JFileChooser.java:265)
at javax.swing.JFileChooser.<init>(JFileChooser.java:226)
at test.init(test.java:56)
at sun.applet.AppletPanel.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)


Source: test.java
------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;
import javax.swing.*;

public class test extends JApplet {

public void init()
{
String laf = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException exc) {
System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
} catch (Exception exc) {
System.err.println("Error loading " + laf + ": " + exc);
}

JFileChooser fc = new JFileChooser("D:\\");
fc.showOpenDialog(getContentPane());
}
}

0 new messages