JDK-8133103 : JavaFX Clipboard should not require AllPermission
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u51
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_8
  • CPU: x86
  • Submitted: 2015-08-05
  • Updated: 2020-01-31
  • Resolved: 2015-10-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u72Fixed 9Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7/8, MacOS X 10, Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
Java 8 update 51

A DESCRIPTION OF THE PROBLEM :
Technical information:

The problem is related to class javafx.scene.input.Clipboard. The Method getSystemClipboard() contains request for all permissions and does not work without them. It's a bug - code should ask for "accessClipboard".

Unfortunately, SAP code is not involved and we are not able to write workaround in our code to prevent this issue. Oracle's team should fix it inside the JavaFX class.


Source code for related class:
package javafx.scene.input;


...
    /**
     * Gets the current system clipboard, through which data can be stored and
     * retrieved. There is ever only one system clipboard for a JavaFX application.
     * @return The single system clipboard, used for cut / copy / paste operations
     */
    public static Clipboard getSystemClipboard() {
        try {
            final SecurityManager securityManager = System.getSecurityManager();
            if (securityManager != null) {
-->                securityManager.checkPermission(new AllPermission());
            }
            return getSystemClipboardImpl();
        } catch (final SecurityException e) {
            return getLocalClipboardImpl();
        }
    }
.....

Stacktrace for call
Daemon System Thread [JavaFX Application Thread] (Suspended (entry into method <init> in AllPermission))            
            AllPermission.<init>() line: 66 [local variables unavailable] 
            Clipboard.getSystemClipboard() line: 173    
            PasteboardImpl.<init>() line: 38        
            UtilitiesImpl.createPasteboard() line: 39       
            WCPasteboard.<clinit>() line: 43      
            WebPage.twkProcessKeyEvent(long, int, String, String, int, boolean, boolean, boolean, boolean) line: not available [native method]       
            WebPage.dispatchKeyEvent(WCKeyEvent) line: 737        
            WebView.processKeyEvent(KeyEvent) line: 1062  
            WebView.lambda$registerEventHandlers$31(KeyEvent) line: 1140                     
            453037847.handle(Event) line: not available            
            CompositeEventHandler$NormalEventHandlerRecord<T>.handleBubblingEvent(T) line: 218   
            CompositeEventHandler<T>.dispatchBubblingEvent(Event) line: 80        
            EventHandlerManager.dispatchBubblingEvent(EventType<Event>, Event) line: 238      
            EventHandlerManager.dispatchBubblingEvent(Event) line: 191    
            NodeEventDispatcher(CompositeEventDispatcher).dispatchBubblingEvent(Event) line: 59       
            NodeEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 58       
            EventDispatchChainImpl.dispatchEvent(Event) line: 114   
            SceneEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 56      
            EventDispatchChainImpl.dispatchEvent(Event) line: 114   
            WindowEventDispatcher(BasicEventDispatcher).dispatchEvent(Event, EventDispatchChain) line: 56  
            EventDispatchChainImpl.dispatchEvent(Event) line: 114   
            EventUtil.fireEventImpl(EventDispatchChain, EventTarget, Event) line: 74        
            EventUtil.fireEvent(EventTarget, Event) line: 54    
            Event.fireEvent(EventTarget, Event) line: 198        
            Scene$KeyHandler.process(KeyEvent) line: 3965   
            Scene$KeyHandler.access$1800(Scene$KeyHandler, KeyEvent) line: 3911        
            Scene.impl_processKeyEvent(KeyEvent) line: 2040           
            Scene$ScenePeerListener.keyEvent(KeyEvent) line: 2502 
            EmbeddedScene.lambda$null$297(int, char[], int, int) line: 305     
            1430468791.run() line: not available 
            AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]          
            EmbeddedScene.lambda$keyEvent$298(int, char[], int, int) line: 291       
            438625584.run() line: not available   
            PlatformImpl.lambda$null$170(Runnable) line: 295           
            1760710214.run() line: not available 
            AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]          
            PlatformImpl.lambda$runLater$171(Runnable, AccessControlContext) line: 294            
            770953327.run() line: not available   
            InvokeLaterDispatcher$Future.run() line: 95 [local variables unavailable]  


REGRESSION.  Last worked in version 8u51

ADDITIONAL REGRESSION INFORMATION: 
Lets check the getSystemClipboard() method in XToolkit class:

    public  Clipboard getSystemClipboard() {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
        }
        synchronized (this) {
            if (clipboard == null) {
                clipboard = new XClipboard("System", "CLIPBOARD");
            }
        }
        return clipboard;
    }


***
As You can see XToolkit is checking for
security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Any test application with Swing JFrame + JFXPanel + FX inputField.

Important is initialize SecurityManager without AllPermissions!

try to copy/paste application from
https://javafx-jira.kenai.com/browse/RT-38922

but You need to add your own SecurityManager

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Correction in JavaFX Clipboard class

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
try to copy/paste application from
https://javafx-jira.kenai.com/browse/RT-38922

but You need to add your own SecurityManager
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Provide AllPermissions for your application.

SUPPORT :
YES


Comments
http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/dfed384250ec
09-10-2015

+1
09-10-2015

I tested this with the attached test program and policy file.
08-10-2015

http://cr.openjdk.java.net/~kcr/8133103/webrev.00/ The fix is as described above, to use AWTPermission("accessClipBoard") in FX when validating permissions for clipboard and dragboard operations, rather than requiring AllPermission. The same patch applies cleanly for 9-dev and 8u-dev.
08-10-2015

The proposed fix is to use AWTPermission("accessClipBoard") in FX when validating permissions for clipboard and dragboard operations, rather than requiring AllPermission. In order to avoid a hard dependency on AWT we will need to eventually define FX fine-grained permissions (to implement JDK-8091308) and then check the AWT permission using reflection if the check for the FX-specific permission fails.
08-10-2015

Attached test program with policy file that reproduces the bug. You can run it as follows: java -Djava.security.manager -Djava.security.policy=clipboard.policy ClipboardBug The AWT text field can copy/paste to/from the system clipboard. The JavaFX text field cannot.
08-10-2015

As this is working as designed changing this request from Bug to Enhancement.
10-09-2015

Note that there is a long-standing RFE to define fine-grained permissions for JavaFX, JDK-8091308. That would only be done for a major release, so if a fix is needed sooner, we might need a targeted fix for just this clipboard issue.
09-09-2015

I'm raising it back to P3 since it is a regression and the workaround may not be acceptable for some applications.
09-09-2015

This was the result of an intentional change, and is consistent with all other permissions in JavaFX. We might consider using specific permissions, although not likely AWT-specific permissions. Lowering to P4 since this is working as intended and there is a workaround.
08-08-2015