java applet js,签名的Java Applet从JavaScript调用时给出的AccessControlException

First of all I'm aware that my question is same as in here. But that question did not helped me.

I have self signed applet.

jarsigner -verify sJSApplet.jar

jar verified.

Warning:

This jar contains entries whose signer certificate will expire within six months.

Applet's purpose is to open MS Word document from LAN machine.

So far I've tried opening using Desktop.open() and Runtime.exec(). With AccessController.doPrivileged and without. I always get java.security.AccessControlException: access denied.

I'm out of options. What else I could do?

I cannot use java.policy file.

HTML

function openFile( command ) {

var applet = "Applet failed to run. No Java plug-in was found.";

var body = document.getElementsByTagName("body")[0];

var div = document.createElement("div");

div.innerHTML = applet;

body.appendChild(div);

}

Open file

Java code:

public class WordApplet extends JApplet {

@Override

public void init() {

openFile(getParameter("filePath"));

};

public void openFile(final String path) {

AccessController.doPrivileged(new PrivilegedAction() {

@Override

public Object run() {

try {

Runtime.getRuntime().exec("winword " + path);

//Desktop.getDesktop().open(new File(path));

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

});

}

}

Full stack trace

java.security.AccessControlException: access denied (java.io.FilePermission <> execute)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkExec(Unknown Source)

at java.lang.ProcessBuilder.start(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at com.test.applet.JSApplet$1.run(JSApplet.java:34)

at java.security.AccessController.doPrivileged(Native Method)

at com.avacoda.swing.JSApplet.openFile(JSApplet.java:29)

at com.avacoda.swing.JSApplet.init(JSApplet.java:25)

at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)

at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

basic: Applet initialized

解决方案

There is nothing wrong with code samples above. Both cases Desktop.getDesktop().open() and Runtime.getRuntime().exec() works perfectly.

My problem was badly packaged jar.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值