Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 这个小程序在冰茶JRE中工作吗?_Java_Security_Applet_Icedtea - Fatal编程技术网

Java 这个小程序在冰茶JRE中工作吗?

Java 这个小程序在冰茶JRE中工作吗?,java,security,applet,icedtea,Java,Security,Applet,Icedtea,我提到了一个小演示。in&一位冰茶JRE用户评论说该演示。失败 为了他们。他们拒绝了对小程序的许可(从而将其限制在沙盒中)&他们应该看到 绿色的“此小程序是沙盒”页面。相反,小程序完全失败,他们看到一个“灰色空间” 小程序应该在哪里 我敢说它试图实例化一个文件对象,这就是区别所在。即。 Sun/OracleJRE将允许它没有问题,只抛出一个安全异常 当小程序尝试创建JFileChooser时。OTOH冰茶JRE不允许 要创建的文件 因此,这段代码应该可以解决这个问题。它将移动创建/添加 JEdi

我提到了一个小演示。in&一位冰茶JRE用户评论说该演示。失败 为了他们。他们拒绝了对小程序的许可(从而将其限制在沙盒中)&他们应该看到 绿色的“此小程序是沙盒”页面。相反,小程序完全失败,他们看到一个“灰色空间” 小程序应该在哪里

我敢说它试图实例化一个
文件
对象,这就是区别所在。即。 Sun/OracleJRE将允许它没有问题,只抛出一个安全异常 当小程序尝试创建
JFileChooser
时。OTOH冰茶JRE不允许
要创建的文件

因此,这段代码应该可以解决这个问题。它将移动创建/添加
JEditorPane
和第一个 在调用
新文件(…)
之前,会出现一条“all-else fails”(其他所有操作均失败)消息,然后显示绿色的“沙盒”页面

我的问题是。对于使用冰茶JRE的用户,此代码是否“像广告中所宣传的那样有效”

要测试它,请执行以下操作:

  • 访问以下位置的小程序:
  • 拒绝数字签名代码。这对于创建正确的 测试小程序的条件。
  • 观察/报告小程序是否加载绿色 . 沙盒 文档将表示修复错误的“成功”。 同样令人感兴趣的(可能很少)是网站的主页 ,哪个链接 小程序页面、小程序中显示的每个HTML文件以及包含 代码的源代码&HTML,以及一个antbuild.xml,所以你们可以“在家里做这件事,孩子们”

    这是新代码

    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()");
        }
    }
    
    package org.pscode.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兼容的文档。
    此小程序在安全环境方面以防御方式加载,
    如果用户拒绝接受数字签名代码*/
    公共类DocumentLoader扩展了JApplet{
    绝地窗格文件;
    @凌驾
    公共void init(){
    System.out.println(“init()”);
    JPanel main=新的JPanel();
    main.setLayout(新的BorderLayout());
    getContentPane().add(主);
    document=新的文本窗格(“text/html”,
    “测试测试安全环境…”;
    添加(新的JScrollPane(文档),BorderLayout.CENTER);
    System.out.println(“init():输入'try'”;
    试一试{
    //作为预防措施,设置绿色的“沙盒URL”。。
    URL sandboxed=新URL(getDocumentBase(),“sandbox.html”);
    文件设置页(沙盒);
    //沙盒小程序可以/实例化似乎有些奇怪/
    //一个文件对象,但在它对其执行任何操作之前
    //JVM认为它“正常”。直到我们用
    //“File”对象,它实际上只是一个文件名。
    System.out.println(“init():实例化文件”);
    文件f=新文件(“.”);
    System.out.println(“init():实例化文件,创建文件选择器”);
    //对于沙盒小程序,上面的所有内容都是可能的
    //*测试*此小程序是否为沙盒
    最终JFileChooser jfc=
    新建JFileChooser(f);//调用安全检查
    jfc.setFileSelectionMode(仅限于JFileChooser.FILES_);
    jfc.setMultiSelectionEnabled(假);
    System.out.println(
    init():已创建文件选择器+
    “创建/添加‘加载文档’按钮”);
    JButton按钮=新JButton(“加载文档”);
    addActionListener(新建ActionListener()){
    已执行的公共无效行动(行动事件ae){
    int result=jfc.showOpenDialog(
    文档加载器;
    if(result==JFileChooser.APPROVE_选项){
    File temp=jfc.getSelectedFile();
    试一试{
    URL page=temp.toURI().toul();
    文件设置页(第页);
    }捕获(例外e){
    e、 printStackTrace();
    }
    }
    }
    } );
    main.add(按钮,BorderLayout.SOUTH);
    //小程序受信任,请更改为红色的“欢迎页面”
    URL trusted=新URL(getDocumentBase(),“trusted.html”);
    文件设置页(受信任);
    }捕获(格式错误){
    printStackTrace();
    document.setText(murle.toString());
    }捕获(ioe异常ioe){
    ioe.printStackTrace();
    document.setText(ioe.toString());
    }捕获(AccessControlException ace){
    ace.printStackTrace();
    //文档应该已经显示sandbox.html
    }
    }
    @凌驾
    公开作废开始(){
    System.out.println(“start()”);
    }
    @凌驾
    公共停车场(){
    System.out.println(“stop()”);
    }
    @凌驾
    公共空间销毁(){
    System.out.println(“destroy()”);
    }
    }
    
    这里是
    java.stderr
    上的输出(java控制台的一半等价物-另一半是
    java.stdout
    ,在您的例子中为空):

    我编译了这个并修改了你的HTML文件来使用它,它给出了
    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
    
    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.");
        }
    }
    
    $ java -version java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1~10.04.1) OpenJDK Client VM (build 19.0-b09, mixed mode, sharing) $ appletviewer http://pscode.org/test/docload/applet-latest.html Warning: Can't read AppletViewer properties file: … Using defaults. init() init(): entering 'try' init(): instantiate file init(): file instantiated, create file chooser java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393) at java.security.AccessController.checkPermission(AccessController.java:553) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1302) at java.lang.System.getProperty(System.java:669) at javax.swing.filechooser.FileSystemView.getHomeDirectory(FileSystemView.java:397) at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(MetalFileChooserUI.java:282) at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:153) at javax.swing.plaf.metal.MetalFileChooserUI.installUI(MetalFileChooserUI.java:155) at javax.swing.JComponent.setUI(JComponent.java:651) at javax.swing.JFileChooser.updateUI(JFileChooser.java:1781) at javax.swing.JFileChooser.setup(JFileChooser.java:374) at javax.swing.JFileChooser.(JFileChooser.java:347) at javax.swing.JFileChooser.(JFileChooser.java:330) at org.pscode.eg.docload.DocumentLoader.init(DocumentLoader.java:57) at sun.applet.AppletPanel.run(AppletPanel.java:436) at java.lang.Thread.run(Thread.java:636) start() stop() destroy() $ java -version java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-9M3326) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode) $ appletviewer http://pscode.org/test/docload/applet-latest.html init() init(): entering 'try' init(): instantiate file init(): file instantiated, create file chooser java.security.AccessControlException: access denied (java.io.FilePermission . read) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374) at java.security.AccessController.checkPermission(AccessController.java:546) at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) at java.lang.SecurityManager.checkRead(SecurityManager.java:871) at java.io.File.exists(File.java:731) at javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:548) at javax.swing.JFileChooser.(JFileChooser.java:334) at javax.swing.JFileChooser.(JFileChooser.java:316) at org.pscode.eg.docload.DocumentLoader.init(DocumentLoader.java:57) at sun.applet.AppletPanel.run(AppletPanel.java:424) at java.lang.Thread.run(Thread.java:680) start() stop() destroy()