Skip to content

Commit 4d898aa

Browse files
committed
8344896: Remove obsolete checks for AWTPermission accessClipboard
Reviewed-by: azvegint
1 parent 08dfc4a commit 4d898aa

File tree

11 files changed

+10
-280
lines changed

11 files changed

+10
-280
lines changed

src/java.desktop/macosx/classes/sun/lwawt/LWToolkit.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,6 @@ public final PrintJob getPrintJob(Frame frame, String doctitle,
407407

408408
@Override
409409
public final Clipboard getSystemClipboard() {
410-
@SuppressWarnings("removal")
411-
SecurityManager security = System.getSecurityManager();
412-
if (security != null) {
413-
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
414-
}
415-
416410
synchronized (this) {
417411
if (clipboard == null) {
418412
clipboard = createPlatformClipboard();

src/java.desktop/share/classes/java/awt/TextComponent.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import javax.accessibility.AccessibleText;
4545
import javax.swing.text.AttributeSet;
4646

47-
import sun.awt.AWTPermissions;
4847
import sun.awt.InputMethodSupport;
4948

5049
/**
@@ -744,20 +743,6 @@ protected String paramString() {
744743
return str + ",selection=" + getSelectionStart() + "-" + getSelectionEnd();
745744
}
746745

747-
/**
748-
* Assigns a valid value to the canAccessClipboard instance variable.
749-
*/
750-
private boolean canAccessClipboard() {
751-
@SuppressWarnings("removal")
752-
SecurityManager sm = System.getSecurityManager();
753-
if (sm == null) return true;
754-
try {
755-
sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
756-
return true;
757-
} catch (SecurityException e) {}
758-
return false;
759-
}
760-
761746
/*
762747
* Serialization support.
763748
*/

src/java.desktop/share/classes/java/awt/event/InputEvent.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Arrays;
3434

3535
import sun.awt.AWTAccessor;
36-
import sun.awt.AWTPermissions;
3736
import sun.util.logging.PlatformLogger;
3837

3938
/**
@@ -313,6 +312,7 @@ public static int getMaskForButton(int button) {
313312
/*
314313
* A flag that indicates that this instance can be used to access
315314
* the system clipboard.
315+
* This should be false in a headless environment, true in a headful one.
316316
*/
317317
private transient boolean canAccessSystemClipboard;
318318

@@ -385,26 +385,7 @@ public void setCanAccessSystemClipboard(InputEvent event,
385385
}
386386

387387
private boolean canAccessSystemClipboard() {
388-
boolean b = false;
389-
390-
if (!GraphicsEnvironment.isHeadless()) {
391-
@SuppressWarnings("removal")
392-
SecurityManager sm = System.getSecurityManager();
393-
if (sm != null) {
394-
try {
395-
sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
396-
b = true;
397-
} catch (SecurityException se) {
398-
if (logger.isLoggable(PlatformLogger.Level.FINE)) {
399-
logger.fine("InputEvent.canAccessSystemClipboard() got SecurityException ", se);
400-
}
401-
}
402-
} else {
403-
b = true;
404-
}
405-
}
406-
407-
return b;
388+
return !GraphicsEnvironment.isHeadless();
408389
}
409390

410391
/**

src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,10 @@ public void mouseClicked(MouseEvent e) {
467467
// mouse 1 behavior
468468
if(nclicks == 1) {
469469
selectedWordEvent = null;
470-
} else if(nclicks == 2
471-
&& SwingUtilities2.canEventAccessSystemClipboard(e)) {
470+
} else if (nclicks == 2) {
472471
selectWord(e);
473472
selectedWordEvent = null;
474-
} else if(nclicks == 3
475-
&& SwingUtilities2.canEventAccessSystemClipboard(e)) {
473+
} else if (nclicks == 3) {
476474
Action a = null;
477475
ActionMap map = getComponent().getActionMap();
478476
if (map != null) {
@@ -489,8 +487,7 @@ public void mouseClicked(MouseEvent e) {
489487
}
490488
} else if (SwingUtilities.isMiddleMouseButton(e)) {
491489
// mouse 2 behavior
492-
if (nclicks == 1 && component.isEditable() && component.isEnabled()
493-
&& SwingUtilities2.canEventAccessSystemClipboard(e)) {
490+
if (nclicks == 1 && component.isEditable() && component.isEnabled()) {
494491
// paste system selection, if it exists
495492
JTextComponent c = (JTextComponent) e.getSource();
496493
if (c != null) {
@@ -547,8 +544,7 @@ public void mousePressed(MouseEvent e) {
547544
} else {
548545
shouldHandleRelease = false;
549546
adjustCaretAndFocus(e);
550-
if (nclicks == 2
551-
&& SwingUtilities2.canEventAccessSystemClipboard(e)) {
547+
if (nclicks == 2) {
552548
selectWord(e);
553549
}
554550
}
@@ -1394,9 +1390,6 @@ void repaintNewCaret() {
13941390
}
13951391

13961392
private void updateSystemSelection() {
1397-
if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
1398-
return;
1399-
}
14001393
if (this.dot != this.mark && component != null && component.hasFocus()) {
14011394
Clipboard clip = getSystemSelection();
14021395
if (clip != null) {

src/java.desktop/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,6 @@ public Object getTransferData(DataFlavor df)
224224
InvalidDnDOperationException
225225
{
226226

227-
@SuppressWarnings("removal")
228-
SecurityManager sm = System.getSecurityManager();
229-
try {
230-
if (!dropInProcess && sm != null) {
231-
sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
232-
}
233-
} catch (Exception e) {
234-
Thread currentThread = Thread.currentThread();
235-
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
236-
return null;
237-
}
238-
239227
Long lFormat = null;
240228
Transferable localTransferable = local;
241229

src/java.desktop/share/classes/sun/swing/SwingUtilities2.java

Lines changed: 3 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ public static void putAATextInfo(boolean lafCondition,
189189
public static final StringUIClientPropertyKey BASICMENUITEMUI_MAX_TEXT_OFFSET =
190190
new StringUIClientPropertyKey ("maxTextOffset");
191191

192-
// security stuff
193-
private static final String UntrustedClipboardAccess =
194-
"UNTRUSTED_CLIPBOARD_ACCESS_KEY";
195-
196192
//all access to charsBuffer is to be synchronized on charsBufferLock
197193
private static final int CHAR_BUFFER_SIZE = 100;
198194
private static final Object charsBufferLock = new Object();
@@ -1458,123 +1454,14 @@ public int hashCode() {
14581454
}
14591455
}
14601456

1461-
/*
1462-
* here goes the fix for 4856343 [Problem with applet interaction
1463-
* with system selection clipboard]
1464-
*
1465-
* NOTE. In case isTrustedContext() no checking
1466-
* are to be performed
1467-
*/
1468-
14691457
/**
1470-
* checks the security permissions for accessing system clipboard
1471-
*
1472-
* for untrusted context (see isTrustedContext) checks the
1473-
* permissions for the current event being handled
1458+
* checks if the system clipboard can be accessed.
1459+
* This is true in a headful environment, false in a headless one
14741460
*
14751461
*/
14761462
public static boolean canAccessSystemClipboard() {
1477-
boolean canAccess = false;
1478-
if (!GraphicsEnvironment.isHeadless()) {
1479-
@SuppressWarnings("removal")
1480-
SecurityManager sm = System.getSecurityManager();
1481-
if (sm == null) {
1482-
canAccess = true;
1483-
} else {
1484-
try {
1485-
sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1486-
canAccess = true;
1487-
} catch (SecurityException e) {
1488-
}
1489-
if (canAccess && ! isTrustedContext()) {
1490-
canAccess = canCurrentEventAccessSystemClipboard(true);
1491-
}
1492-
}
1493-
}
1494-
return canAccess;
1463+
return !GraphicsEnvironment.isHeadless();
14951464
}
1496-
/**
1497-
* Returns true if EventQueue.getCurrentEvent() has the permissions to
1498-
* access the system clipboard
1499-
*/
1500-
public static boolean canCurrentEventAccessSystemClipboard() {
1501-
return isTrustedContext()
1502-
|| canCurrentEventAccessSystemClipboard(false);
1503-
}
1504-
1505-
/**
1506-
* Returns true if the given event has permissions to access the
1507-
* system clipboard
1508-
*
1509-
* @param e AWTEvent to check
1510-
*/
1511-
public static boolean canEventAccessSystemClipboard(AWTEvent e) {
1512-
return isTrustedContext()
1513-
|| canEventAccessSystemClipboard(e, false);
1514-
}
1515-
1516-
/**
1517-
* Returns true if the given event is current gesture for
1518-
* accessing clipboard
1519-
*
1520-
* @param ie InputEvent to check
1521-
*/
1522-
@SuppressWarnings("deprecation")
1523-
private static boolean isAccessClipboardGesture(InputEvent ie) {
1524-
boolean allowedGesture = false;
1525-
if (ie instanceof KeyEvent) { //we can validate only keyboard gestures
1526-
KeyEvent ke = (KeyEvent)ie;
1527-
int keyCode = ke.getKeyCode();
1528-
int keyModifiers = ke.getModifiers();
1529-
switch(keyCode) {
1530-
case KeyEvent.VK_C:
1531-
case KeyEvent.VK_V:
1532-
case KeyEvent.VK_X:
1533-
allowedGesture = (keyModifiers == InputEvent.CTRL_MASK);
1534-
break;
1535-
case KeyEvent.VK_INSERT:
1536-
allowedGesture = (keyModifiers == InputEvent.CTRL_MASK ||
1537-
keyModifiers == InputEvent.SHIFT_MASK);
1538-
break;
1539-
case KeyEvent.VK_COPY:
1540-
case KeyEvent.VK_PASTE:
1541-
case KeyEvent.VK_CUT:
1542-
allowedGesture = true;
1543-
break;
1544-
case KeyEvent.VK_DELETE:
1545-
allowedGesture = ( keyModifiers == InputEvent.SHIFT_MASK);
1546-
break;
1547-
}
1548-
}
1549-
return allowedGesture;
1550-
}
1551-
1552-
/**
1553-
* Returns true if e has the permissions to
1554-
* access the system clipboard and if it is allowed gesture (if
1555-
* checkGesture is true)
1556-
*
1557-
* @param e AWTEvent to check
1558-
* @param checkGesture boolean
1559-
*/
1560-
private static boolean canEventAccessSystemClipboard(AWTEvent e,
1561-
boolean checkGesture) {
1562-
if (EventQueue.isDispatchThread()) {
1563-
/*
1564-
* Checking event permissions makes sense only for event
1565-
* dispatching thread
1566-
*/
1567-
if (e instanceof InputEvent
1568-
&& (! checkGesture || isAccessClipboardGesture((InputEvent)e))) {
1569-
return AWTAccessor.getInputEventAccessor().
1570-
canAccessSystemClipboard((InputEvent) e);
1571-
} else {
1572-
return false;
1573-
}
1574-
} else {
1575-
return true;
1576-
}
1577-
}
15781465

15791466
/**
15801467
* Utility method that throws SecurityException if SecurityManager is set
@@ -1590,31 +1477,6 @@ public static void checkAccess(int modifiers) {
15901477
}
15911478
}
15921479

1593-
/**
1594-
* Returns true if EventQueue.getCurrentEvent() has the permissions to
1595-
* access the system clipboard and if it is allowed gesture (if
1596-
* checkGesture true)
1597-
*
1598-
* @param checkGesture boolean
1599-
*/
1600-
private static boolean canCurrentEventAccessSystemClipboard(boolean
1601-
checkGesture) {
1602-
AWTEvent event = EventQueue.getCurrentEvent();
1603-
return canEventAccessSystemClipboard(event, checkGesture);
1604-
}
1605-
1606-
/**
1607-
* see RFE 5012841 [Per AppContect security permissions] for the
1608-
* details
1609-
*
1610-
*/
1611-
@SuppressWarnings("removal")
1612-
private static boolean isTrustedContext() {
1613-
return (System.getSecurityManager() == null)
1614-
|| (AppContext.getAppContext().
1615-
get(UntrustedClipboardAccess) == null);
1616-
}
1617-
16181480
public static String displayPropertiesToCSS(Font font, Color fg) {
16191481
StringBuilder rule = new StringBuilder("body {");
16201482
if (font != null) {

src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
import java.util.ArrayList;
115115
import java.util.Collection;
116116
import java.util.HashMap;
117-
import java.util.Hashtable;
118117
import java.util.Iterator;
119118
import java.util.LinkedList;
120119
import java.util.Map;
@@ -129,7 +128,6 @@
129128
import javax.swing.UIDefaults;
130129

131130
import sun.awt.AWTAccessor;
132-
import sun.awt.AWTPermissions;
133131
import sun.awt.AppContext;
134132
import sun.awt.DisplayChangedListener;
135133
import sun.awt.LightweightFrame;
@@ -1233,11 +1231,6 @@ public boolean getLockingKeyState(int key) {
12331231

12341232
@Override
12351233
public Clipboard getSystemClipboard() {
1236-
@SuppressWarnings("removal")
1237-
SecurityManager security = System.getSecurityManager();
1238-
if (security != null) {
1239-
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1240-
}
12411234
synchronized (this) {
12421235
if (clipboard == null) {
12431236
clipboard = new XClipboard("System", "CLIPBOARD");
@@ -1248,11 +1241,6 @@ public Clipboard getSystemClipboard() {
12481241

12491242
@Override
12501243
public Clipboard getSystemSelection() {
1251-
@SuppressWarnings("removal")
1252-
SecurityManager security = System.getSecurityManager();
1253-
if (security != null) {
1254-
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
1255-
}
12561244
synchronized (this) {
12571245
if (selection == null) {
12581246
selection = new XClipboard("Selection", "PRIMARY");

src/java.desktop/windows/classes/sun/awt/windows/WTextComponentPeer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
abstract
3333
class WTextComponentPeer extends WComponentPeer implements TextComponentPeer {
3434

35-
static {
36-
initIDs();
37-
}
38-
3935
// TextComponentPeer implementation
4036

4137
@Override
@@ -107,11 +103,6 @@ public void valueChanged() {
107103
postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
108104
}
109105

110-
/**
111-
* Initialize JNI field and method IDs
112-
*/
113-
private static native void initIDs();
114-
115106
@Override
116107
public boolean shouldClearRectBeforePaint() {
117108
return false;

0 commit comments

Comments
 (0)