Copy/Paste not working in a signed Applet

前端 未结 4 1274
予麋鹿
予麋鹿 2020-12-03 15:43

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

相关标签:
4条回答
  • 2020-12-03 16:24

    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. 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.

    First locate your local Java Security Policy file. The file is named java.policy and should be in the lib\security folder of your Java installation. On Windows 7, it can be found at C:\Program Files (x86)\Java\jre6\lib\security. Copy this file to your home folder (ex. C:\Users\Kyle). Rename the file to .java.policy (note the period at the beginning). 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.

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

    0 讨论(0)
  • 2020-12-03 16:24

    Besides Dennis' overview, see Copy in sand-boxed app. in 1.6.0_24+ at the OTN.

    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. Since Java Web Start existed, JWS provided sand-boxed copy via. the JNLP API's javax.jnlp.ClipboardService, & since Sun 1.6.0_10, & the next gen. plug-in, embedded applets can be deployed using JWS & can access the JNLP API.

    See also

    • http://pscode.org/prop/js.html. Direct link to the test applet used in that thread. 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.
    • Frame based Demo. of the ClipboardService, with source and build file.
    0 讨论(0)
  • 2020-12-03 16:29
    1. Take a backup of java.policy which is at (Ex: C:\Program Files (x86)\Java\jre7\lib\security)

    2. Look for line in java.policy file // "standard" properies that can be read by anyone

    3. Then modify java.policy and add as below

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

    0 讨论(0)
  • 2020-12-03 16:43

    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:

        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.

    0 讨论(0)
提交回复
热议问题