gpt4 book ai didi

java - 这个小程序在 Iced Tea JRE 中工作吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:22 29 4
gpt4 key购买 nike

我提到了一个小演示。在 Setting up policies for an Applet embedded in HTML & 一位 Iced Tea JRE 用户评论说该演示。失败的为他们。他们拒绝小程序的许可(从而将其限制在沙盒中)并且应该看到绿色的“这个小程序是沙盒”页面。相反,小程序完全失败,他们看到了一个“灰色空间”小程序应该在的位置。

我正在等待它试图实例化一个 File 对象,这是不同之处。 IE。Sun/Oracle JRE 将毫无问题地允许它,只会抛出一个安全异常当小程序尝试创建 JFileChooser 时。 OTOH 冰茶 JRE 不允许要创建的文件

因此,这段代码应该可以解决这个问题。它移动了创建/添加JEditorPane 和第一个的安装在 new File(..) 调用之前显示“其他所有方法均失败”消息,然后是绿色的“沙盒”页面。

我的问题是。对于使用 Iced Tea JRE 的用户,此代码是否“像宣传的那样工作”?

测试它:

  1. 访问小程序 pscode.org/test/docload/applet-latest.html
  2. 拒绝数字签名代码。这对创建正确的代码非常重要测试小程序的条件。
  3. 观察/报告小程序是否加载绿色 sandbox.html .沙盒文档将代表修复错误的“成功”。

同样令人感兴趣的(可能很少)是 Demo of Defensive Loading of Trusted Applets , 哪个链接到小程序页面,小程序中显示的每个 HTML 文件,以及包含代码和 HTML 的源代码,以及一个 Ant build.xml,这样您就可以“在家做, children ”。

这是新代码。

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()");
}
}

最佳答案

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

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

所以,如果我在对话框中按取消,看起来您的小程序代码甚至都没有加载。

confirmation dialog

我认为从 Java 方面您无能为力 - 也许使用其他签名过程或通过 JNLP 启动小程序会有所帮助。或者在 IcedTea 上提交错误报告。


为了证明这一点,我创建了一个真正简单的小程序,方法是从您的小程序中省略所有关键内容:

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.");
}
}

我编译了它并修改了您的 HTML 文件以改为使用它,它给出了完全相同的症状。

IcedTea 似乎重新定义了当用户按下取消键时要执行的操作。公平地说,对话框中的按钮是“运行”和“取消”,而不是“以所有权限运行”和“沙盒运行”。

(在 Sun 的对话框中有相同的按钮,但实际上它们的意思不同于询问。)

关于java - 这个小程序在 Iced Tea JRE 中工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5356850/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com