Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Security problem with File list()  RSS feed

 
wbcicles
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please help. I'm having a security problem when trying to list the content of a local dir from an Applet that resides in the same dir.... It was my understanding that an Applet can access the location it resides in(it's origin)???
The Code:
import java.io.*;
import java.applet.Applet;
public class TestDir extends Applet
{
public void init()
{
File f = new File(getCodeBase().toString());
String s = new String(f.list().toString());
System.out.println(f);
}
}

The Error:
java.security.AccessControlException: access denied (java.io.FilePermission file
:\C:\MyJava read)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkRead(SecurityManager.java:890)
at java.io.File.list(File.java:769)
at TestDir.init(TestDir.java:11)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
Is there anything I can do to overcome this problem?
Thanks for your help.... G.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This security is controlled by a policy file that is used by your browser. Usually it's the java.policy file in the java\jre\security subdirectory (which my be under windows). The settings are to provide you protection from someone gaining access to your computer and do harm or gain information that you may not want them to have. I checked mine and it doesn't allow read or write of any files or directories on my pc except the java.home \lib\ext directory (so don't store any vital information there). Getting your jar file signed can aliviate some of the security issues but, I'm not sure which ones. You can find and edit your policy file but, it still probably won't work on another persons PC.
Hope this helps
Hope this helps.
 
wbcicles
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help....
 
karthikeyan subramanian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the policytool utility to assign file permissions and check out the options for various things like IO permissions , socket permissions etc..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!