Path: blob/master/src/java.desktop/share/classes/java/awt/AWTPermission.java
41152 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.awt;2627import java.io.Serial;28import java.security.BasicPermission;2930/**31* This class is for AWT permissions.32* An {@code AWTPermission} contains a target name but33* no actions list; you either have the named permission34* or you don't.35*36* <P>37* The target name is the name of the AWT permission (see below). The naming38* convention follows the hierarchical property naming convention.39* Also, an asterisk could be used to represent all AWT permissions.40*41* <P>42* The following table lists all the possible {@code AWTPermission}43* target names, and for each provides a description of what the44* permission allows and a discussion of the risks of granting code45* the permission.46*47* <table class="striped">48* <caption>AWTPermission target names, descriptions, and associated risks49* </caption>50* <thead>51* <tr>52* <th scope="col">Permission Target Name53* <th scope="col">What the Permission Allows54* <th scope="col">Risks of Allowing this Permission55* </thead>56* <tbody>57* <tr>58* <th scope="row">accessClipboard59* <td>Posting and retrieval of information to and from the AWT clipboard60* <td>This would allow malfeasant code to share potentially sensitive or61* confidential information.62* <tr>63* <th scope="row">accessEventQueue64* <td>Access to the AWT event queue65* <td>After retrieving the AWT event queue, malicious code may peek at and66* even remove existing events from its event queue, as well as post bogus67* events which may purposefully cause the application or applet to68* misbehave in an insecure manner.69* <tr>70* <th scope="row">accessSystemTray71* <td>Access to the AWT SystemTray instance72* <td>This would allow malicious code to add tray icons to the system tray.73* First, such an icon may look like the icon of some known application74* (such as a firewall or anti-virus) and order a user to do something75* unsafe (with help of balloon messages). Second, the system tray may be76* glutted with tray icons so that no one could add a tray icon anymore.77* <tr>78* <th scope="row">createRobot79* <td>Create java.awt.Robot objects80* <td>The java.awt.Robot object allows code to generate native-level mouse81* and keyboard events as well as read the screen. It could allow malicious82* code to control the system, run other programs, read the display, and83* deny mouse and keyboard access to the user.84* <tr>85* <th scope="row">fullScreenExclusive86* <td>Enter full-screen exclusive mode87* <td>Entering full-screen exclusive mode allows direct access to low-level88* graphics card memory. This could be used to spoof the system, since the89* program is in direct control of rendering. Depending on the90* implementation, the security warning may not be shown for the windows91* used to enter the full-screen exclusive mode (assuming that the92* {@code fullScreenExclusive} permission has been granted to this93* application). Note that this behavior does not mean that the94* {@code showWindowWithoutWarningBanner} permission will be automatically95* granted to the application which has the {@code fullScreenExclusive}96* permission: non-full-screen windows will continue to be shown with the97* security warning.98* <tr>99* <th scope="row">listenToAllAWTEvents100* <td>Listen to all AWT events, system-wide101* <td>After adding an AWT event listener, malicious code may scan all AWT102* events dispatched in the system, allowing it to read all user input (such103* as passwords). Each AWT event listener is called from within the context104* of that event queue's EventDispatchThread, so if the accessEventQueue105* permission is also enabled, malicious code could modify the contents of106* AWT event queues system-wide, causing the application or applet to107* misbehave in an insecure manner.108* <tr>109* <th scope="row">readDisplayPixels110* <td>Readback of pixels from the display screen111* <td>Interfaces such as the java.awt.Composite interface or the112* java.awt.Robot class allow arbitrary code to examine pixels on the113* display enable malicious code to snoop on the activities of the user.114* <tr>115* <th scope="row">replaceKeyboardFocusManager116* <td>Sets the {@code KeyboardFocusManager} for a particular thread.117* <td>When {@code SecurityManager} is installed, the invoking thread must118* be granted this permission in order to replace the current119* {@code KeyboardFocusManager}. If permission is not granted, a120* {@code SecurityException} will be thrown.121* <tr>122* <th scope="row">setAppletStub123* <td>Setting the stub which implements Applet container services124* <td>Malicious code could set an applet's stub and result in unexpected125* behavior or denial of service to an applet.126* <tr>127* <th scope="row">setWindowAlwaysOnTop128* <td>Setting always-on-top property of the window:129* {@link Window#setAlwaysOnTop}130* <td>The malicious window might make itself look and behave like a real131* full desktop, so that information entered by the unsuspecting user is132* captured and subsequently misused133* <tr>134* <th scope="row">showWindowWithoutWarningBanner135* <td>Display of a window without also displaying a banner warning that the136* window was created by an applet137* <td>Without this warning, an applet may pop up windows without the user138* knowing that they belong to an applet. Since users may make139* security-sensitive decisions based on whether or not the window belongs140* to an applet (entering a username and password into a dialog box, for141* example), disabling this warning banner may allow applets to trick the142* user into entering such information.143* <tr>144* <th scope="row">toolkitModality145* <td>Creating {@link Dialog.ModalityType#TOOLKIT_MODAL TOOLKIT_MODAL}146* dialogs and setting the147* {@link Dialog.ModalExclusionType#TOOLKIT_EXCLUDE TOOLKIT_EXCLUDE} window148* property.149* <td>When a toolkit-modal dialog is shown from an applet, it blocks all150* other applets in the browser. When launching applications from Java Web151* Start, its windows (such as the security dialog) may also be blocked by152* toolkit-modal dialogs, shown from these applications.153* <tr>154* <th scope="row">watchMousePointer155* <td>Getting the information about the mouse pointer position at any time156* <td>Constantly watching the mouse pointer, an applet can make guesses157* about what the user is doing, i.e. moving the mouse to the lower left158* corner of the screen most likely means that the user is about to launch159* an application. If a virtual keypad is used so that keyboard is emulated160* using the mouse, an applet may guess what is being typed.161* </tbody>162* </table>163*164* @see java.security.BasicPermission165* @see java.security.Permission166* @see java.security.Permissions167* @see java.security.PermissionCollection168* @see java.lang.SecurityManager169*170* @author Marianne Mueller171* @author Roland Schemers172*/173public final class AWTPermission extends BasicPermission {174175/**176* Use serialVersionUID from JDK 1.2 for interoperability.177*/178@Serial179private static final long serialVersionUID = 8890392402588814465L;180181/**182* Creates a new {@code AWTPermission} with the specified name.183* The name is the symbolic name of the {@code AWTPermission},184* such as "topLevelWindow", "systemClipboard", etc. An asterisk185* may be used to indicate all AWT permissions.186*187* @param name the name of the AWTPermission188*189* @throws NullPointerException if {@code name} is {@code null}.190* @throws IllegalArgumentException if {@code name} is empty.191*/192193public AWTPermission(String name)194{195super(name);196}197198/**199* Creates a new {@code AWTPermission} object with the specified name.200* The name is the symbolic name of the {@code AWTPermission}, and the201* actions string is currently unused and should be {@code null}.202*203* @param name the name of the {@code AWTPermission}204* @param actions should be {@code null}205*206* @throws NullPointerException if {@code name} is {@code null}.207* @throws IllegalArgumentException if {@code name} is empty.208*/209210public AWTPermission(String name, String actions)211{212super(name, actions);213}214}215216217