1. /*
  2. * @(#)RuntimePermission.java 1.44 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. import java.security.*;
  9. import java.util.Enumeration;
  10. import java.util.Hashtable;
  11. import java.util.StringTokenizer;
  12. /**
  13. * This class is for runtime permissions. A RuntimePermission
  14. * contains a name (also referred to as a "target name") but
  15. * no actions list; you either have the named permission
  16. * or you don't.
  17. *
  18. * <P>
  19. * The target name is the name of the runtime permission (see below). The
  20. * naming convention follows the hierarchical property naming convention.
  21. * Also, an asterisk
  22. * may appear at the end of the name, following a ".", or by itself, to
  23. * signify a wildcard match. For example: "loadLibrary.*" or "*" is valid,
  24. * "*loadLibrary" or "a*b" is not valid.
  25. * <P>
  26. * The following table lists all the possible RuntimePermission target names,
  27. * and for each provides a description of what the permission allows
  28. * and a discussion of the risks of granting code the permission.
  29. * <P>
  30. *
  31. * <table border=1 cellpadding=5 summary="permission target name,
  32. * what the target allows,and associated risks">
  33. * <tr>
  34. * <th>Permission Target Name</th>
  35. * <th>What the Permission Allows</th>
  36. * <th>Risks of Allowing this Permission</th>
  37. * </tr>
  38. *
  39. * <tr>
  40. * <td>createClassLoader</td>
  41. * <td>Creation of a class loader</td>
  42. * <td>This is an extremely dangerous permission to grant.
  43. * Malicious applications that can instantiate their own class
  44. * loaders could then load their own rogue classes into the system.
  45. * These newly loaded classes could be placed into any protection
  46. * domain by the class loader, thereby automatically granting the
  47. * classes the permissions for that domain.</td>
  48. * </tr>
  49. *
  50. * <tr>
  51. * <td>getClassLoader</td>
  52. * <td>Retrieval of a class loader (e.g., the class loader for the calling
  53. * class)</td>
  54. * <td>This would grant an attacker permission to get the
  55. * class loader for a particular class. This is dangerous because
  56. * having access to a class's class loader allows the attacker to
  57. * load other classes available to that class loader. The attacker
  58. * would typically otherwise not have access to those classes.</td>
  59. * </tr>
  60. *
  61. * <tr>
  62. * <td>setContextClassLoader</td>
  63. * <td>Setting of the context class loader used by a thread</td>
  64. * <td>The context class loader is used by system code and extensions
  65. * when they need to lookup resources that might not exist in the system
  66. * class loader. Granting setContextClassLoader permission would allow
  67. * code to change which context class loader is used
  68. * for a particular thread, including system threads.</td>
  69. * </tr>
  70. *
  71. * <tr>
  72. * <td>setSecurityManager</td>
  73. * <td>Setting of the security manager (possibly replacing an existing one)
  74. * </td>
  75. * <td>The security manager is a class that allows
  76. * applications to implement a security policy. Granting the setSecurityManager
  77. * permission would allow code to change which security manager is used by
  78. * installing a different, possibly less restrictive security manager,
  79. * thereby bypassing checks that would have been enforced by the original
  80. * security manager.</td>
  81. * </tr>
  82. *
  83. * <tr>
  84. * <td>createSecurityManager</td>
  85. * <td>Creation of a new security manager</td>
  86. * <td>This gives code access to protected, sensitive methods that may
  87. * disclose information about other classes or the execution stack.</td>
  88. * </tr>
  89. *
  90. * <tr>
  91. * <td>exitVM</td>
  92. * <td>Halting of the Java Virtual Machine</td>
  93. * <td>This allows an attacker to mount a denial-of-service attack
  94. * by automatically forcing the virtual machine to halt.
  95. * Note: The "exitVM" permission is automatically granted to all code
  96. * loaded from the application class path, thus enabling applications
  97. * to terminate themselves.</td>
  98. * </tr>
  99. *
  100. * <tr>
  101. * <td>shutdownHooks</td>
  102. * <td>Registration and cancellation of virtual-machine shutdown hooks</td>
  103. * <td>This allows an attacker to register a malicious shutdown
  104. * hook that interferes with the clean shutdown of the virtual machine.</td>
  105. * </tr>
  106. *
  107. * <tr>
  108. * <td>setFactory</td>
  109. * <td>Setting of the socket factory used by ServerSocket or Socket,
  110. * or of the stream handler factory used by URL</td>
  111. * <td>This allows code to set the actual implementation
  112. * for the socket, server socket, stream handler, or RMI socket factory.
  113. * An attacker may set a faulty implementation which mangles the data
  114. * stream.</td>
  115. * </tr>
  116. *
  117. * <tr>
  118. * <td>setIO</td>
  119. * <td>Setting of System.out, System.in, and System.err</td>
  120. * <td>This allows changing the value of the standard system streams.
  121. * An attacker may change System.in to monitor and
  122. * steal user input, or may set System.err to a "null" OutputSteam,
  123. * which would hide any error messages sent to System.err. </td>
  124. * </tr>
  125. *
  126. * <tr>
  127. * <td>modifyThread</td>
  128. * <td>Modification of threads, e.g., via calls to Thread <code>stop</code>,
  129. * <code>suspend</code>, <code>resume</code>, <code>setPriority</code>,
  130. * and <code>setName</code> methods</td>
  131. * <td>This allows an attacker to start or suspend any thread
  132. * in the system.</td>
  133. * </tr>
  134. *
  135. * <tr>
  136. * <td>stopThread</td>
  137. * <td>Stopping of threads via calls to the Thread <code>stop</code>
  138. * method</td>
  139. * <td>This allows code to stop any thread in the system provided that it is
  140. * already granted permission to access that thread.
  141. * This poses as a threat, because that code may corrupt the system by
  142. * killing existing threads.</td>
  143. * </tr>
  144. *
  145. * <tr>
  146. * <td>modifyThreadGroup</td>
  147. * <td>modification of thread groups, e.g., via calls to ThreadGroup
  148. * <code>destroy</code>, <code>getParent</code>, <code>resume</code>,
  149. * <code>setDaemon</code>, <code>setMaxPriority</code>, <code>stop</code>,
  150. * and <code>suspend</code> methods</td>
  151. * <td>This allows an attacker to create thread groups and
  152. * set their run priority.</td>
  153. * </tr>
  154. *
  155. * <tr>
  156. * <td>getProtectionDomain</td>
  157. * <td>Retrieval of the ProtectionDomain for a class</td>
  158. * <td>This allows code to obtain policy information
  159. * for a particular code source. While obtaining policy information
  160. * does not compromise the security of the system, it does give
  161. * attackers additional information, such as local file names for
  162. * example, to better aim an attack.</td>
  163. * </tr>
  164. *
  165. * <tr>
  166. * <td>readFileDescriptor</td>
  167. * <td>Reading of file descriptors</td>
  168. * <td>This would allow code to read the particular file associated
  169. * with the file descriptor read. This is dangerous if the file
  170. * contains confidential data.</td>
  171. * </tr>
  172. *
  173. * <tr>
  174. * <td>writeFileDescriptor</td>
  175. * <td>Writing to file descriptors</td>
  176. * <td>This allows code to write to a particular file associated
  177. * with the descriptor. This is dangerous because it may allow
  178. * malicious code to plant viruses or at the very least, fill up
  179. * your entire disk.</td>
  180. * </tr>
  181. *
  182. * <tr>
  183. * <td>loadLibrary.{library name}</td>
  184. * <td>Dynamic linking of the specified library</td>
  185. * <td>It is dangerous to allow an applet permission to load native code
  186. * libraries, because the Java security architecture is not designed to and
  187. * does not prevent malicious behavior at the level of native code.</td>
  188. * </tr>
  189. *
  190. * <tr>
  191. * <td>accessClassInPackage.{package name}</td>
  192. * <td>Access to the specified package via a class loader's
  193. * <code>loadClass</code> method when that class loader calls
  194. * the SecurityManager <code>checkPackageAcesss</code> method</td>
  195. * <td>This gives code access to classes in packages
  196. * to which it normally does not have access. Malicious code
  197. * may use these classes to help in its attempt to compromise
  198. * security in the system.</td>
  199. * </tr>
  200. *
  201. * <tr>
  202. * <td>defineClassInPackage.{package name}</td>
  203. * <td>Definition of classes in the specified package, via a class
  204. * loader's <code>defineClass</code> method when that class loader calls
  205. * the SecurityManager <code>checkPackageDefinition</code> method.</td>
  206. * <td>This grants code permission to define a class
  207. * in a particular package. This is dangerous because malicious
  208. * code with this permission may define rogue classes in
  209. * trusted packages like <code>java.security</code> or <code>java.lang</code>,
  210. * for example.</td>
  211. * </tr>
  212. *
  213. * <tr>
  214. * <td>accessDeclaredMembers</td>
  215. * <td>Access to the declared members of a class</td>
  216. * <td>This grants code permission to query a class for its public,
  217. * protected, default (package) access, and private fields and/or
  218. * methods. Although the code would have
  219. * access to the private and protected field and method names, it would not
  220. * have access to the private/protected field data and would not be able
  221. * to invoke any private methods. Nevertheless, malicious code
  222. * may use this information to better aim an attack.
  223. * Additionally, it may invoke any public methods and/or access public fields
  224. * in the class. This could be dangerous if
  225. * the code would normally not be able to invoke those methods and/or
  226. * access the fields because
  227. * it can't cast the object to the class/interface with those methods
  228. * and fields.
  229. </td>
  230. * </tr>
  231. * <tr>
  232. * <td>queuePrintJob</td>
  233. * <td>Initiation of a print job request</td>
  234. * <td>This could print sensitive information to a printer,
  235. * or simply waste paper.</td>
  236. * </tr>
  237. *
  238. * </table>
  239. *
  240. * @see java.security.BasicPermission
  241. * @see java.security.Permission
  242. * @see java.security.Permissions
  243. * @see java.security.PermissionCollection
  244. * @see java.lang.SecurityManager
  245. *
  246. * @version 1.44 03/01/23
  247. *
  248. * @author Marianne Mueller
  249. * @author Roland Schemers
  250. */
  251. public final class RuntimePermission extends BasicPermission {
  252. /**
  253. * Creates a new RuntimePermission with the specified name.
  254. * The name is the symbolic name of the RuntimePermission, such as
  255. * "exit", "setFactory", etc. An asterisk
  256. * may appear at the end of the name, following a ".", or by itself, to
  257. * signify a wildcard match.
  258. *
  259. * @param name the name of the RuntimePermission.
  260. */
  261. public RuntimePermission(String name)
  262. {
  263. super(name);
  264. }
  265. /**
  266. * Creates a new RuntimePermission object with the specified name.
  267. * The name is the symbolic name of the RuntimePermission, and the
  268. * actions String is currently unused and should be null.
  269. *
  270. * @param name the name of the RuntimePermission.
  271. * @param actions should be null.
  272. */
  273. public RuntimePermission(String name, String actions)
  274. {
  275. super(name, actions);
  276. }
  277. }