author | anthony |
Tue, 05 May 2009 17:56:31 +0400 | |
changeset 3444 | 18840bd1c784 |
parent 1940 | e81514210873 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 1997-2005 Sun Microsystems, Inc. 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import java.security.*; |
|
29 |
import java.util.Enumeration; |
|
30 |
import java.util.Hashtable; |
|
31 |
import java.util.StringTokenizer; |
|
32 |
||
33 |
/** |
|
34 |
* This class is for runtime permissions. A RuntimePermission |
|
35 |
* contains a name (also referred to as a "target name") but |
|
36 |
* no actions list; you either have the named permission |
|
37 |
* or you don't. |
|
38 |
* |
|
39 |
* <P> |
|
40 |
* The target name is the name of the runtime permission (see below). The |
|
41 |
* naming convention follows the hierarchical property naming convention. |
|
42 |
* Also, an asterisk |
|
43 |
* may appear at the end of the name, following a ".", or by itself, to |
|
44 |
* signify a wildcard match. For example: "loadLibrary.*" or "*" is valid, |
|
45 |
* "*loadLibrary" or "a*b" is not valid. |
|
46 |
* <P> |
|
47 |
* The following table lists all the possible RuntimePermission target names, |
|
48 |
* and for each provides a description of what the permission allows |
|
49 |
* and a discussion of the risks of granting code the permission. |
|
50 |
* <P> |
|
51 |
* |
|
52 |
* <table border=1 cellpadding=5 summary="permission target name, |
|
53 |
* what the target allows,and associated risks"> |
|
54 |
* <tr> |
|
55 |
* <th>Permission Target Name</th> |
|
56 |
* <th>What the Permission Allows</th> |
|
57 |
* <th>Risks of Allowing this Permission</th> |
|
58 |
* </tr> |
|
59 |
* |
|
60 |
* <tr> |
|
61 |
* <td>createClassLoader</td> |
|
62 |
* <td>Creation of a class loader</td> |
|
63 |
* <td>This is an extremely dangerous permission to grant. |
|
64 |
* Malicious applications that can instantiate their own class |
|
65 |
* loaders could then load their own rogue classes into the system. |
|
66 |
* These newly loaded classes could be placed into any protection |
|
67 |
* domain by the class loader, thereby automatically granting the |
|
68 |
* classes the permissions for that domain.</td> |
|
69 |
* </tr> |
|
70 |
* |
|
71 |
* <tr> |
|
72 |
* <td>getClassLoader</td> |
|
73 |
* <td>Retrieval of a class loader (e.g., the class loader for the calling |
|
74 |
* class)</td> |
|
75 |
* <td>This would grant an attacker permission to get the |
|
76 |
* class loader for a particular class. This is dangerous because |
|
77 |
* having access to a class's class loader allows the attacker to |
|
78 |
* load other classes available to that class loader. The attacker |
|
79 |
* would typically otherwise not have access to those classes.</td> |
|
80 |
* </tr> |
|
81 |
* |
|
82 |
* <tr> |
|
83 |
* <td>setContextClassLoader</td> |
|
84 |
* <td>Setting of the context class loader used by a thread</td> |
|
85 |
* <td>The context class loader is used by system code and extensions |
|
86 |
* when they need to lookup resources that might not exist in the system |
|
87 |
* class loader. Granting setContextClassLoader permission would allow |
|
88 |
* code to change which context class loader is used |
|
89 |
* for a particular thread, including system threads.</td> |
|
90 |
* </tr> |
|
91 |
* |
|
92 |
* <tr> |
|
93 |
* <td>enableContextClassLoaderOverride</td> |
|
94 |
* <td>Subclass implementation of the thread context class loader methods</td> |
|
95 |
* <td>The context class loader is used by system code and extensions |
|
96 |
* when they need to lookup resources that might not exist in the system |
|
97 |
* class loader. Granting enableContextClassLoaderOverride permission would allow |
|
98 |
* a subclass of Thread to override the methods that are used |
|
99 |
* to get or set the context class loader for a particular thread.</td> |
|
100 |
* </tr> |
|
101 |
* |
|
102 |
* <tr> |
|
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
103 |
* <td>closeClassLoader</td> |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
104 |
* <td>Closing of a ClassLoader</td> |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
105 |
* <td>Granting this permission allows code to close any URLClassLoader |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
106 |
* that it has a reference to.</td> |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
107 |
* </tr> |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
108 |
* |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
2
diff
changeset
|
109 |
* <tr> |
2 | 110 |
* <td>setSecurityManager</td> |
111 |
* <td>Setting of the security manager (possibly replacing an existing one) |
|
112 |
* </td> |
|
113 |
* <td>The security manager is a class that allows |
|
114 |
* applications to implement a security policy. Granting the setSecurityManager |
|
115 |
* permission would allow code to change which security manager is used by |
|
116 |
* installing a different, possibly less restrictive security manager, |
|
117 |
* thereby bypassing checks that would have been enforced by the original |
|
118 |
* security manager.</td> |
|
119 |
* </tr> |
|
120 |
* |
|
121 |
* <tr> |
|
122 |
* <td>createSecurityManager</td> |
|
123 |
* <td>Creation of a new security manager</td> |
|
124 |
* <td>This gives code access to protected, sensitive methods that may |
|
125 |
* disclose information about other classes or the execution stack.</td> |
|
126 |
* </tr> |
|
127 |
* |
|
128 |
* <tr> |
|
129 |
* <td>getenv.{variable name}</td> |
|
130 |
* <td>Reading of the value of the specified environment variable</td> |
|
131 |
* <td>This would allow code to read the value, or determine the |
|
132 |
* existence, of a particular environment variable. This is |
|
133 |
* dangerous if the variable contains confidential data.</td> |
|
134 |
* </tr> |
|
135 |
* |
|
136 |
* <tr> |
|
137 |
* <td>exitVM.{exit status}</td> |
|
138 |
* <td>Halting of the Java Virtual Machine with the specified exit status</td> |
|
139 |
* <td>This allows an attacker to mount a denial-of-service attack |
|
140 |
* by automatically forcing the virtual machine to halt. |
|
141 |
* Note: The "exitVM.*" permission is automatically granted to all code |
|
142 |
* loaded from the application class path, thus enabling applications |
|
143 |
* to terminate themselves. Also, the "exitVM" permission is equivalent to |
|
144 |
* "exitVM.*".</td> |
|
145 |
* </tr> |
|
146 |
* |
|
147 |
* <tr> |
|
148 |
* <td>shutdownHooks</td> |
|
149 |
* <td>Registration and cancellation of virtual-machine shutdown hooks</td> |
|
150 |
* <td>This allows an attacker to register a malicious shutdown |
|
151 |
* hook that interferes with the clean shutdown of the virtual machine.</td> |
|
152 |
* </tr> |
|
153 |
* |
|
154 |
* <tr> |
|
155 |
* <td>setFactory</td> |
|
156 |
* <td>Setting of the socket factory used by ServerSocket or Socket, |
|
157 |
* or of the stream handler factory used by URL</td> |
|
158 |
* <td>This allows code to set the actual implementation |
|
159 |
* for the socket, server socket, stream handler, or RMI socket factory. |
|
160 |
* An attacker may set a faulty implementation which mangles the data |
|
161 |
* stream.</td> |
|
162 |
* </tr> |
|
163 |
* |
|
164 |
* <tr> |
|
165 |
* <td>setIO</td> |
|
166 |
* <td>Setting of System.out, System.in, and System.err</td> |
|
167 |
* <td>This allows changing the value of the standard system streams. |
|
168 |
* An attacker may change System.in to monitor and |
|
169 |
* steal user input, or may set System.err to a "null" OutputStream, |
|
170 |
* which would hide any error messages sent to System.err. </td> |
|
171 |
* </tr> |
|
172 |
* |
|
173 |
* <tr> |
|
174 |
* <td>modifyThread</td> |
|
175 |
* <td>Modification of threads, e.g., via calls to Thread |
|
176 |
* <tt>interrupt</tt>, <tt>stop</tt>, <tt>suspend</tt>, |
|
177 |
* <tt>resume</tt>, <tt>setDaemon</tt>, <tt>setPriority</tt>, |
|
178 |
* <tt>setName</tt> and <tt>setUncaughtExceptionHandler</tt> |
|
179 |
* methods</td> |
|
180 |
* <td>This allows an attacker to modify the behaviour of |
|
181 |
* any thread in the system.</td> |
|
182 |
* </tr> |
|
183 |
* |
|
184 |
* <tr> |
|
185 |
* <td>stopThread</td> |
|
186 |
* <td>Stopping of threads via calls to the Thread <code>stop</code> |
|
187 |
* method</td> |
|
188 |
* <td>This allows code to stop any thread in the system provided that it is |
|
189 |
* already granted permission to access that thread. |
|
190 |
* This poses as a threat, because that code may corrupt the system by |
|
191 |
* killing existing threads.</td> |
|
192 |
* </tr> |
|
193 |
* |
|
194 |
* <tr> |
|
195 |
* <td>modifyThreadGroup</td> |
|
196 |
* <td>modification of thread groups, e.g., via calls to ThreadGroup |
|
197 |
* <code>destroy</code>, <code>getParent</code>, <code>resume</code>, |
|
198 |
* <code>setDaemon</code>, <code>setMaxPriority</code>, <code>stop</code>, |
|
199 |
* and <code>suspend</code> methods</td> |
|
200 |
* <td>This allows an attacker to create thread groups and |
|
201 |
* set their run priority.</td> |
|
202 |
* </tr> |
|
203 |
* |
|
204 |
* <tr> |
|
205 |
* <td>getProtectionDomain</td> |
|
206 |
* <td>Retrieval of the ProtectionDomain for a class</td> |
|
207 |
* <td>This allows code to obtain policy information |
|
208 |
* for a particular code source. While obtaining policy information |
|
209 |
* does not compromise the security of the system, it does give |
|
210 |
* attackers additional information, such as local file names for |
|
211 |
* example, to better aim an attack.</td> |
|
212 |
* </tr> |
|
213 |
* |
|
214 |
* <tr> |
|
215 |
* <td>getFileSystemAttributes</td> |
|
216 |
* <td>Retrieval of file system attributes</td> |
|
217 |
* <td>This allows code to obtain file system information such as disk usage |
|
218 |
* or disk space available to the caller. This is potentially dangerous |
|
219 |
* because it discloses information about the system hardware |
|
220 |
* configuration and some information about the caller's privilege to |
|
221 |
* write files.</td> |
|
222 |
* </tr> |
|
223 |
* |
|
224 |
* <tr> |
|
225 |
* <td>readFileDescriptor</td> |
|
226 |
* <td>Reading of file descriptors</td> |
|
227 |
* <td>This would allow code to read the particular file associated |
|
228 |
* with the file descriptor read. This is dangerous if the file |
|
229 |
* contains confidential data.</td> |
|
230 |
* </tr> |
|
231 |
* |
|
232 |
* <tr> |
|
233 |
* <td>writeFileDescriptor</td> |
|
234 |
* <td>Writing to file descriptors</td> |
|
235 |
* <td>This allows code to write to a particular file associated |
|
236 |
* with the descriptor. This is dangerous because it may allow |
|
237 |
* malicious code to plant viruses or at the very least, fill up |
|
238 |
* your entire disk.</td> |
|
239 |
* </tr> |
|
240 |
* |
|
241 |
* <tr> |
|
242 |
* <td>loadLibrary.{library name}</td> |
|
243 |
* <td>Dynamic linking of the specified library</td> |
|
244 |
* <td>It is dangerous to allow an applet permission to load native code |
|
245 |
* libraries, because the Java security architecture is not designed to and |
|
246 |
* does not prevent malicious behavior at the level of native code.</td> |
|
247 |
* </tr> |
|
248 |
* |
|
249 |
* <tr> |
|
250 |
* <td>accessClassInPackage.{package name}</td> |
|
251 |
* <td>Access to the specified package via a class loader's |
|
252 |
* <code>loadClass</code> method when that class loader calls |
|
253 |
* the SecurityManager <code>checkPackageAccess</code> method</td> |
|
254 |
* <td>This gives code access to classes in packages |
|
255 |
* to which it normally does not have access. Malicious code |
|
256 |
* may use these classes to help in its attempt to compromise |
|
257 |
* security in the system.</td> |
|
258 |
* </tr> |
|
259 |
* |
|
260 |
* <tr> |
|
261 |
* <td>defineClassInPackage.{package name}</td> |
|
262 |
* <td>Definition of classes in the specified package, via a class |
|
263 |
* loader's <code>defineClass</code> method when that class loader calls |
|
264 |
* the SecurityManager <code>checkPackageDefinition</code> method.</td> |
|
265 |
* <td>This grants code permission to define a class |
|
266 |
* in a particular package. This is dangerous because malicious |
|
267 |
* code with this permission may define rogue classes in |
|
268 |
* trusted packages like <code>java.security</code> or <code>java.lang</code>, |
|
269 |
* for example.</td> |
|
270 |
* </tr> |
|
271 |
* |
|
272 |
* <tr> |
|
273 |
* <td>accessDeclaredMembers</td> |
|
274 |
* <td>Access to the declared members of a class</td> |
|
275 |
* <td>This grants code permission to query a class for its public, |
|
276 |
* protected, default (package) access, and private fields and/or |
|
277 |
* methods. Although the code would have |
|
278 |
* access to the private and protected field and method names, it would not |
|
279 |
* have access to the private/protected field data and would not be able |
|
280 |
* to invoke any private methods. Nevertheless, malicious code |
|
281 |
* may use this information to better aim an attack. |
|
282 |
* Additionally, it may invoke any public methods and/or access public fields |
|
283 |
* in the class. This could be dangerous if |
|
284 |
* the code would normally not be able to invoke those methods and/or |
|
285 |
* access the fields because |
|
286 |
* it can't cast the object to the class/interface with those methods |
|
287 |
* and fields. |
|
288 |
</td> |
|
289 |
* </tr> |
|
290 |
* <tr> |
|
291 |
* <td>queuePrintJob</td> |
|
292 |
* <td>Initiation of a print job request</td> |
|
293 |
* <td>This could print sensitive information to a printer, |
|
294 |
* or simply waste paper.</td> |
|
295 |
* </tr> |
|
296 |
* |
|
297 |
* <tr> |
|
298 |
* <td>getStackTrace</td> |
|
299 |
* <td>Retrieval of the stack trace information of another thread.</td> |
|
300 |
* <td>This allows retrieval of the stack trace information of |
|
301 |
* another thread. This might allow malicious code to monitor the |
|
302 |
* execution of threads and discover vulnerabilities in applications.</td> |
|
303 |
* </tr> |
|
304 |
* |
|
305 |
* <tr> |
|
306 |
* <td>setDefaultUncaughtExceptionHandler</td> |
|
307 |
* <td>Setting the default handler to be used when a thread |
|
308 |
* terminates abruptly due to an uncaught exception</td> |
|
309 |
* <td>This allows an attacker to register a malicious |
|
310 |
* uncaught exception handler that could interfere with termination |
|
311 |
* of a thread</td> |
|
312 |
* </tr> |
|
313 |
* |
|
314 |
* <tr> |
|
315 |
* <td>preferences</td> |
|
316 |
* <td>Represents the permission required to get access to the |
|
317 |
* java.util.prefs.Preferences implementations user or system root |
|
318 |
* which in turn allows retrieval or update operations within the |
|
319 |
* Preferences persistent backing store.) </td> |
|
320 |
* <td>This permission allows the user to read from or write to the |
|
321 |
* preferences backing store if the user running the code has |
|
322 |
* sufficient OS privileges to read/write to that backing store. |
|
323 |
* The actual backing store may reside within a traditional filesystem |
|
324 |
* directory or within a registry depending on the platform OS</td> |
|
325 |
* </tr> |
|
326 |
* |
|
327 |
* <tr> |
|
328 |
* <td>usePolicy</td> |
|
329 |
* <td>Granting this permission disables the Java Plug-In's default |
|
330 |
* security prompting behavior.</td> |
|
331 |
* <td>For more information, refer to Java Plug-In's guides, <a href= |
|
332 |
* "../../../technotes/guides/plugin/developer_guide/security.html"> |
|
333 |
* Applet Security Basics</a> and <a href= |
|
334 |
* "../../../technotes/guides/plugin/developer_guide/rsa_how.html#use"> |
|
335 |
* usePolicy Permission</a>.</td> |
|
336 |
* </tr> |
|
337 |
* </table> |
|
338 |
* |
|
339 |
* @see java.security.BasicPermission |
|
340 |
* @see java.security.Permission |
|
341 |
* @see java.security.Permissions |
|
342 |
* @see java.security.PermissionCollection |
|
343 |
* @see java.lang.SecurityManager |
|
344 |
* |
|
345 |
* |
|
346 |
* @author Marianne Mueller |
|
347 |
* @author Roland Schemers |
|
348 |
*/ |
|
349 |
||
350 |
public final class RuntimePermission extends BasicPermission { |
|
351 |
||
352 |
private static final long serialVersionUID = 7399184964622342223L; |
|
353 |
||
354 |
/** |
|
355 |
* Creates a new RuntimePermission with the specified name. |
|
356 |
* The name is the symbolic name of the RuntimePermission, such as |
|
357 |
* "exit", "setFactory", etc. An asterisk |
|
358 |
* may appear at the end of the name, following a ".", or by itself, to |
|
359 |
* signify a wildcard match. |
|
360 |
* |
|
361 |
* @param name the name of the RuntimePermission. |
|
362 |
* |
|
363 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
364 |
* @throws IllegalArgumentException if <code>name</code> is empty. |
|
365 |
*/ |
|
366 |
||
367 |
public RuntimePermission(String name) |
|
368 |
{ |
|
369 |
super(name); |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Creates a new RuntimePermission object with the specified name. |
|
374 |
* The name is the symbolic name of the RuntimePermission, and the |
|
375 |
* actions String is currently unused and should be null. |
|
376 |
* |
|
377 |
* @param name the name of the RuntimePermission. |
|
378 |
* @param actions should be null. |
|
379 |
* |
|
380 |
* @throws NullPointerException if <code>name</code> is <code>null</code>. |
|
381 |
* @throws IllegalArgumentException if <code>name</code> is empty. |
|
382 |
*/ |
|
383 |
||
384 |
public RuntimePermission(String name, String actions) |
|
385 |
{ |
|
386 |
super(name, actions); |
|
387 |
} |
|
388 |
} |