user2327483
user2327483

Reputation: 1

Can't get applet to read text file

I've tried to get my Java Applet to read from my text file, but I do not have sufficient privaleges to read the file when i run the applet in my browser. I have tried to use policy files but I cannot seem to get them to work.

I later tried

System.setProperty("java.security.policy", "*filelocation*");

but i got this error

java.security.AccessControlException: access denied (java.util.PropertyPermission        java.security.policy write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at BIT.init(BIT.java:35)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

What ways can I get my applet to run in my browser? It works fine in Eclipse's applet viewer.

Upvotes: 0

Views: 2739

Answers (2)

Vishal K
Vishal K

Reputation: 13066

The reason is specified within the What Applets Can and Cannot Do. It clearly specifies that:

Applets that are not signed are restricted to the security sandbox, and run only if the user accepts the applet. Applets that are signed by a certificate from a recognized certificate authority can either run only in the sandbox, or can request permission to run outside the sandbox. In either case, the user must accept the applet's security certificate, otherwise the applet is blocked from running.

Later it states that:

Sandbox applets cannot perform the following operations:

  • They cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.
  • They cannot connect to or retrieve resources from any third party server (any server other than the server it originated from).
  • They cannot load native libraries.
  • They cannot change the SecurityManager.
  • They cannot create a ClassLoader.
  • They cannot read certain system properties. See System Properties for a list of forbidden system properties.

To know about how to sign an Applet look here : How to Sign Applets Using RSA-Signed Certificates

Upvotes: 2

paulsm4
paulsm4

Reputation: 121871

You really ought to consider signing the applet.

This (short!) FAQ discusses both policies and signing:

Here is the offician documentation:

And here is a good (albeit old) tutorial:

Upvotes: 1

Related Questions