|
1 /* |
|
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package java.lang.management; |
|
27 |
|
28 /** |
|
29 * The permission which the SecurityManager will check when code |
|
30 * that is running with a SecurityManager calls methods defined |
|
31 * in the management interface for the Java platform. |
|
32 * <P> |
|
33 * The following table |
|
34 * provides a summary description of what the permission allows, |
|
35 * and discusses the risks of granting code the permission. |
|
36 * |
|
37 * <table class="striped"> |
|
38 * <caption style="display:none">Table shows permission target name, what the permission allows, and associated risks</caption> |
|
39 * <thead> |
|
40 * <tr> |
|
41 * <th scope="col">Permission Target Name</th> |
|
42 * <th scope="col">What the Permission Allows</th> |
|
43 * <th scope="col">Risks of Allowing this Permission</th> |
|
44 * </tr> |
|
45 * </thead> |
|
46 * <tbody style="text=align:left"> |
|
47 * |
|
48 * <tr> |
|
49 * <th scope="row">control</th> |
|
50 * <td>Ability to control the runtime characteristics of the Java virtual |
|
51 * machine, for example, enabling and disabling the verbose output for |
|
52 * the class loading or memory system, setting the threshold of a memory |
|
53 * pool, and enabling and disabling the thread contention monitoring |
|
54 * support. Some actions controlled by this permission can disclose |
|
55 * information about the running application, like the -verbose:class |
|
56 * flag. |
|
57 * </td> |
|
58 * <td>This allows an attacker to control the runtime characteristics |
|
59 * of the Java virtual machine and cause the system to misbehave. An |
|
60 * attacker can also access some information related to the running |
|
61 * application. |
|
62 * </td> |
|
63 * </tr> |
|
64 * <tr> |
|
65 * <th scope="row">monitor</th> |
|
66 * <td>Ability to retrieve runtime information about |
|
67 * the Java virtual machine such as thread |
|
68 * stack trace, a list of all loaded class names, and input arguments |
|
69 * to the Java virtual machine.</td> |
|
70 * <td>This allows malicious code to monitor runtime information and |
|
71 * uncover vulnerabilities.</td> |
|
72 * </tr> |
|
73 * |
|
74 * </tbody> |
|
75 * </table> |
|
76 * |
|
77 * <p> |
|
78 * Programmers do not normally create ManagementPermission objects directly. |
|
79 * Instead they are created by the security policy code based on reading |
|
80 * the security policy file. |
|
81 * |
|
82 * @author Mandy Chung |
|
83 * @since 1.5 |
|
84 * |
|
85 * @see java.security.BasicPermission |
|
86 * @see java.security.Permission |
|
87 * @see java.security.Permissions |
|
88 * @see java.security.PermissionCollection |
|
89 * @see java.lang.SecurityManager |
|
90 * |
|
91 */ |
|
92 |
|
93 public final class ManagementPermission extends java.security.BasicPermission { |
|
94 private static final long serialVersionUID = 1897496590799378737L; |
|
95 |
|
96 /** |
|
97 * Constructs a ManagementPermission with the specified name. |
|
98 * |
|
99 * @param name Permission name. Must be either "monitor" or "control". |
|
100 * |
|
101 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
102 * @throws IllegalArgumentException if <code>name</code> is empty or invalid. |
|
103 */ |
|
104 public ManagementPermission(String name) { |
|
105 super(name); |
|
106 if (!name.equals("control") && !name.equals("monitor")) { |
|
107 throw new IllegalArgumentException("name: " + name); |
|
108 } |
|
109 } |
|
110 |
|
111 /** |
|
112 * Constructs a new ManagementPermission object. |
|
113 * |
|
114 * @param name Permission name. Must be either "monitor" or "control". |
|
115 * @param actions Must be either null or the empty string. |
|
116 * |
|
117 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
118 * @throws IllegalArgumentException if <code>name</code> is empty or |
|
119 * if arguments are invalid. |
|
120 */ |
|
121 public ManagementPermission(String name, String actions) |
|
122 throws IllegalArgumentException { |
|
123 super(name); |
|
124 if (!name.equals("control") && !name.equals("monitor")) { |
|
125 throw new IllegalArgumentException("name: " + name); |
|
126 } |
|
127 if (actions != null && actions.length() > 0) { |
|
128 throw new IllegalArgumentException("actions: " + actions); |
|
129 } |
|
130 } |
|
131 } |