开发者

Problem with using signed Applet with policy File

开发者 https://www.devze.com 2023-02-14 11:51 出处:网络
i have a problem with the .java.policy entries for my applet. I would try to create folders and files with an applet. I had already signed my jar and added in the ${user.home}/.java.policy-file the f

i have a problem with the .java.policy entries for my applet.

I would try to create folders and files with an applet. I had already signed my jar and added in the ${user.home}/.java.policy-file the following lines:

grant {
  permission java.io.FilePermission "<<ALL FILES>>", "read";
  permission java.io.FilePermission "<<ALL FILES>>", "write";
};

with this added lines, my applet works great, but this is not a good style, because every jar at any places becomes the file permissions too.

At the oracle pages are examples to set the codeBase to the specified applet.jar and set the signedBy (the alias wich the jar-file is signed) to grand permissions.

I have tried this many times, but it doesn't work.

The code i have tried:

grant codeBase "http://www.wkmovies.de/appletDemo/-" {
  permission java.io.FilePermission "<<ALL FILES>>", "read";
  permission java.io.FilePermission "<<ALL FILES>>", "write";
};

or

grant signedBy "AKlettke" {
  permission java.io.FilePermission "<<ALL FILES>>", "read";
  permission java.io.FilePermission "<<ALL FILES>>", "write";
};

I have uploaded this example to: www.wkmovies.de/appletDemo/index.html

How can i set up the policy file, that my applet will work?


Here my code snips: HTML:

<a href="javascript:document.applet1.createFolder();">
  Create Folder at C:\\Temp
</a>
<applet name="applet1" id="app开发者_如何学运维let1" width="0" height="0" alt=""
  archive="applets/Demo.jar,applets/lib/commons-lang-2.4.jar" 
  code="demo.FolderCreator.class">
</applet>

FolderCreator class:

try {
  File f = new File("C:\\temp");
  f.mkdir();
  JOptionPane.showMessageDialog(null, "folder created",
    "successfull", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
  e.printStackTrace();
  JOptionPane.showMessageDialog(null, e.getMessage(),
    e.getClass().getName(), JOptionPane.ERROR_MESSAGE);
}

(JDK1.6.0_23, Firefox 3.0.19, WinXP 32bit)


Try priveleged API: http://download.oracle.com/javase/1.4.2/docs/guide/security/doprivileged.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号