6854954: Eliminate static dependency on java.awt.AWTPermission
Reviewed-by: mullan, mchung, anthony
This commit is contained in:
parent
936d0362c2
commit
2170e604da
@ -856,7 +856,7 @@ public class Dialog extends Window {
|
||||
if (type == ModalityType.TOOLKIT_MODAL) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION);
|
||||
sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
|
||||
}
|
||||
}
|
||||
modalityType = type;
|
||||
|
@ -76,7 +76,7 @@ public class MouseInfo {
|
||||
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.WATCH_MOUSE_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.WATCH_MOUSE_PERMISSION);
|
||||
}
|
||||
|
||||
Point point = new Point(0, 0);
|
||||
|
@ -167,7 +167,7 @@ public class Robot {
|
||||
private void checkRobotAllowed() {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.CREATE_ROBOT_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.CREATE_ROBOT_PERMISSION);
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ public class Robot {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(
|
||||
SecurityConstants.READ_DISPLAY_PIXELS_PERMISSION);
|
||||
SecurityConstants.AWT.READ_DISPLAY_PIXELS_PERMISSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,7 +490,7 @@ public class SystemTray {
|
||||
static void checkSystemTrayAllowed() {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.ACCESS_SYSTEM_TRAY_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.ACCESS_SYSTEM_TRAY_PERMISSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2025,7 +2025,7 @@ public abstract class Toolkit {
|
||||
}
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
|
||||
}
|
||||
synchronized (this) {
|
||||
SelectiveAWTEventListener selectiveListener =
|
||||
@ -2094,7 +2094,7 @@ public abstract class Toolkit {
|
||||
}
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
@ -2165,7 +2165,7 @@ public abstract class Toolkit {
|
||||
public AWTEventListener[] getAWTEventListeners() {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
|
||||
}
|
||||
synchronized (this) {
|
||||
EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
|
||||
@ -2217,7 +2217,7 @@ public abstract class Toolkit {
|
||||
public AWTEventListener[] getAWTEventListeners(long eventMask) {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
|
||||
}
|
||||
synchronized (this) {
|
||||
EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
|
||||
|
@ -1581,7 +1581,7 @@ public class Window extends Container implements Accessible {
|
||||
if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION);
|
||||
sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
|
||||
}
|
||||
}
|
||||
modalExclusionType = exclusionType;
|
||||
@ -2129,7 +2129,7 @@ public class Window extends Container implements Accessible {
|
||||
public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
security.checkPermission(SecurityConstants.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
|
||||
security.checkPermission(SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
|
||||
}
|
||||
|
||||
boolean oldAlwaysOnTop;
|
||||
|
@ -1341,7 +1341,7 @@ class SecurityManager {
|
||||
throw new NullPointerException("window can't be null");
|
||||
}
|
||||
try {
|
||||
checkPermission(SecurityConstants.TOPLEVEL_WINDOW_PERMISSION);
|
||||
checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION);
|
||||
return true;
|
||||
} catch (SecurityException se) {
|
||||
// just return false
|
||||
@ -1391,7 +1391,7 @@ class SecurityManager {
|
||||
* @see #checkPermission(java.security.Permission) checkPermission
|
||||
*/
|
||||
public void checkSystemClipboardAccess() {
|
||||
checkPermission(SecurityConstants.ACCESS_CLIPBOARD_PERMISSION);
|
||||
checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1412,7 +1412,7 @@ class SecurityManager {
|
||||
* @see #checkPermission(java.security.Permission) checkPermission
|
||||
*/
|
||||
public void checkAwtEventQueueAccess() {
|
||||
checkPermission(SecurityConstants.CHECK_AWT_EVENTQUEUE_PERMISSION);
|
||||
checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -412,7 +412,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(
|
||||
SecurityConstants.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
|
||||
SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
|
||||
}
|
||||
} catch (SecurityException se) {
|
||||
// There is no permission to show popups over the task bar
|
||||
|
42
jdk/src/share/classes/sun/awt/AWTPermissionFactory.java
Normal file
42
jdk/src/share/classes/sun/awt/AWTPermissionFactory.java
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package sun.awt;
|
||||
|
||||
import java.awt.AWTPermission;
|
||||
import sun.security.util.PermissionFactory;
|
||||
|
||||
/**
|
||||
* A factory object for AWTPermission objects.
|
||||
*/
|
||||
|
||||
public class AWTPermissionFactory
|
||||
implements PermissionFactory<AWTPermission>
|
||||
{
|
||||
@Override
|
||||
public AWTPermission newPermission(String name) {
|
||||
return new AWTPermission(name);
|
||||
}
|
||||
}
|
@ -54,7 +54,6 @@ import java.net.SocketPermission;
|
||||
import java.net.NetPermission;
|
||||
import java.util.PropertyPermission;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.awt.AWTPermission;
|
||||
/*
|
||||
import javax.security.auth.AuthPermission;
|
||||
import javax.security.auth.kerberos.ServicePermission;
|
||||
@ -1023,8 +1022,6 @@ public class PolicyFile extends java.security.Policy {
|
||||
return new NetPermission(name, actions);
|
||||
} else if (claz.equals(AllPermission.class)) {
|
||||
return SecurityConstants.ALL_PERMISSION;
|
||||
} else if (claz.equals(AWTPermission.class)) {
|
||||
return new AWTPermission(name, actions);
|
||||
/*
|
||||
} else if (claz.equals(ReflectPermission.class)) {
|
||||
return new ReflectPermission(name, actions);
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package sun.security.util;
|
||||
|
||||
import java.security.Permission;
|
||||
|
||||
/**
|
||||
* A factory object that creates Permission objects.
|
||||
*/
|
||||
|
||||
public interface PermissionFactory<T extends Permission> {
|
||||
T newPermission(String name);
|
||||
}
|
@ -25,12 +25,12 @@
|
||||
|
||||
package sun.security.util;
|
||||
|
||||
import java.io.FilePermission;
|
||||
import java.awt.AWTPermission;
|
||||
import java.util.PropertyPermission;
|
||||
import java.lang.RuntimePermission;
|
||||
import java.net.SocketPermission;
|
||||
import java.net.NetPermission;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.Permission;
|
||||
import java.security.BasicPermission;
|
||||
import java.security.SecurityPermission;
|
||||
import java.security.AllPermission;
|
||||
import javax.security.auth.AuthPermission;
|
||||
@ -71,45 +71,118 @@ public final class SecurityConstants {
|
||||
// sun.security.provider.PolicyFile
|
||||
public static final AllPermission ALL_PERMISSION = new AllPermission();
|
||||
|
||||
// java.lang.SecurityManager
|
||||
public static final AWTPermission TOPLEVEL_WINDOW_PERMISSION =
|
||||
new AWTPermission("showWindowWithoutWarningBanner");
|
||||
/**
|
||||
* Permission type used when AWT is not present.
|
||||
*/
|
||||
private static class FakeAWTPermission extends BasicPermission {
|
||||
private static final long serialVersionUID = -1L;
|
||||
public FakeAWTPermission(String name) {
|
||||
super(name);
|
||||
}
|
||||
public String toString() {
|
||||
return "(\"java.awt.AWTPermission\" \"" + getName() + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
// java.lang.SecurityManager
|
||||
public static final AWTPermission ACCESS_CLIPBOARD_PERMISSION =
|
||||
new AWTPermission("accessClipboard");
|
||||
/**
|
||||
* Permission factory used when AWT is not present.
|
||||
*/
|
||||
private static class FakeAWTPermissionFactory
|
||||
implements PermissionFactory<FakeAWTPermission>
|
||||
{
|
||||
@Override
|
||||
public FakeAWTPermission newPermission(String name) {
|
||||
return new FakeAWTPermission(name);
|
||||
}
|
||||
}
|
||||
|
||||
// java.lang.SecurityManager
|
||||
public static final AWTPermission CHECK_AWT_EVENTQUEUE_PERMISSION =
|
||||
new AWTPermission("accessEventQueue");
|
||||
/**
|
||||
* AWT Permissions used in the JDK.
|
||||
*/
|
||||
public static class AWT {
|
||||
private AWT() { }
|
||||
|
||||
// java.awt.Dialog
|
||||
public static final AWTPermission TOOLKIT_MODALITY_PERMISSION =
|
||||
new AWTPermission("toolkitModality");
|
||||
/**
|
||||
* The class name of the factory to create java.awt.AWTPermission objects.
|
||||
*/
|
||||
private static final String AWTFactory = "sun.awt.AWTPermissionFactory";
|
||||
|
||||
// java.awt.Robot
|
||||
public static final AWTPermission READ_DISPLAY_PIXELS_PERMISSION =
|
||||
new AWTPermission("readDisplayPixels");
|
||||
/**
|
||||
* The PermissionFactory to create AWT permissions (or fake permissions
|
||||
* if AWT is not present).
|
||||
*/
|
||||
private static final PermissionFactory<?> factory = permissionFactory();
|
||||
|
||||
// java.awt.Robot
|
||||
public static final AWTPermission CREATE_ROBOT_PERMISSION =
|
||||
new AWTPermission("createRobot");
|
||||
private static PermissionFactory<?> permissionFactory() {
|
||||
Class<?> c = AccessController
|
||||
.doPrivileged(new PrivilegedAction<Class<?>>() {
|
||||
public Class<?> run() {
|
||||
try {
|
||||
return Class.forName(AWTFactory, true, null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// not available
|
||||
return null;
|
||||
}
|
||||
}});
|
||||
if (c != null) {
|
||||
// AWT present
|
||||
try {
|
||||
return (PermissionFactory<?>)c.newInstance();
|
||||
} catch (InstantiationException x) {
|
||||
throw new InternalError(x.getMessage());
|
||||
} catch (IllegalAccessException x) {
|
||||
throw new InternalError(x.getMessage());
|
||||
}
|
||||
} else {
|
||||
// AWT not present
|
||||
return new FakeAWTPermissionFactory();
|
||||
}
|
||||
}
|
||||
|
||||
// java.awt.MouseInfo
|
||||
public static final AWTPermission WATCH_MOUSE_PERMISSION =
|
||||
new AWTPermission("watchMousePointer");
|
||||
private static Permission newAWTPermission(String name) {
|
||||
return factory.newPermission(name);
|
||||
}
|
||||
|
||||
// java.awt.Window
|
||||
public static final AWTPermission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
|
||||
new AWTPermission("setWindowAlwaysOnTop");
|
||||
// java.lang.SecurityManager
|
||||
public static final Permission TOPLEVEL_WINDOW_PERMISSION =
|
||||
newAWTPermission("showWindowWithoutWarningBanner");
|
||||
|
||||
// java.awt.Toolkit
|
||||
public static final AWTPermission ALL_AWT_EVENTS_PERMISSION =
|
||||
new AWTPermission("listenToAllAWTEvents");
|
||||
// java.lang.SecurityManager
|
||||
public static final Permission ACCESS_CLIPBOARD_PERMISSION =
|
||||
newAWTPermission("accessClipboard");
|
||||
|
||||
// java.awt.SystemTray
|
||||
public static final AWTPermission ACCESS_SYSTEM_TRAY_PERMISSION =
|
||||
new AWTPermission("accessSystemTray");
|
||||
// java.lang.SecurityManager
|
||||
public static final Permission CHECK_AWT_EVENTQUEUE_PERMISSION =
|
||||
newAWTPermission("accessEventQueue");
|
||||
|
||||
// java.awt.Dialog
|
||||
public static final Permission TOOLKIT_MODALITY_PERMISSION =
|
||||
newAWTPermission("toolkitModality");
|
||||
|
||||
// java.awt.Robot
|
||||
public static final Permission READ_DISPLAY_PIXELS_PERMISSION =
|
||||
newAWTPermission("readDisplayPixels");
|
||||
|
||||
// java.awt.Robot
|
||||
public static final Permission CREATE_ROBOT_PERMISSION =
|
||||
newAWTPermission("createRobot");
|
||||
|
||||
// java.awt.MouseInfo
|
||||
public static final Permission WATCH_MOUSE_PERMISSION =
|
||||
newAWTPermission("watchMousePointer");
|
||||
|
||||
// java.awt.Window
|
||||
public static final Permission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION =
|
||||
newAWTPermission("setWindowAlwaysOnTop");
|
||||
|
||||
// java.awt.Toolkit
|
||||
public static final Permission ALL_AWT_EVENTS_PERMISSION =
|
||||
newAWTPermission("listenToAllAWTEvents");
|
||||
|
||||
// java.awt.SystemTray
|
||||
public static final Permission ACCESS_SYSTEM_TRAY_PERMISSION =
|
||||
newAWTPermission("accessSystemTray");
|
||||
}
|
||||
|
||||
// java.net.URL
|
||||
public static final NetPermission SPECIFY_HANDLER_PERMISSION =
|
||||
|
Loading…
x
Reference in New Issue
Block a user