简体   繁体   English

复制/粘贴在签名的Applet中不起作用

[英]Copy/Paste not working in a signed Applet

I've a signed applet (which verifies correctly with jarsigner ) that for some reason will not allow copy and paste from the system clipboard into a JTextField despite the documentation telling me that it is supposed to work for signed applets. 我有一个签名的 applet(可以通过jarsigner正确验证),尽管文档告诉我它应该适用于签名的applet,但出于某种原因,它不允许从系统剪贴板中复制粘贴到JTextField

Furthermore, I've other applets which are signed with the same keyfile that do let me copy and paste text. 此外,我还有其他使用相同密钥文件签名的小程序,它们确实允许我复制和粘贴文本。 I have searched high and low on the internet and can't seem to find any clues. 我在互联网上搜寻高潮和低潮,似乎找不到任何线索。 What is making me pull my hair out is that there seems to be no way to debug this (no output in the console - no thrown exceptions). 使我烦恼的是,似乎没有办法调试它(控制台中没有输出-没有抛出异常)。

Does any one have any ideas on how I can debug this to find out why Java doesn't like this particular applet? 有没有人对如何调试它有任何想法,以找出为什么Java不喜欢这个特定的applet?

Many thanks for any suggestions! 非常感谢您的任何建议!

Well, it turns out with the release of the Java Plug-in 1.6.0_24 in February 2011, copy and paste from the system clipboard was deemed a security hole and disabled. 好吧,事实证明,2011年2月发布了Java Plug-in 1.6.0_24,从系统剪贴板中进行复制和粘贴被认为是安全漏洞,并且已被禁用。 You can copy and paste BETWEEN applets. 您可以在小程序之间复制和粘贴。 But if you try to use something from your main clipboard, it can't be copied in. 但是,如果您尝试使用主剪贴板中的某些内容,则无法将其复制到其中。

So there are a couple of options for a workaround. 因此,有两种解决方法。 You can roll back to an earlier version of the plug-in. 您可以回滚到该插件的早期版本。 That will work, but chances are all future releases will still keep copy and paste disabled, so you'd never be able to upgrade. 那会起作用,但是所有将来的发行版都有可能仍然禁用复制和粘贴功能,因此您将永远无法升级。

The other alternative is to provide a custom java security policy file which enables access to the system clipboard again. 另一种选择是提供一个自定义的Java安全策略文件,该文件可再次访问系统剪贴板。

First locate your local Java Security Policy file. 首先找到本地Java安全策略文件。 The file is named java.policy and should be in the lib\\security folder of your Java installation. 该文件名为java.policy,应位于Java安装的lib \\ security文件夹中。 On Windows 7, it can be found at C:\\Program Files (x86)\\Java\\jre6\\lib\\security. 在Windows 7上,可以在C:\\ Program Files(x86)\\ Java \\ jre6 \\ lib \\ security下找到它。 Copy this file to your home folder (ex. C:\\Users\\Kyle). 将此文件复制到您的主文件夹(例如C:\\ Users \\ Kyle)。 Rename the file to .java.policy (note the period at the beginning). 将文件重命名为.java.policy(注意开头的句点)。 Edit the file in a text editor. 在文本编辑器中编辑文件。 Locate this line of text: 找到以下文本行:

// "standard" properies that can be read by anyone

Add the following line just below it like so: 在其下方添加以下行,如下所示:

// "standard" properies that can be read by anyone
permission java.awt.AWTPermission "accessClipboard";

Save the file. 保存文件。 Close any open browsers and ensure that Java is not running before testing. 在测试之前,请关闭所有打开的浏览器,并确保Java没有运行。

source: http://blogs.oracle.com/kyle/entry/copy_and_paste_in_java 来源: http//blogs.oracle.com/kyle/entry/copy_and_paste_in_java

Besides Dennis' overview, see Copy in sand-boxed app. 除了Dennis的概述之外,请参见在沙盒应用程序中复制。 in 1.6.0_24+ at the OTN. OTN上为1.6.0_24 +

While Ctrl-c copy no longer works by default, it is possible to add the functionality back in for any applet run in a 'Next Generation' Java Plug-In. 尽管默认情况下Ctrl-c复制不再起作用,但是可以为“下一代” Java插件中运行的任何小程序重新添加功能。 Since Java Web Start existed, JWS provided sand-boxed copy via. 由于存在Java Web Start,因此JWS提供了沙盒复制通过。 the JNLP API's javax.jnlp.ClipboardService , & since Sun 1.6.0_10, & the next gen. JNLP API的javax.jnlp.ClipboardService ,以及从Sun 1.6.0_10起的版本,以及下一代。 plug-in, embedded applets can be deployed using JWS & can access the JNLP API. 插件,嵌入式小程序可以使用JWS进行部署,并且可以访问JNLP API。

See also 也可以看看

  • http://pscode.org/prop/js.html . http://pscode.org/prop/js.html Direct link to the test applet used in that thread. 直接链接到该线程中使用的测试applet。 It offers copy ability in a sand-boxed applet. 它在沙盒小程序中提供复制功能。 If it works on the problem machine (browser, set-up ..whatever) you should be able to rework it to offer (unprompted) paste in a signed applet. 如果它在有问题的机器(浏览器,设置..无论如何)上都可以工作,则您应该可以对其进行重新加工以提供(无提示)粘贴在签名的applet中。
  • Frame based Demo. 基于框架的演示。 of the ClipboardService , with source and build file. ClipboardService的代码 ,包括源文件和构建文件。
  1. Take a backup of java.policy which is at (Ex: C:\\Program Files (x86)\\Java\\jre7\\lib\\security ) 在(例如: C:\\Program Files (x86)\\Java\\jre7\\lib\\security )处备份java.policy

  2. Look for line in java.policy file // "standard" properies that can be read by anyone java.policy文件中查找// "standard" properies that can be read by anyone

  3. Then modify java.policy and add as below 然后修改java.policy并添加如下

// "standard" properies that can be read by anyone permission java.security.AllPermission;

I'm not sure why, but the JTextField object I'm using doesn't seem to be properly connected to the key events (maybe because I added a FocusListener?) - but adding the following code: 我不确定为什么,但是我使用的JTextField对象似乎未正确连接到关键事件(也许是因为我添加了FocusListener吗?)-但是添加了以下代码:

    searchTextField.addKeyListener(new java.awt.event.KeyListener() {
        public void keyPressed(KeyEvent e) {
            //System.out.println("KEY:"+e);
            if (e.getKeyCode() == 86 && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
                java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
                java.awt.datatransfer.Transferable clipData = clipboard.getContents(clipboard);
                String s;
                try {
                    s = (String)(clipData.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor));
                } catch (Exception ex) {
                    s = ex.toString();
                }
                searchTextField.setText(s);
            }
        }
        public void keyReleased(KeyEvent e) {
        }
        public void keyTyped(KeyEvent e) {
        }
    });

...allows me to paste into the field. ...允许我粘贴到该字段中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM