在是否冰茶JRE这个小程序的工作? [英] Does this applet work in an Iced Tea JRE?

查看:150
本文介绍了在是否冰茶JRE这个小程序的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提到一个小的演示。在<一个href=\"http://stackoverflow.com/questions/5313672/setting-up-policies-for-an-applet-embedded-in-html/5314300#5314300\">
嵌入在HTML &放一个Applet设置策略;冰茶JRE用户评论说,该演示。失败
他们。他们的被拒以小程序(从而将其限制在沙箱)及被应该,查看
有色绿色的此applet是沙箱页面。相反,小程序完全失败,他们看到了灰色空间
那里的小程序应该是。

我发动它试图实例化一个文件对象的区别。 I.E.
太阳/ Oracle的JRE将允许它没有问题,只是抛出一个安全异常
当小程序试图创建的JFileChooser 。 OTOH冰茶JRE不允许
文件被创建

因此​​,该code应该解决这个问题。它会将创建/加入的
的JEditorPane 和安装1日
一个一切都失败了的消息,那么绿色的沙箱页面,在新的文件之前(..)电话。

我的问题是。这是否code为用户提供了一个冰茶JRE为标榜的工作?

要测试一下:


  1. 访问小程序在
    PS code.org /测试/ docload / applet的latest.html
  2. 拒绝了数字签名code。这是非常重要的,建立正确的
    条件下测试该小程序。
  3. 观察/报告中的小程序是否加载绿色的
    sandbox.html 。在沙箱
    文件将在修复bug重新present成功。

还感兴趣的(小有可能是什么)是网页
可信的applet的防守数据加载中演示,哪个环节
到小程序网页​​中,每个HTML文件的显示在小应用程序,和包含一个ZIP存档
在code和来源; HTML和Ant build.xml文件,因此您可以在家做,孩子们的。

下面是新的code。

 包org.ps code.eg.docload;进口java.awt.BorderLayout中;进口java.awt.event.ActionListener;
进口java.awt.event.ActionEvent中;进口javax.swing.JApplet中;
进口javax.swing.JButton中;
进口javax.swing.JEditorPane中;
进口javax.swing.JPanel中;
进口javax.swing.JScrollPane中;
进口javax.swing.JFileChooser中;进口的java.net.URL;
进口java.net.MalformedURLException;进口的java.io.File;
进口java.io.IOException异常;进口java.security.AccessControlException;/ **小程序来显示的JEditorPane中兼容的文件。
这个小程序加载在一次防守方式的安全环境方面,
如果用户拒绝接受数字签名code。 * /
公共类DocumentLoader扩展JApplet的{
    JEdi​​torPane的文件;    @覆盖
    公共无效的init(){
        的System.out.println(的init());        主要的JPanel =新JPanel();
        main.setLayout(新的BorderLayout());
        。的getContentPane()加(主);        文档=新的JEditorPane(text / html的
            &LT; HTML和GT;&LT;身体GT;&LT; H1&GT;测试与LT; / H1&GT;&LT; P&GT;测试安全环境..);
        main.add(新JScrollPane的(文件),BorderLayout.CENTER);
        的System.out.println(的init():进入'尝试');        尝试{
            //设置了绿色的沙盒URL,为precaution ..
            URL沙盒=新的URL(getDocumentBase(),sandbox.html);
            document.setPage(沙盒);            //这听起来很奇怪,一个沙盒applet可/实例/
            // File对象,但直到它去用它做任何事情时,
            // JVM认为,OK。直到我们去做了什么
            //'文件'的对象,它实际上只是一个文件名。
            的System.out.println(的init():实例文件);
            文件f =新的文件(。);
            的System.out.println(的init():文件实例化,创建文件选择);
            //上述这里的一切是可能的沙盒小程序            // *测试*如果这个小程序是沙箱
            最终的JFileChooser JFC =
                新的JFileChooser(F); //调用安全检查
            jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            jfc.setMultiSelectionEnabled(假);            的System.out.println(
                的init():文件选择创建的,+
                创建/添加加载文件按钮);
            JButton的按钮=的新的JButton(加载文件);
            button.addActionListener(新的ActionListener(){
                    公共无效的actionPerformed(ActionEvent的AE){
                        INT结果= jfc.showOpenDialog(
                            DocumentLoader.this);
                        如果(结果== JFileChooser.APPROVE_OPTION){
                            文件TEMP = jfc.getSelectedFile();
                            尝试{
                                URL页面= temp.toURI()的toURL()。
                                document.setPage(页);
                            }赶上(例外五){
                                e.printStackTrace();
                            }
                        }
                    }
                });
            main.add(按钮,BorderLayout.SOUTH);            //小程序是可信的,变成红色的欢迎页面
            URL =值得信赖的新网址(getDocumentBase(),trusted.html);
            document.setPage(信任);
        }赶上(MalformedURLException的穆尔勒){
            murle.printStackTrace();
            document.setText(murle.toString());
        }赶上(IOException异常IOE){
            ioe.printStackTrace();
            document.setText(ioe.toString());
        }赶上(ACE的AccessControlException){
            ace.printStackTrace();
            //文件应该已经显示sandbox.html
        }
    }    @覆盖
    公共无效的start(){
        的System.out.println(启动());
    }    @覆盖
    公共无效停止(){
        的System.out.println(停止());
    }    @覆盖
    公共无效的destroy(){
        的System.out.println(破坏());
    }
}


解决方案

下面是 java.stderr 输出(Java控制台相当于一半 - 的另一半是 java.stdout ,里面是空的你的情况):

  net.sourceforge.jnlp.LaunchException:致命:初始化错误:无法初始化小程序。
        在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:604)
        在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:548)
        在net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:729)
net.sourceforge.jnlp.LaunchException:引起不良反应:启动错误:不罐验证。
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.checkTrustWithUser(JNLPClassLoader.java:467)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.initializeResources(JNLPClassLoader.java:410)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader&LT;&初始化GT;(JNLPClassLoader.java:168)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.getInstance(JNLPClassLoader.java:249)
        在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:575)
        ... 2个
致:
net.sourceforge.jnlp.LaunchException:致命:启动错误:不罐验证。
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.checkTrustWithUser(JNLPClassLoader.java:467)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.initializeResources(JNLPClassLoader.java:410)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader&LT;&初始化GT;(JNLPClassLoader.java:168)
        在net.sourceforge.jnlp.runtime.JNLPClassLoader.getInstance(JNLPClassLoader.java:249)
        在net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:575)
        在net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:548)
        在net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:729)
显示java.lang.NullPointerException
        在net.sourceforge.jnlp.NetxPanel.runLoader(NetxPanel.java:99)
        在sun.applet.AppletPanel.run(AppletPanel.java:380)
        在java.lang.Thread.run(Thread.java:636)
显示java.lang.NullPointerException
        在sun.applet.AppletPanel.run(AppletPanel.java:430)
        在java.lang.Thread.run(Thread.java:636)
java.lang.Exception的:小程序初始化超时
        在sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:637)
        在sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:270)
        在sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:82)
了java.lang.RuntimeException:无法处理消息:处理60822154例如2
        在sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:660)
        在sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:270)
        在sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:82)
java.lang.Exception的:引起小程序初始化超时
        在sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:637)
        ... 2个

所以,它看起来像你的applet code甚至没有加载,如果我preSS的取消的对话框。

我认为没有什么可以从Java端在这里做的 - 也许使用其他签名程序或启动小程序通过JNLP会有所帮助。或提交的IcedTea一个bug报告。


要证明这一点,我从你的小应用程序都省略关键创建一个真正简单的小程序

 包org.ps code.eg.docload;进口java.awt.FlowLayout中;
进口的javax.swing *。公共类例子扩展JApplet的{
    JLabel的标签;    公共无效的init()
    {
        的System.out.println(的init());
        SwingUtilities.invokeLater(Runnable的新(){公共无效的run(){
            标签=新的JLabel(inited。);
            的getContentPane()的setLayout(新的FlowLayout());
            。的getContentPane()加(标签);
        }});
    }    @覆盖
    公共无效的start(){
        的System.out.println(启动());
        label.setText(开始了。);
    }    @覆盖
    公共无效停止(){
        的System.out.println(停止());
        label.setText(停止);
    }    @覆盖
    公共无效的destroy(){
        的System.out.println(破坏());
        label.setText(破坏。);
    }
}

我编这一点,并修改您的HTML文件,而不是使用它,和它给完全一样的症状。

这似乎IcedTea的重新定义,当用户presses取消做什么。为了公平起见,在该对话框中的按钮是运行,取消,而不是所有权限运行和运行沙盒。

(在Sun的对话框有相同的按键,但实际上他们的意思的东西比别的问道。)

I mentioned a small demo. in Setting up policies for an Applet embedded in HTML & an Iced Tea JRE user commented that the demo. failed for them. They refused permission to the applet (thereby limiting it to the sand-box) & were supposed to see the green colored 'this applet is sand-boxed' page. Instead the applet completely failed and they saw a 'gray space' where the applet should have been.

I am WAGing that it was attempting to instantiate a File object that is the difference. I.E. The Sun/Oracle JRE will allow it without problem, only throwing a security exception when the applet attempts to create the JFileChooser. OTOH the Iced Tea JRE does not allow the File to be created.

As such, this code should fix that problem. It moves the creation/adding of the JEditorPane and installation of 1st an 'all else fails' message, then the green colored 'sand-boxed' page, to before the new File(..) call.

My question is. Does this code 'work as advertised' for users with an Iced Tea JRE?

To test it:

  1. Visit the applet at pscode.org/test/docload/applet-latest.html
  2. Refuse the digitally signed code. This is very important to create the right conditions to test the applet.
  3. Observe/report whether the applet loads the green colored sandbox.html. The sand-boxed document will represent 'success' at fixing the bug.

Also of interest (what little there might be) is the homepage for the Demo of Defensive Loading of Trusted Applets, which links to the applet page(s), each of the HTML files displayed in the applet, and a ZIP archive containing the source of the code & HTML, and an Ant build.xml so you can 'do this at home, kids'.

Here is the new code.

package org.pscode.eg.docload;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JFileChooser;

import java.net.URL;
import java.net.MalformedURLException;

import java.io.File;
import java.io.IOException;

import java.security.AccessControlException;

/** An applet to display documents that are JEditorPane compatible.
This applet loads in a defensive way in terms of the security environment,
in case the user has refused to accept the digitally signed code. */
public class DocumentLoader extends JApplet {
    JEditorPane document;

    @Override
    public void init() {
        System.out.println("init()");

        JPanel main = new JPanel();
        main.setLayout( new BorderLayout() );
        getContentPane().add(main);

        document = new JEditorPane("text/html",
            "<html><body><h1>Testing</h1><p>Testing security environment..");
        main.add( new JScrollPane(document), BorderLayout.CENTER );
        System.out.println("init(): entering 'try'");

        try {
            // set up the green 'sandboxed URL', as a precaution..
            URL sandboxed = new URL(getDocumentBase(), "sandbox.html");
            document.setPage( sandboxed );

            // It might seem odd that a sandboxed applet can /instantiate/
            // a File object, but until it goes to do anything with it, the
            // JVM considers it 'OK'.  Until we go to do anything with a
            // 'File' object, it is really just a filename.
            System.out.println("init(): instantiate file");
            File f = new File(".");
            System.out.println("init(): file instantiated, create file chooser");
            // Everything above here is possible for a sandboxed applet

            // *test* if this applet is sandboxed
            final JFileChooser jfc =
                new JFileChooser(f); // invokes security check
            jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            jfc.setMultiSelectionEnabled(false);

            System.out.println(
                "init(): file chooser created, " +
                "create/add 'Load Document' button");
            JButton button = new JButton("Load Document");
            button.addActionListener( new ActionListener(){
                    public void actionPerformed(ActionEvent ae) {
                        int result = jfc.showOpenDialog(
                            DocumentLoader.this);
                        if ( result==JFileChooser.APPROVE_OPTION ) {
                            File temp = jfc.getSelectedFile();
                            try {
                                URL page = temp.toURI().toURL();
                                document.setPage( page );
                            } catch(Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } );
            main.add( button, BorderLayout.SOUTH );

            // the applet is trusted, change to the red 'welcome page'
            URL trusted = new URL(getDocumentBase(), "trusted.html");
            document.setPage(trusted);
        } catch (MalformedURLException murle) {
            murle.printStackTrace();
            document.setText( murle.toString() );
        } catch (IOException ioe) {
            ioe.printStackTrace();
            document.setText( ioe.toString() );
        } catch (AccessControlException ace) {
            ace.printStackTrace();
            // document should already be showing sandbox.html
        }
    }

    @Override
    public void start() {
        System.out.println("start()");
    }

    @Override
    public void stop() {
        System.out.println("stop()");
    }

    @Override
    public void destroy() {
        System.out.println("destroy()");
    }
}

解决方案

Here is the output on java.stderr (one half of the equivalent of the Java console - the other half is java.stdout, which is empty in your case):

net.sourceforge.jnlp.LaunchException: Fatal: Initialization Error: Could not initialize applet.
        at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:604)
        at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:548)
        at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:729)
Caused by: net.sourceforge.jnlp.LaunchException: Fatal: Launch Error: Jars not verified.
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.checkTrustWithUser(JNLPClassLoader.java:467)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.initializeResources(JNLPClassLoader.java:410)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.<init>(JNLPClassLoader.java:168)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.getInstance(JNLPClassLoader.java:249)
        at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:575)
        ... 2 more
Caused by: 
net.sourceforge.jnlp.LaunchException: Fatal: Launch Error: Jars not verified.
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.checkTrustWithUser(JNLPClassLoader.java:467)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.initializeResources(JNLPClassLoader.java:410)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.<init>(JNLPClassLoader.java:168)
        at net.sourceforge.jnlp.runtime.JNLPClassLoader.getInstance(JNLPClassLoader.java:249)
        at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:575)
        at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:548)
        at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:729)
java.lang.NullPointerException
        at net.sourceforge.jnlp.NetxPanel.runLoader(NetxPanel.java:99)
        at sun.applet.AppletPanel.run(AppletPanel.java:380)
        at java.lang.Thread.run(Thread.java:636)
java.lang.NullPointerException
        at sun.applet.AppletPanel.run(AppletPanel.java:430)
        at java.lang.Thread.run(Thread.java:636)
java.lang.Exception: Applet initialization timeout
        at sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:637)
        at sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:270)
        at sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:82)
java.lang.RuntimeException: Failed to handle message: handle 60822154 for instance 2
        at sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:660)
        at sun.applet.PluginStreamHandler.handleMessage(PluginStreamHandler.java:270)
        at sun.applet.PluginMessageHandlerWorker.run(PluginMessageHandlerWorker.java:82)
Caused by: java.lang.Exception: Applet initialization timeout
        at sun.applet.PluginAppletViewer.handleMessage(PluginAppletViewer.java:637)
        ... 2 more

So, it looks like your applet code is not even loaded if I press Cancel in the dialog box.

I think there is nothing you can do here from the Java side - maybe using another signing procedure or starting the applet by JNLP would help. Or filing a bug report on IcedTea.


To demonstrate this, I created a real simple applet by omitting everything critical from your applet:

package org.pscode.eg.docload;

import java.awt.FlowLayout;
import javax.swing.*;

public class Example extends JApplet {


    JLabel label;

    public void init()
    {
        System.out.println("init()");
        SwingUtilities.invokeLater(new Runnable(){public void run() {
            label = new JLabel("inited.");
            getContentPane().setLayout(new FlowLayout());
            getContentPane().add(label);
        }});
    }

    @Override
    public void start() {
        System.out.println("start()");
        label.setText("started.");
    }

    @Override
    public void stop() {
        System.out.println("stop()");
        label.setText("stopped.");
    }

    @Override
    public void destroy() {
        System.out.println("destroy()");
        label.setText("destroyed.");
    }
}

I compiled this and modified your HTML file to use this instead, and it gives totally the same symptoms.

It seems IcedTea has redefined what to do when the user presses cancel. To be fair, the buttons in the dialog box are "Run" and "Cancel", not "Run with all permissions" and "Run sandboxed".

(In Sun's dialog there are the same buttons, but in effect they mean something else than asked.)

这篇关于在是否冰茶JRE这个小程序的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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