You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Vasily Zakharov (JIRA)" <ji...@apache.org> on 2007/03/23 18:33:32 UTC
[jira] Commented: (HARMONY-3479) [classlib][swing][netbeans]
TransferHandler.getPasteAction().actionPerformed() doesn't check if
accessClipboard is allowed
[ https://issues.apache.org/jira/browse/HARMONY-3479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12483667 ]
Vasily Zakharov commented on HARMONY-3479:
------------------------------------------
The problem is really more complex than I thought.
Here's the updated test, that actually throws SecurityException, like org.netbeans.TopSecurityManager does:
import java.awt.AWTPermission;
import java.awt.event.ActionEvent;
import java.security.Permission;
import javax.swing.Action;
import javax.swing.JPanel;
import javax.swing.TransferHandler;
public class Test {
private static boolean flag = false;
public static void main(String args[]) throws Exception {
System.setSecurityManager(new TestSecurityManager());
Action action = TransferHandler.getPasteAction();
ActionEvent event = new ActionEvent(new JPanel(), 0, "");
System.out.println("Before");
action.actionPerformed(event);
System.out.println("After");
System.out.println(flag ? "SUCCESS" : "FAIL");
}
private static class TestSecurityManager extends SecurityManager {
public void checkPermission(Permission perm) {
if ((perm instanceof AWTPermission)
&& "accessClipboard".equals(perm.getName())) {
flag = true;
new Throwable().printStackTrace();
throw new SecurityException("test");
}
}
}
}
Output on RI:
Before
java.lang.Throwable
at Test$TestSecurityManager.checkPermission(Test.java:27)
at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown Source)
at com.sun.java.swing.SwingUtilities2.canAccessSystemClipboard(Unknown Source)
at javax.swing.TransferHandler$TransferAction.getClipboard(Unknown Source)
at javax.swing.TransferHandler$TransferAction.actionPerformed(Unknown Source)
at Test.main(Test.java:17)
After
SUCCESS
Output on Harmony (after TransferHandler is patched):
Before
java.lang.Throwable
at Test$TestSecurityManager.checkPermission(Test.java:27)
at java.lang.SecurityManager.checkSystemClipboardAccess(SecurityManager.java:472)
at java.awt.ToolkitImpl.getSystemClipboard(ToolkitImpl.java:467)
at javax.swing.TransferHandler.getSystemClipboard(TransferHandler.java:155)
at javax.swing.TransferHandler.access$1(TransferHandler.java:154)
at javax.swing.TransferHandler$3.actionPerformed(TransferHandler.java:88)
at Test.main(Test.java:17)
Exception in thread "main" java.lang.SecurityException: test
at Test$TestSecurityManager.checkPermission(Test.java:28)
at java.lang.SecurityManager.checkSystemClipboardAccess(SecurityManager.java:472)
at java.awt.ToolkitImpl.getSystemClipboard(ToolkitImpl.java:467)
at javax.swing.TransferHandler.getSystemClipboard(TransferHandler.java:155)
at javax.swing.TransferHandler.access$1(TransferHandler.java:154)
at javax.swing.TransferHandler$3.actionPerformed(TransferHandler.java:88)
at Test.main(Test.java:17)
You see, TransferHandler is actually working, however RI clearly catches the SecurityException somewhere (my guess is com.sun.java.swing.SwingUtilities2.canAccessSystemClipboard() is doing that, judging by its name), and we probably need to do something like that.
I'm going to update the patch to TransferHandler.
> [classlib][swing][netbeans] TransferHandler.getPasteAction().actionPerformed() doesn't check if accessClipboard is allowed
> --------------------------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3479
> URL: https://issues.apache.org/jira/browse/HARMONY-3479
> Project: Harmony
> Issue Type: Bug
> Components: App-Oriented Bug Reports, Classlib
> Reporter: Vasily Zakharov
>
> Consider the following test:
> import java.awt.AWTPermission;
> import java.awt.event.ActionEvent;
> import java.security.Permission;
> import javax.swing.Action;
> import javax.swing.JPanel;
> import javax.swing.TransferHandler;
> public class Test {
> private static boolean flag = false;
> public static void main(String args[]) throws Exception {
> System.setSecurityManager(new TestSecurityManager());
> Action action = TransferHandler.getPasteAction();
> ActionEvent event = new ActionEvent(new JPanel(), 0, "");
> System.out.println("Before");
> action.actionPerformed(event);
> System.out.println("After");
> System.out.println(flag ? "SUCCESS" : "FAIL");
> }
> private static class TestSecurityManager extends SecurityManager {
> public void checkPermission(Permission perm) {
> if ((perm instanceof AWTPermission)
> && "accessClipboard".equals(perm.getName())) {
> flag = true;
> new Throwable().printStackTrace();
> }
> }
> }
> }
> I inserted stack printing to see the stack of calls that leads to security check on RI.
> Output on RI:
> Before
> java.lang.Throwable
> at Test$TestSecurityManager.checkPermission(Test.java:27)
> at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown Source)
> at com.sun.java.swing.SwingUtilities2.canAccessSystemClipboard(Unknown Source)
> at javax.swing.TransferHandler$TransferAction.getClipboard(Unknown Source)
> at javax.swing.TransferHandler$TransferAction.actionPerformed(Unknown Source)
> at Test.main(Test.java:17)
> java.lang.Throwable
> at Test$TestSecurityManager.checkPermission(Test.java:27)
> at java.lang.SecurityManager.checkSystemClipboardAccess(Unknown Source)
> at sun.awt.windows.WToolkit.getSystemClipboard(Unknown Source)
> at javax.swing.TransferHandler$TransferAction.getClipboard(Unknown Source)
> at javax.swing.TransferHandler$TransferAction.actionPerformed(Unknown Source)
> at Test.main(Test.java:17)
> After
> SUCCESS
> Output on Harmony:
> Before
> After
> FAIL
> The same problem also occurs for getCopyAction() and getCutAction(), probably this is the same problem.
> At first look it seems to be a Swing problem, but my guess is the actual problem really lays in the AWT layer.
> This issue was discovered while trying to run Netbeans on Harmony.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.