Can a JApplet
use a JFileChooser
so that the user can select a file on his hard-drive? Or would this violate Java applet security? (I'm assuming that the default security settings are being used. I don't want to ask my users to grant me extra permissions.)
This thread indicates that you need to digitally sign your applet before a JFileChooser
is permitted.
As mentioned, you need to sign your applet, which result in a "vague security warning" when the user is presented the applet. When the user accept to run this applet, the applet is given full access and functions like an ordinary application with it's obvious security implications. I'm in the same dilemma regarding a web application I'm working on and is not yet sure if it'll get deployed.
You could alternatively use the built-in filebrowser in the webbrowser and bounce back the file-content from your server if you're working with smaller files.
Also, some security measures you can make regarding a signed applet are:
Validating the origin of the applet code.
URL appletUrl = MyApplet.class.getProtectionDomain().getCodeSource().getLocation();
if(appletUrl.toString().equalsIgnoreCase(safeAppletUrl) == false)
return false;
Verifying the base URL from which the applet was run.
URL documentUrl = this.getDocumentBase();
if(documentUrl.toString().equalsIgnoreCase(safeDocumentUrl) == false)
return false;
In that case (of using default settings), you're correct, the default security manager does not allow access to local files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With