Apple Applet Permissions

I put together a basic applet in which the user selects a file from his hard drive, he reads the first line of this file and passes it to JavaScript for some additional preprocessing, and then when you click the button, it tries to download this file via HTTP POST- request. I found a very simple open source applet for downloading files that I copied and changed for this last bit.

The problem is that it does not work. It seems to work fine, but then I run into two permission issues. Messages in the Java console say that the applet had access to failures in the following two resolutions:

java.lang.RuntimePermission setFactory
java.io.FilePermission read

I find this strange because I thought I granted permission to the applets already when I built it using the "self-signed" option noted in NetBeans and then clicked to confirm a small security popup in the browser.

Also, the part that I encoded myself, where it reads the file and passes the first line to JavaScript, works fine. This is a pretty clear indicator that the applet can read from the local file system! The problem does not start until I try to start the download. One point, I suppose, is that the boot process seems to be starting in a new thread, while everything else works in the main class without creating threads.

I am a complete newbie in Java and know little about threads in Java; Do I need to somehow transfer permissions to this new thread? Or something like that? Thanks in advance.

+5
source share
3 answers

You probably need to ask the security administrator (code, not administrator) to get permission to perform a privileged operation. For various reasons, it is not always useful for an applet to open a local file, so it is quite protected.

The main key is to call AccessController.doPrivileged()and there is a good little tutorial on it on the Java Ranch FAQ.

+3
source

, . , , JavaScript, , .

( , ): http://blog.carrythezero.com/?p=5

, : JavaScript , . , -, , , , .

+1

This is probably because JavaScript is unsigned. I highly recommend not signing the code, especially if you don’t know what you are doing. From 6u10 (not on Mac yet) applets can use JNLP, including FileOpenService, so you don't need to sign up.

0
source

All Articles