Giving a JApplet read write access to the local file system

≯℡__Kan透↙ 提交于 2020-01-03 05:14:31

问题


I have a JApplet that I want to give read write print etc permission to. This applet is loaded only from the local file system

I have been reading through the controlling applets part of the java tutorials and have successfully created a policy file, giving permissions and specifying the code base http://docs.oracle.com/javase/tutorial/security/tour1/index.html

To get the example applet to write to the local system successfully I had to add this line to the java.security file. policy.url.3=file:/home/susanj/test/examplepolicy

The question is, How does one achieve the same result through code?.

I assume you start with the Policy class http://docs.oracle.com/javase/6/docs/api/java/security/Policy.html#getInstance%28java.lang.String,%20java.security.Policy.Parameters%29

create a new policy with either one of the getInstance methods

Policy.getInstance(String type,Policy.Parameters params)

Policy. getInstance(String type,Policy.Parameters params, Provider provider)

Policy. getInstance(String type,Policy.Parameters params, String provider)

and add it via the Policy.setPolicy(Policy p) method and then use Policy.refresh();

Unfortunately it seems to fall apart with the getInstance method and things start to get pretty confusing, what I need to know is what type, policy parameters do I need to use as arguments to give full permission to my applet.

This applet is not download from the internet, it is part of a desktop application so I can run a class/jar file with full privileges before the applet loads. I'm assuming you may be able to set the policy file this way before the applet loads?

I am assuming that this is actually the correct way.

Regards

Brett


回答1:


It would be a really bad idea if you could modify the policy from within the sandbox...which is what it sounds like you're trying to do.

Have a read through Set up a Policy File to Grant the Required Permission.

You basically need to update the Policy file in the default instance of Java before you can run the Applet.

Or you can sign it.

  • How to Sign Applets Using RSA-Signed Certificates
  • Is it possible to sign a java applet for free?


来源:https://stackoverflow.com/questions/11996620/giving-a-japplet-read-write-access-to-the-local-file-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!