签名的 Java Applet 在连接到 Web 服务时引发安全异常

发布于 2024-08-08 04:16:03 字数 1159 浏览 4 评论 0原文

我有一个在 tomcat 5.5 上运行的 java 小程序。它已签名(-selfcert)。当我的 Applet 尝试连接到 Web 服务(已经在这一行中)时,我仍然收到 java.security.AccessControlException: access returned (java.lang.RuntimePermission createClassLoader) 异常:

ws_locator = new My_WebserviceLocator(ws_adress + "?wsdl",
                new javax.xml.namespace.QName("http://impl.webservice", "My_Webservice"));

因为有一些类似的这里有问题,我读过它们:

  • 是的,小程序已签名。我用 -verify 检查过。

  • Tomcat 安全异常,可能是,但我已添加到 catalina.policy:

    grant codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/-" {
        权限 java.security.AllPermission; };
    

    授予 codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/applet.jar" { 权限 java.security.AllPermission; };

并且通常的东西也在那里:

grant codeBase "file:${java.home}/jre/lib/ext/-" {
        permission java.security.AllPermission;
};

没有结果。

好的,快速更新,添加:

grant{
        permission java.security.AllPermission;
};

到本地 java.policy 文件修复了问题。但这不是我想要的,小程序应该在普通机器上运行,并带有默认的 java.policy 文件。因此必须从代码中修复它。

I have an java applet running on tomcat 5.5. It is signed ( -selfcert). I still get an java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader) Exception, when my Applet tries to connect to a webservice (already in this line):

ws_locator = new My_WebserviceLocator(ws_adress + "?wsdl",
                new javax.xml.namespace.QName("http://impl.webservice", "My_Webservice"));

Since there are some similar questions here, an i read them:

  • Yes, the applet is signed. I checked it with -verify.

  • Tomcat security exception, may be, but i have added to catalina.policy:

    grant codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/-" {
        permission java.security.AllPermission;    };
    

    grant codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/applet.jar" { permission java.security.AllPermission; };

and the usual stuff like is also in there:

grant codeBase "file:${java.home}/jre/lib/ext/-" {
        permission java.security.AllPermission;
};

with no result.

Ok, quick update, adding:

grant{
        permission java.security.AllPermission;
};

to the local java.policy file fixes the problem. BUT thats not what i am looking for, the applet should run on an avarage machine, with dafault java.policy file. So it has to be fixed from within the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天暗了我发光 2024-08-15 04:16:03

您是从 applet 主线程还是从使用 javascript 调用 applet 方法启动的线程调用 WS?

请参阅下面的示例。

希望有帮助。

public class MyApplet extends JApplet {

    @Override
    public void start() {
        // It will work if your applet is signed
        callWebService();
    }

    public void methodCalledFromJavascriptWrong() {
        // It will NOT work even if your applet is signed
        callWebService();

    }

    public void methodCalledFromJavascriptGood() {
        AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                // It will work if your applet is signed
                callWebService();
                return null;
            }

        });

    }

    private void callWebService() {
        //Here you call your web service
    }
}

Do you call your WS from the applet main thread or from a thread initiated by a call to the applet's method using javascript?

See example below.

Hope it helps.

public class MyApplet extends JApplet {

    @Override
    public void start() {
        // It will work if your applet is signed
        callWebService();
    }

    public void methodCalledFromJavascriptWrong() {
        // It will NOT work even if your applet is signed
        callWebService();

    }

    public void methodCalledFromJavascriptGood() {
        AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                // It will work if your applet is signed
                callWebService();
                return null;
            }

        });

    }

    private void callWebService() {
        //Here you call your web service
    }
}
赴月观长安 2024-08-15 04:16:03

在服务器上设置权限并不是解决方案。抱怨的是浏览器中的安全管理器。

建议使用 AccessManager 确实是强制性的,否则将会失败。
但是,当从 start() 或 init() 调用 Web 服务时,您也需要执行相同的操作。

请问:WebService 调用是您拥有小程序的唯一原因吗?最好放置一个代理 servlet 以避免相同域策略限制。然后就可以在浏览器中使用纯HTML + Javascript了。

如果在小程序完全启动之前从 JS 调用小程序可能会失败,因此您应该等待小程序准备就绪。

Setting permissions on the server is not the solution. It is the security manager in the browser that complains.

The proposed use of AccessManager is indead mandatory or this will fail.
But you also need to do the same when calling the webservice from start() or init().

Can I ask: is the WebService call the only reason why you have an applet ? It might be better to put a proxy servlet in place to avoid Same domain policy restrictions. Then you can use pure HTML + Javascript in the browser.

Calling into an applet from JS can fail if you do it before the applet is fully started, so you should wait for the applet to be ready.

他是夢罘是命 2024-08-15 04:16:03

如果您正在使用小程序中的其他库(jar),它们会与任何受限资源发生交互,那么它们也应该被签名。
因此,请提供整个堆栈跟踪和 My_WebserviceLocator。 (并且不要使用下划线)。例如,尝试签署 axis.jar。

If you are using other libraries (jars) from your applet, that interract with any restricted resource, they should also be signed.
So give the whole stacktrace, and the My_WebserviceLocator. (And don't use underscores). For example try signing the axis.jar.

反话 2024-08-15 04:16:03

作为临时解决方法,您可以禁用 SecurityManager。当然,这会带来一些安全问题,但至少您可以将其追踪到 SecurityManager(即权限问题)。

System.setSecurityManager(null);

如果这确实有效,我的猜测是您配置了错误的策略文件。当从浏览器运行小程序时,我几乎确信小程序启动器将是常规的消费者 JRE,而不是与 JDK 捆绑在一起的 jre。

As a temporary workaround, you can disable the SecurityManager. Of course this have some security issues, but at least you will be able to track it down to the SecurityManager (ie, a permissions issue).

System.setSecurityManager(null);

If this indeed works, my guess is that you are configuring the wrong policy file. When running an applet from the browser, I'm almost sure that the applet launcher will be a regular consumer JRE, not the jre bundled with the JDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文