" java.security.AccessControlException:拒绝访问"执行签署的Java Applet [英] "java.security.AccessControlException: access denied" executing a signed Java Applet

查看:803
本文介绍了" java.security.AccessControlException:拒绝访问"执行签署的Java Applet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点点的Java Applet和我有一个恼人的问题。我的签署我用我自己的密钥库JAR使用jarsigner工具(以下的说明)。

I have a little Java Applet and I have an annoying issue. I have signed my JAR with my own keystore using jarsigner tool (following these instructions).

Java程序下载一个签署 JAR,并尝试与扩展类的 URLClassLoader的。这个JAR尝试执行此行code的:

The Java Applet downloads a signed JAR and tries to launch it with an extended class of URLClassLoader. This JAR tries to execute this line of code:

ClassLoader.getSystemClassLoader().getResource("aResource");

它无法通过完成一个大的堆栈跟踪:

It fails with a large stack trace finished by:

Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
    at java.security.AccessController.checkPermission(AccessController.java:555)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1476)
    at test.SecondJAR.main(SecondJAR.java:8)

(线路test.SecondJAR的8对应的getResource(...)

当Java小程序启动时,系统会提示用户,如果他/她相信出版商接受证书:

When the Java Applet is launched, the user is prompted to accept the certificate if he/she trusts the publisher:

就算我接受它,发生异常。即使我安装证书,并提示消息被自动接受,发生异常。

Even if I accept it, the exception occurred. Even if I install the certificate, and the prompt message is automatically accepted, the exception occurred.

我曾尝试过这样的:

AccessController.doPrivileged(new PrivilegedAction<Object>() {
    public Object run() {
        ClassLoader.getSystemClassLoader().getResource("aResource");
        return null;
    }
});

和失败与相同的异常。

任何帮助将是AP preciated!

Any help would be appreciated!

推荐答案

最后,我已经找到了答案!

Finally I have found the answer!

我跟着谭安德的指导方针和我创建了一个自定义的 SecurityManager的。我的小安全管理器看起来是这样的:

I followed the guidelines of Andrew Thomson and I created a custom SecurityManager. My little security manager looks like this:

private class MySecurityManager extends SecurityManager {
    @Override
    public void checkPermission(Permission perm) {
        return;
    }
}

这是接受所有权限一个被忽视的安全管理。应该改进只允许获取系统的ClassLoader的运行时间。

It is a neglected security manager that accepts all permissions. It should be improved allowing only getting system ClassLoader in runtime.

要使用我的丑的SecurityManager我说这些线在的Java Applet 的start()方法的开头:

To use my ugly SecurityManager I added these lines at the beginning of Java Applet start() method:

SecurityManager sm = new MySecurityManager();
System.setSecurityManager(sm);

通过此解决方案,所有的过程和预期一样!

With this workaround, all the process worked as expected!

也许还存在其他的(更好的)解决方案,但它为我工作。

Maybe there exist other (better) solutions, but it worked for me.

感谢大家!

这篇关于&QUOT; java.security.AccessControlException:拒绝访问&QUOT;执行签署的Java Applet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆