Path: blob/master/src/java.management/share/classes/java/lang/management/ManagementPermission.java
41159 views
/*1* Copyright (c) 2003, 2017, 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.lang.management;2627/**28* The permission which the SecurityManager will check when code29* that is running with a SecurityManager calls methods defined30* in the management interface for the Java platform.31* <P>32* The following table33* provides a summary description of what the permission allows,34* and discusses the risks of granting code the permission.35*36* <table class="striped">37* <caption style="display:none">Table shows permission target name, what the permission allows, and associated risks</caption>38* <thead>39* <tr>40* <th scope="col">Permission Target Name</th>41* <th scope="col">What the Permission Allows</th>42* <th scope="col">Risks of Allowing this Permission</th>43* </tr>44* </thead>45* <tbody style="text=align:left">46*47* <tr>48* <th scope="row">control</th>49* <td>Ability to control the runtime characteristics of the Java virtual50* machine, for example, enabling and disabling the verbose output for51* the class loading or memory system, setting the threshold of a memory52* pool, and enabling and disabling the thread contention monitoring53* support. Some actions controlled by this permission can disclose54* information about the running application, like the -verbose:class55* flag.56* </td>57* <td>This allows an attacker to control the runtime characteristics58* of the Java virtual machine and cause the system to misbehave. An59* attacker can also access some information related to the running60* application.61* </td>62* </tr>63* <tr>64* <th scope="row">monitor</th>65* <td>Ability to retrieve runtime information about66* the Java virtual machine such as thread67* stack trace, a list of all loaded class names, and input arguments68* to the Java virtual machine.</td>69* <td>This allows malicious code to monitor runtime information and70* uncover vulnerabilities.</td>71* </tr>72*73* </tbody>74* </table>75*76* <p>77* Programmers do not normally create ManagementPermission objects directly.78* Instead they are created by the security policy code based on reading79* the security policy file.80*81* @author Mandy Chung82* @since 1.583*84* @see java.security.BasicPermission85* @see java.security.Permission86* @see java.security.Permissions87* @see java.security.PermissionCollection88* @see java.lang.SecurityManager89*90*/9192public final class ManagementPermission extends java.security.BasicPermission {93private static final long serialVersionUID = 1897496590799378737L;9495/**96* Constructs a ManagementPermission with the specified name.97*98* @param name Permission name. Must be either "monitor" or "control".99*100* @throws NullPointerException if <code>name</code> is <code>null</code>.101* @throws IllegalArgumentException if <code>name</code> is empty or invalid.102*/103public ManagementPermission(String name) {104super(name);105if (!name.equals("control") && !name.equals("monitor")) {106throw new IllegalArgumentException("name: " + name);107}108}109110/**111* Constructs a new ManagementPermission object.112*113* @param name Permission name. Must be either "monitor" or "control".114* @param actions Must be either null or the empty string.115*116* @throws NullPointerException if <code>name</code> is <code>null</code>.117* @throws IllegalArgumentException if <code>name</code> is empty or118* if arguments are invalid.119*/120public ManagementPermission(String name, String actions)121throws IllegalArgumentException {122super(name);123if (!name.equals("control") && !name.equals("monitor")) {124throw new IllegalArgumentException("name: " + name);125}126if (actions != null && actions.length() > 0) {127throw new IllegalArgumentException("actions: " + actions);128}129}130}131132133