| 1 | /* java.lang.SecurityManager
|
|---|
| 2 | Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.lang;
|
|---|
| 40 |
|
|---|
| 41 | import java.net.*;
|
|---|
| 42 | import java.util.*;
|
|---|
| 43 | import java.io.*;
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | ** SecurityManager is a class you can extend to create
|
|---|
| 47 | ** your own Java security policy. By default, there is
|
|---|
| 48 | ** no SecurityManager installed in 1.1, which means that
|
|---|
| 49 | ** all things are permitted to all people.<P>
|
|---|
| 50 | **
|
|---|
| 51 | ** The default methods in this class deny all
|
|---|
| 52 | ** things to all people.
|
|---|
| 53 | **
|
|---|
| 54 | ** @author John Keiser
|
|---|
| 55 | ** @version 1.1.0, 31 May 1998
|
|---|
| 56 | ** @since JDK1.0
|
|---|
| 57 | **/
|
|---|
| 58 | public class SecurityManager {
|
|---|
| 59 | /** Tells whether or not the SecurityManager is currently
|
|---|
| 60 | ** performing a security check.
|
|---|
| 61 | **/
|
|---|
| 62 | protected boolean inCheck;
|
|---|
| 63 |
|
|---|
| 64 | /** Tells whether or not the SecurityManager is currently
|
|---|
| 65 | ** performing a security check.
|
|---|
| 66 | **
|
|---|
| 67 | ** @return whether or not the SecurityManager is
|
|---|
| 68 | ** currently performing a security check.
|
|---|
| 69 | **/
|
|---|
| 70 | public boolean getInCheck() {
|
|---|
| 71 | return inCheck;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /** Get a list of all the classes currently executing
|
|---|
| 75 | ** methods on the Java stack. getClassContext()[0] is
|
|---|
| 76 | ** the currently executing method
|
|---|
| 77 | ** <STRONG>Spec Note:</STRONG> does not say whether
|
|---|
| 78 | ** the stack will include the getClassContext() call or
|
|---|
| 79 | ** the one just before it.
|
|---|
| 80 | **
|
|---|
| 81 | ** @return an array containing all the methods on classes
|
|---|
| 82 | ** on the Java execution stack.
|
|---|
| 83 | **/
|
|---|
| 84 | protected Class[] getClassContext() {
|
|---|
| 85 | return VMSecurityManager.getClassContext();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /** Find the ClassLoader for the most recent class on the
|
|---|
| 89 | ** stack that was loaded by an explicit ClassLoader. If
|
|---|
| 90 | ** everything on the stack was loaded by the system
|
|---|
| 91 | ** classloader, null is returned.
|
|---|
| 92 | **
|
|---|
| 93 | ** @return the most recent ClassLoader on the execution
|
|---|
| 94 | ** stack.
|
|---|
| 95 | **/
|
|---|
| 96 | protected ClassLoader currentClassLoader() {
|
|---|
| 97 | return VMSecurityManager.currentClassLoader();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /** Find the most recent class on the stack that was
|
|---|
| 101 | ** loaded by an explicit ClassLoader. If everything on
|
|---|
| 102 | ** the stack was loaded by the system classloader, null
|
|---|
| 103 | ** is returned.
|
|---|
| 104 | **
|
|---|
| 105 | ** @return the most recent loaded Class on the execution
|
|---|
| 106 | ** stack.
|
|---|
| 107 | **/
|
|---|
| 108 | protected Class currentLoadedClass() {
|
|---|
| 109 | Class[] c = getClassContext();
|
|---|
| 110 | for(int i=0;i<c.length;i++) {
|
|---|
| 111 | if(c[i].getClassLoader() != null) {
|
|---|
| 112 | return c[i];
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 | return null;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /** Get the depth on the execution stack of the most
|
|---|
| 119 | ** recent class that was loaded by an explicit
|
|---|
| 120 | ** ClassLoader. This can be used as an index into
|
|---|
| 121 | ** getClassContext().
|
|---|
| 122 | **
|
|---|
| 123 | ** @return the index of the most recent loaded Class on
|
|---|
| 124 | ** the execution stack.
|
|---|
| 125 | **/
|
|---|
| 126 | protected int classLoaderDepth() {
|
|---|
| 127 | Class[] c = getClassContext();
|
|---|
| 128 | for(int i=0;i<c.length;i++) {
|
|---|
| 129 | if(c[i].getClassLoader() != null) {
|
|---|
| 130 | return i;
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 | return -1;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | /** Tell whether there is a class loaded with an explicit
|
|---|
| 137 | ** ClassLoader on the stack.
|
|---|
| 138 | **
|
|---|
| 139 | ** @return whether there is a class loaded with an
|
|---|
| 140 | ** explicit ClassLoader on the stack.
|
|---|
| 141 | **/
|
|---|
| 142 | protected boolean inClassLoader() {
|
|---|
| 143 | return classLoaderDepth() != -1;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | /** Get the depth of a particular class on the execution
|
|---|
| 148 | ** stack.
|
|---|
| 149 | **
|
|---|
| 150 | ** @param className the fully-qualified name of the class
|
|---|
| 151 | ** to search for on the stack.
|
|---|
| 152 | ** @return the index of the class on the stack, or -1 if
|
|---|
| 153 | ** the class is not on the stack.
|
|---|
| 154 | **/
|
|---|
| 155 | protected int classDepth(String className) {
|
|---|
| 156 | Class[] c = getClassContext();
|
|---|
| 157 | for(int i=0;i<c.length;i++) {
|
|---|
| 158 | if(className.equals(c[i].getName())) {
|
|---|
| 159 | return i;
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 | return -1;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | /** Tell whether the specified class is on the execution
|
|---|
| 166 | ** stack.
|
|---|
| 167 | **
|
|---|
| 168 | ** @param className the fully-qualified name of the class
|
|---|
| 169 | ** to search for on the stack.
|
|---|
| 170 | ** @return whether the specified class is on the
|
|---|
| 171 | ** execution stack.
|
|---|
| 172 | **/
|
|---|
| 173 | protected boolean inClass(String className) {
|
|---|
| 174 | return classDepth(className) != -1;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | /** Get an implementation-dependent Object that contains
|
|---|
| 178 | ** enough information about the current environment to be
|
|---|
| 179 | ** able to perform standard security checks later. This
|
|---|
| 180 | ** is used by trusted methods that need to verify that
|
|---|
| 181 | ** their callers have sufficient access to perform
|
|---|
| 182 | ** certain operations.<P>
|
|---|
| 183 | **
|
|---|
| 184 | ** Currently the only methods that use this are checkRead()
|
|---|
| 185 | ** and checkConnect().
|
|---|
| 186 | **
|
|---|
| 187 | ** @see checkConnect(java.lang.String,int,java.lang.Object)
|
|---|
| 188 | ** @see checkRead(java.lang.String,java.lang.Object)
|
|---|
| 189 | **/
|
|---|
| 190 | public Object getSecurityContext() {
|
|---|
| 191 | return new SecurityContext(getClassContext());
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /** Check if the current thread is allowed to create a
|
|---|
| 195 | ** ClassLoader.<P>
|
|---|
| 196 | **
|
|---|
| 197 | ** This method is called from ClassLoader.ClassLoader(),
|
|---|
| 198 | ** in other words, whenever a ClassLoader is created.<P>
|
|---|
| 199 | **
|
|---|
| 200 | ** SecurityManager's implementation always denies access.
|
|---|
| 201 | **
|
|---|
| 202 | ** @exception SecurityException if the operation is not
|
|---|
| 203 | ** permitted.
|
|---|
| 204 | ** @see java.lang.ClassLoader#ClassLoader()
|
|---|
| 205 | **/
|
|---|
| 206 | public void checkCreateClassLoader() {
|
|---|
| 207 | throw new SecurityException("Cannot create new ClassLoaders.");
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | /** Check if the current thread is allowed to modify this
|
|---|
| 211 | ** other Thread.<P>
|
|---|
| 212 | **
|
|---|
| 213 | ** Called by Thread.stop(), suspend(), resume(), and
|
|---|
| 214 | ** interrupt(), destroy(), setPriority(), setName() and
|
|---|
| 215 | ** setDaemon().<P>
|
|---|
| 216 | **
|
|---|
| 217 | ** SecurityManager's implementation always denies access.
|
|---|
| 218 | **
|
|---|
| 219 | ** @param g the Thread to check against
|
|---|
| 220 | ** @exception SecurityException if the operation is not
|
|---|
| 221 | ** permitted.
|
|---|
| 222 | ** @see java.lang.Thread#stop()
|
|---|
| 223 | ** @see java.lang.Thread#suspend()
|
|---|
| 224 | ** @see java.lang.Thread#resume()
|
|---|
| 225 | ** @see java.lang.Thread#interrupt()
|
|---|
| 226 | ** @see java.lang.Thread#destroy()
|
|---|
| 227 | ** @see java.lang.Thread#setPriority(int)
|
|---|
| 228 | ** @see java.lang.Thread#setName(java.lang.String)
|
|---|
| 229 | ** @see java.lang.Thread#setDaemon(boolean)
|
|---|
| 230 | **/
|
|---|
| 231 | public void checkAccess(Thread t) {
|
|---|
| 232 | throw new SecurityException("Cannot modify Threads.");
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /** Check if the current thread is allowed to modify this
|
|---|
| 236 | ** ThreadGroup.<P>
|
|---|
| 237 | **
|
|---|
| 238 | ** Called by Thread.Thread() (to add a thread to the
|
|---|
| 239 | ** ThreadGroup), ThreadGroup.ThreadGroup() (to add this
|
|---|
| 240 | ** ThreadGroup to a parent), ThreadGroup.stop(),
|
|---|
| 241 | ** suspend(), resume(), interrupt(), destroy(),
|
|---|
| 242 | ** setDaemon(), and setMaxPriority().<P>
|
|---|
| 243 | **
|
|---|
| 244 | ** SecurityManager's implementation always denies access.
|
|---|
| 245 | **
|
|---|
| 246 | ** @param g the ThreadGroup to check against
|
|---|
| 247 | ** @exception SecurityException if the operation is not
|
|---|
| 248 | ** permitted.
|
|---|
| 249 | ** @see java.lang.Thread#Thread()
|
|---|
| 250 | ** @see java.lang.ThreadGroup#ThreadGroup()
|
|---|
| 251 | ** @see java.lang.ThreadGroup#stop()
|
|---|
| 252 | ** @see java.lang.ThreadGroup#suspend()
|
|---|
| 253 | ** @see java.lang.ThreadGroup#resume()
|
|---|
| 254 | ** @see java.lang.ThreadGroup#interrupt()
|
|---|
| 255 | ** @see java.lang.ThreadGroup#setDaemon(boolean)
|
|---|
| 256 | ** @see java.lang.ThreadGroup#setMaxPriority(int)
|
|---|
| 257 | **/
|
|---|
| 258 | public void checkAccess(ThreadGroup g) {
|
|---|
| 259 | throw new SecurityException("Cannot modify ThreadGroups.");
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | /** Check if the current thread is allowed to exit the
|
|---|
| 263 | ** JVM with the given status.<P>
|
|---|
| 264 | **
|
|---|
| 265 | ** This method is called from Runtime.exit().<P>
|
|---|
| 266 | **
|
|---|
| 267 | ** SecurityManager's implementation always denies access.
|
|---|
| 268 | **
|
|---|
| 269 | ** @param status the status to exit with
|
|---|
| 270 | ** @exception SecurityException if the operation is not
|
|---|
| 271 | ** permitted.
|
|---|
| 272 | ** @see java.lang.Runtime#exit()
|
|---|
| 273 | ** @see java.lang.Runtime#exit(int)
|
|---|
| 274 | **/
|
|---|
| 275 | public void checkExit(int status) {
|
|---|
| 276 | throw new SecurityException("Cannot exit JVM.");
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | /** Check if the current thread is allowed to execute the
|
|---|
| 280 | ** given program.<P>
|
|---|
| 281 | **
|
|---|
| 282 | ** This method is called from Runtime.exec().<P>
|
|---|
| 283 | **
|
|---|
| 284 | ** SecurityManager's implementation always denies access.
|
|---|
| 285 | **
|
|---|
| 286 | ** @param program the name of the program to exec
|
|---|
| 287 | ** @exception SecurityException if the operation is not
|
|---|
| 288 | ** permitted.
|
|---|
| 289 | ** @see java.lang.Runtime#exec(java.lang.String[],java.lang.String[])
|
|---|
| 290 | **/
|
|---|
| 291 | public void checkExec(String program) {
|
|---|
| 292 | throw new SecurityException("Cannot execute programs.");
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | /** Check if the current thread is allowed to link in the
|
|---|
| 296 | ** given native library.<P>
|
|---|
| 297 | **
|
|---|
| 298 | ** This method is called from Runtime.load() (and hence,
|
|---|
| 299 | ** by loadLibrary() as well).<P>
|
|---|
| 300 | **
|
|---|
| 301 | ** SecurityManager's implementation always denies access.
|
|---|
| 302 | **
|
|---|
| 303 | ** @param filename the full name of the library to load
|
|---|
| 304 | ** @exception SecurityException if the operation is not
|
|---|
| 305 | ** permitted.
|
|---|
| 306 | ** @see java.lang.Runtime#load(java.lang.String)
|
|---|
| 307 | **/
|
|---|
| 308 | public void checkLink(String filename) {
|
|---|
| 309 | throw new SecurityException("Cannot link native libraries.");
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | /** Check if the current thread is allowed to read the
|
|---|
| 313 | ** given file using the FileDescriptor.<P>
|
|---|
| 314 | **
|
|---|
| 315 | ** This method is called from
|
|---|
| 316 | ** FileInputStream.FileInputStream().<P>
|
|---|
| 317 | **
|
|---|
| 318 | ** SecurityManager's implementation always denies access.
|
|---|
| 319 | **
|
|---|
| 320 | ** @param desc the FileDescriptor representing the file
|
|---|
| 321 | ** to access
|
|---|
| 322 | ** @exception SecurityException if the operation is not
|
|---|
| 323 | ** permitted.
|
|---|
| 324 | ** @see java.io.FileInputStream#FileInputStream(java.io.FileDescriptor)
|
|---|
| 325 | **/
|
|---|
| 326 | public void checkRead(FileDescriptor desc) {
|
|---|
| 327 | throw new SecurityException("Cannot read files via file descriptors.");
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | /** Check if the current thread is allowed to read the
|
|---|
| 331 | ** given file.<P>
|
|---|
| 332 | **
|
|---|
| 333 | ** This method is called from
|
|---|
| 334 | ** FileInputStream.FileInputStream(),
|
|---|
| 335 | ** RandomAccessFile.RandomAccessFile(), File.exists(),
|
|---|
| 336 | ** canRead(), isFile(), isDirectory(), lastModified(),
|
|---|
| 337 | ** length() and list().<P>
|
|---|
| 338 | **
|
|---|
| 339 | ** SecurityManager's implementation always denies access.
|
|---|
| 340 | **
|
|---|
| 341 | ** @param filename the full name of the file to access
|
|---|
| 342 | ** @exception SecurityException if the operation is not
|
|---|
| 343 | ** permitted.
|
|---|
| 344 | ** @see java.io.File
|
|---|
| 345 | ** @see java.io.FileInputStream#FileInputStream(java.lang.String)
|
|---|
| 346 | ** @see java.io.RandomAccessFile#RandomAccessFile(java.lang.String)
|
|---|
| 347 | **/
|
|---|
| 348 | public void checkRead(String filename) {
|
|---|
| 349 | throw new SecurityException("Cannot read files via file names.");
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | /** Check if the current thread is allowed to read the
|
|---|
| 353 | ** given file. using the given SecurityContext.<P>
|
|---|
| 354 | **
|
|---|
| 355 | ** I know of no core class that calls this method.<P>
|
|---|
| 356 | **
|
|---|
| 357 | ** SecurityManager's implementation always denies access.
|
|---|
| 358 | **
|
|---|
| 359 | ** @param filename the full name of the file to access
|
|---|
| 360 | ** @param securityContext the Security Context to
|
|---|
| 361 | ** determine access for.
|
|---|
| 362 | ** @exception SecurityException if the operation is not
|
|---|
| 363 | ** permitted.
|
|---|
| 364 | **/
|
|---|
| 365 | public void checkRead(String filename, Object securityContext) {
|
|---|
| 366 | throw new SecurityException("Cannot read files via file names.");
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | /** Check if the current thread is allowed to write to the
|
|---|
| 370 | ** given file using the FileDescriptor.<P>
|
|---|
| 371 | **
|
|---|
| 372 | ** This method is called from
|
|---|
| 373 | ** FileOutputStream.FileOutputStream().<P>
|
|---|
| 374 | **
|
|---|
| 375 | ** SecurityManager's implementation always denies access.
|
|---|
| 376 | **
|
|---|
| 377 | ** @param desc the FileDescriptor representing the file
|
|---|
| 378 | ** to access
|
|---|
| 379 | ** @exception SecurityException if the operation is not
|
|---|
| 380 | ** permitted.
|
|---|
| 381 | ** @see java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor)
|
|---|
| 382 | **/
|
|---|
| 383 | public void checkWrite(FileDescriptor desc) {
|
|---|
| 384 | throw new SecurityException("Cannot write files via file descriptors.");
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | /** Check if the current thread is allowed to write to the
|
|---|
| 388 | ** given file.<P>
|
|---|
| 389 | **
|
|---|
| 390 | ** This method is called from
|
|---|
| 391 | ** FileOutputStream.FileOutputStream(),
|
|---|
| 392 | ** RandomAccessFile.RandomAccessFile(),
|
|---|
| 393 | ** File.canWrite(), mkdir(), and renameTo().<P>
|
|---|
| 394 | **
|
|---|
| 395 | ** SecurityManager's implementation always denies access.
|
|---|
| 396 | **
|
|---|
| 397 | ** @param filename the full name of the file to access
|
|---|
| 398 | ** @exception SecurityException if the operation is not
|
|---|
| 399 | ** permitted.
|
|---|
| 400 | ** @see java.io.File#canWrite()
|
|---|
| 401 | ** @see java.io.File#mkdir()
|
|---|
| 402 | ** @see java.io.File#renameTo()
|
|---|
| 403 | ** @see java.io.FileOutputStream#FileOutputStream(java.lang.String)
|
|---|
| 404 | ** @see java.io.RandomAccessFile#RandomAccessFile(java.lang.String)
|
|---|
| 405 | **/
|
|---|
| 406 | public void checkWrite(String filename) {
|
|---|
| 407 | throw new SecurityException("Cannot write files via file names.");
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | /** Check if the current thread is allowed to delete the
|
|---|
| 411 | ** given file.<P>
|
|---|
| 412 | **
|
|---|
| 413 | ** This method is called from File.delete().<P>
|
|---|
| 414 | **
|
|---|
| 415 | ** SecurityManager's implementation always denies access.
|
|---|
| 416 | **
|
|---|
| 417 | ** @param filename the full name of the file to delete
|
|---|
| 418 | ** @exception SecurityException if th operation is not
|
|---|
| 419 | ** permitted.
|
|---|
| 420 | ** @see java.io.File#delete()
|
|---|
| 421 | **/
|
|---|
| 422 | public void checkDelete(String filename) {
|
|---|
| 423 | throw new SecurityException("Cannot delete files.");
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | /** Check if the current thread is allowed to connect to a
|
|---|
| 427 | ** given host on a given port.<P>
|
|---|
| 428 | **
|
|---|
| 429 | ** This method is called from Socket.Socket().
|
|---|
| 430 | **
|
|---|
| 431 | ** SecurityManager's implementation always denies access.
|
|---|
| 432 | **
|
|---|
| 433 | ** @param host the host to connect to
|
|---|
| 434 | ** @param port the port to connect on
|
|---|
| 435 | ** @exception SecurityException if the operation is not
|
|---|
| 436 | ** permitted
|
|---|
| 437 | ** @see java.net.Socket#Socket()
|
|---|
| 438 | **/
|
|---|
| 439 | public void checkConnect(String host, int port) {
|
|---|
| 440 | throw new SecurityException("Cannot make network connections.");
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | /** Check if the current thread is allowed to connect to a
|
|---|
| 444 | ** given host on a given port using a specific security
|
|---|
| 445 | ** context to determine access.<P>
|
|---|
| 446 | **
|
|---|
| 447 | ** This method is not called in the 1.1 core classes.<P>
|
|---|
| 448 | **
|
|---|
| 449 | ** SecurityManager's implementation always denies access.
|
|---|
| 450 | **
|
|---|
| 451 | ** @param host the host to connect to
|
|---|
| 452 | ** @param port the port to connect on
|
|---|
| 453 | ** @param securityContext the security context to
|
|---|
| 454 | ** determine access with
|
|---|
| 455 | ** @exception SecurityException if the operation is not
|
|---|
| 456 | ** permitted
|
|---|
| 457 | **/
|
|---|
| 458 | public void checkConnect(String host, int port, Object securityContext) {
|
|---|
| 459 | throw new SecurityException("Cannot make network connections.");
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | /** Check if the current thread is allowed to listen to a
|
|---|
| 463 | ** specific port for data.<P>
|
|---|
| 464 | **
|
|---|
| 465 | ** This method is called by ServerSocket.ServerSocket().<P>
|
|---|
| 466 | **
|
|---|
| 467 | ** SecurityManager's implementation always denies access.
|
|---|
| 468 | **
|
|---|
| 469 | ** @param port the port to listen on
|
|---|
| 470 | ** @exception SecurityException if the operation is not
|
|---|
| 471 | ** permitted
|
|---|
| 472 | ** @see java.net.ServerSocket#ServerSocket(int)
|
|---|
| 473 | **/
|
|---|
| 474 | public void checkListen(int port) {
|
|---|
| 475 | throw new SecurityException("Cannot listen for connections.");
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | /** Check if the current thread is allowed to accept a
|
|---|
| 479 | ** connection from a particular host on a particular
|
|---|
| 480 | ** port.<P>
|
|---|
| 481 | **
|
|---|
| 482 | ** This method is called by ServerSocket.implAccept().<P>
|
|---|
| 483 | **
|
|---|
| 484 | ** SecurityManager's implementation always denies access.
|
|---|
| 485 | **
|
|---|
| 486 | ** @param host the host which wishes to connect
|
|---|
| 487 | ** @param port the port the connection will be on
|
|---|
| 488 | ** @exception SecurityException if the operation is not
|
|---|
| 489 | ** permitted
|
|---|
| 490 | ** @see java.net.ServerSocket#accept()
|
|---|
| 491 | **/
|
|---|
| 492 | public void checkAccept(String host, int port) {
|
|---|
| 493 | throw new SecurityException("Cannot accept connections.");
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | /** Check if the current thread is allowed to read and
|
|---|
| 497 | ** write multicast to a particular address.<P>
|
|---|
| 498 | **
|
|---|
| 499 | ** SecurityManager's implementation always denies access.
|
|---|
| 500 | **
|
|---|
| 501 | ** @XXX where is it called?
|
|---|
| 502 | **
|
|---|
| 503 | ** @param addr the address to multicast to.
|
|---|
| 504 | ** @exception SecurityException if the operation is not
|
|---|
| 505 | ** permitted.
|
|---|
| 506 | **/
|
|---|
| 507 | public void checkMulticast(InetAddress addr) {
|
|---|
| 508 | throw new SecurityException("Cannot read or write multicast.");
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 | /** Check if the current thread is allowed to read and
|
|---|
| 512 | ** write multicast to a particular address with a
|
|---|
| 513 | ** particular ttl value.<P>
|
|---|
| 514 | **
|
|---|
| 515 | ** SecurityManager's implementation always denies access.<P>
|
|---|
| 516 | **
|
|---|
| 517 | ** @XXX where is it called?
|
|---|
| 518 | **
|
|---|
| 519 | ** @XXX what the hell is ttl? Expand abbreviation.
|
|---|
| 520 | **
|
|---|
| 521 | ** @param addr the address to multicast to.
|
|---|
| 522 | ** @param ttl the ttl value to use
|
|---|
| 523 | ** @exception SecurityException if the operation is not
|
|---|
| 524 | ** permitted.
|
|---|
| 525 | **/
|
|---|
| 526 | public void checkMulticast(InetAddress addr, byte ttl) {
|
|---|
| 527 | throw new SecurityException("Cannot read or write multicast.");
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | /**
|
|---|
| 531 | ** Check if the current thread is allowed to perform an
|
|---|
| 532 | ** operation that requires the specified <code>Permission</code>.
|
|---|
| 533 | **
|
|---|
| 534 | ** @param perm The <code>Permission</code> required.
|
|---|
| 535 | ** @exception SecurityException If the operation is not allowed.
|
|---|
| 536 | **/
|
|---|
| 537 | public void checkPermission(java.security.Permission perm) {
|
|---|
| 538 | throw new SecurityException("Operation not allowed");
|
|---|
| 539 | }
|
|---|
| 540 |
|
|---|
| 541 | /**
|
|---|
| 542 | ** Check if the current thread is allowed to perform an
|
|---|
| 543 | ** operation that requires the specified <code>Permission</code>.
|
|---|
| 544 | **
|
|---|
| 545 | ** @param perm The <code>Permission</code> required.
|
|---|
| 546 | ** @param context A security context
|
|---|
| 547 | ** @exception SecurityException If the operation is not allowed.
|
|---|
| 548 | ** @since 1.2
|
|---|
| 549 | **/
|
|---|
| 550 | public void checkPermission(java.security.Permission perm,
|
|---|
| 551 | Object context) {
|
|---|
| 552 | throw new SecurityException("Operation not allowed");
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | /** Check if the current thread is allowed to read or
|
|---|
| 556 | ** write all the system properties at once.<P>
|
|---|
| 557 | **
|
|---|
| 558 | ** This method is called by System.getProperties()
|
|---|
| 559 | ** and setProperties().<P>
|
|---|
| 560 | **
|
|---|
| 561 | ** SecurityManager's implementation always denies access.
|
|---|
| 562 | **
|
|---|
| 563 | ** @exception SecurityException if the operation is not
|
|---|
| 564 | ** permitted.
|
|---|
| 565 | ** @see java.lang.System#getProperties()
|
|---|
| 566 | ** @see java.lang.System#setProperties(java.util.Properties)
|
|---|
| 567 | **/
|
|---|
| 568 | public void checkPropertiesAccess() {
|
|---|
| 569 | throw new SecurityException("Cannot access all system properties at once.");
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | /** Check if the current thread is allowed to read or
|
|---|
| 573 | ** write a particular system property.<P>
|
|---|
| 574 | **
|
|---|
| 575 | ** This method is called by System.getProperty() and
|
|---|
| 576 | ** setProperty().<P>
|
|---|
| 577 | **
|
|---|
| 578 | ** SecurityManager's implementation always denies access.
|
|---|
| 579 | **
|
|---|
| 580 | ** @exception SecurityException is the operation is not
|
|---|
| 581 | ** permitted.
|
|---|
| 582 | ** @see java.lang.System#getProperty(java.lang.String)
|
|---|
| 583 | ** @see java.lang.System#setProperty(java.lang.String,java.lang.String)
|
|---|
| 584 | **/
|
|---|
| 585 | public void checkPropertyAccess(String name) {
|
|---|
| 586 | throw new SecurityException("Cannot access individual system properties.");
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | /** Check if the current thread is allowed to create a
|
|---|
| 590 | ** top-level window. If it is not, the operation should
|
|---|
| 591 | ** still go through, but some sort of nonremovable
|
|---|
| 592 | ** warning should be placed on the window to show that it
|
|---|
| 593 | ** is untrusted.<P>
|
|---|
| 594 | **
|
|---|
| 595 | ** This method is called by Window.Window().<P>
|
|---|
| 596 | **
|
|---|
| 597 | ** SecurityManager's implementation always denies access.
|
|---|
| 598 | **
|
|---|
| 599 | ** @param window the window to create
|
|---|
| 600 | ** @see java.awt.Window#Window(java.awt.Frame)
|
|---|
| 601 | **/
|
|---|
| 602 | public boolean checkTopLevelWindow(Object window) {
|
|---|
| 603 | return false;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | /** Check if the current thread is allowed to create a
|
|---|
| 607 | ** print job.<P>
|
|---|
| 608 | **
|
|---|
| 609 | ** This method is called by Toolkit.getPrintJob(). (I
|
|---|
| 610 | ** assume so, at least, it just don't say nothing about
|
|---|
| 611 | ** it in the spec.)<P>
|
|---|
| 612 | **
|
|---|
| 613 | ** SecurityManager's implementation always denies access.
|
|---|
| 614 | **
|
|---|
| 615 | ** @exception SecurityException if the operation is not
|
|---|
| 616 | ** permitted.
|
|---|
| 617 | ** @see java.awt.Toolkit.getPrintJob(java.awt.Frame,java.lang.String,java.util.Properties)
|
|---|
| 618 | **/
|
|---|
| 619 | public void checkPrintJobAccess() {
|
|---|
| 620 | throw new SecurityException("Cannot create print jobs.");
|
|---|
| 621 | }
|
|---|
| 622 |
|
|---|
| 623 | /** Check if the current thread is allowed to use the
|
|---|
| 624 | ** system clipboard.<P>
|
|---|
| 625 | **
|
|---|
| 626 | ** This method is called by Toolkit.getSystemClipboard().
|
|---|
| 627 | ** (I assume.)<P>
|
|---|
| 628 | **
|
|---|
| 629 | ** SecurityManager's implementation always denies access.
|
|---|
| 630 | **
|
|---|
| 631 | ** @exception SecurityException if the operation is not
|
|---|
| 632 | ** permitted.
|
|---|
| 633 | ** @see java.awt.Toolkit#getSystemClipboard()
|
|---|
| 634 | **/
|
|---|
| 635 | public void checkSystemClipboardAccess() {
|
|---|
| 636 | throw new SecurityException("Cannot access the system clipboard.");
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 | /** Check if the current thread is allowed to use the AWT
|
|---|
| 640 | ** event queue.<P>
|
|---|
| 641 | **
|
|---|
| 642 | ** This method is called by Toolkit.getSystemEventQueue().<P>
|
|---|
| 643 | **
|
|---|
| 644 | ** SecurityManager's implementation always denies access.
|
|---|
| 645 | **
|
|---|
| 646 | ** @exception SecurityException if the operation is not
|
|---|
| 647 | ** permitted.
|
|---|
| 648 | ** @see java.awt.Toolkit#getSystemEventQueue()
|
|---|
| 649 | **/
|
|---|
| 650 | public void checkAwtEventQueueAccess() {
|
|---|
| 651 | throw new SecurityException("Cannot access the AWT event queue.");
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | /** Check if the current thread is allowed to access the
|
|---|
| 655 | ** specified package at all.<P>
|
|---|
| 656 | **
|
|---|
| 657 | ** This method is called by ClassLoader.loadClass() in
|
|---|
| 658 | ** user-created ClassLoaders.<P>
|
|---|
| 659 | **
|
|---|
| 660 | ** SecurityManager's implementation always denies access.
|
|---|
| 661 | **
|
|---|
| 662 | ** @param packageName the package name to check access to
|
|---|
| 663 | ** @exception SecurityException if the operation is not
|
|---|
| 664 | ** permitted.
|
|---|
| 665 | ** @see java.lang.ClassLoader#loadClass(java.lang.String,boolean)
|
|---|
| 666 | **/
|
|---|
| 667 | public void checkPackageAccess(String packageName) {
|
|---|
| 668 | throw new SecurityException("Cannot access packages via the ClassLoader.");
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | /** Check if the current thread is allowed to define
|
|---|
| 672 | ** classes the specified package. If the class already
|
|---|
| 673 | ** created, though, ClassLoader.loadClass() can still
|
|---|
| 674 | ** return the Class if checkPackageAccess() checks out.<P>
|
|---|
| 675 | **
|
|---|
| 676 | ** This method is called by ClassLoader.loadClass() in
|
|---|
| 677 | ** user-created ClassLoaders.<P>
|
|---|
| 678 | **
|
|---|
| 679 | ** SecurityManager's implementation always denies access.
|
|---|
| 680 | **
|
|---|
| 681 | ** @param packageName the package name to check access to
|
|---|
| 682 | ** @exception SecurityException if the operation is not
|
|---|
| 683 | ** permitted.
|
|---|
| 684 | ** @see java.lang.ClassLoader#loadClass(java.lang.String,boolean)
|
|---|
| 685 | **/
|
|---|
| 686 | public void checkPackageDefinition(String packageName) {
|
|---|
| 687 | throw new SecurityException("Cannot load classes into any packages via the ClassLoader.");
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | /** Check if the current thread is allowed to set the
|
|---|
| 691 | ** current socket factory.<P>
|
|---|
| 692 | **
|
|---|
| 693 | ** This method is called by Socket.setSocketImplFactory(),
|
|---|
| 694 | ** ServerSocket.setSocketFactory(), and
|
|---|
| 695 | ** URL.setURLStreamHandlerFactory().<P>
|
|---|
| 696 | **
|
|---|
| 697 | ** SecurityManager's implementation always denies access.
|
|---|
| 698 | **
|
|---|
| 699 | ** @exception SecurityException if the operation is not
|
|---|
| 700 | ** permitted.
|
|---|
| 701 | ** @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
|
|---|
| 702 | ** @see java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory)
|
|---|
| 703 | ** @see java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
|
|---|
| 704 | **/
|
|---|
| 705 | public void checkSetFactory() {
|
|---|
| 706 | throw new SecurityException("Cannot set the socket factory.");
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 | /** Check if the current thread is allowed to get certain
|
|---|
| 710 | ** types of Methods, Fields and Constructors from a Class
|
|---|
| 711 | ** object.<P>
|
|---|
| 712 | **
|
|---|
| 713 | ** This method is called by Class.getMethod[s](),
|
|---|
| 714 | ** Class.getField[s](), Class.getConstructor[s],
|
|---|
| 715 | ** Class.getDeclaredMethod[s](),
|
|---|
| 716 | ** Class.getDeclaredField[s](), and
|
|---|
| 717 | ** Class.getDeclaredConstructor[s]().<P>
|
|---|
| 718 | **
|
|---|
| 719 | ** SecurityManager's implementation always denies access.
|
|---|
| 720 | **
|
|---|
| 721 | ** @param c the Class to check
|
|---|
| 722 | ** @param memberType the type of members to check
|
|---|
| 723 | ** against, either Member.DECLARED or
|
|---|
| 724 | ** Member.PUBLIC.
|
|---|
| 725 | ** @exception SecurityException if the operation is not
|
|---|
| 726 | ** permitted.
|
|---|
| 727 | ** @see java.lang.Class
|
|---|
| 728 | ** @see java.lang.reflect.Member#DECLARED
|
|---|
| 729 | ** @see java.lang.reflect.Member#PUBLIC
|
|---|
| 730 | **/
|
|---|
| 731 | public void checkMemberAccess(Class c, int memberType) {
|
|---|
| 732 | throw new SecurityException("Cannot access members of classes.");
|
|---|
| 733 | }
|
|---|
| 734 |
|
|---|
| 735 | /** Test whether a particular security action may be
|
|---|
| 736 | ** taken.
|
|---|
| 737 | ** @param action the desired action to take
|
|---|
| 738 | ** @exception SecurityException if the action is denied.
|
|---|
| 739 | ** @XXX I have no idea what actions must be tested
|
|---|
| 740 | ** or where.
|
|---|
| 741 | **/
|
|---|
| 742 | public void checkSecurityAccess(String action) {
|
|---|
| 743 | checkPermission (new java.security.SecurityPermission (action));
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | /** Get the ThreadGroup that a new Thread should belong
|
|---|
| 747 | ** to by default.<P>
|
|---|
| 748 | **
|
|---|
| 749 | ** Called by Thread.Thread().<P>
|
|---|
| 750 | **
|
|---|
| 751 | ** SecurityManager's implementation just uses the
|
|---|
| 752 | ** ThreadGroup of the current Thread.<P>
|
|---|
| 753 | **
|
|---|
| 754 | ** <STRONG>Spec Note:</STRONG> it is not clear whether
|
|---|
| 755 | ** the new Thread is guaranteed to pass the
|
|---|
| 756 | ** checkAccessThreadGroup() test when using this
|
|---|
| 757 | ** ThreadGroup. I presume so.
|
|---|
| 758 | **
|
|---|
| 759 | ** @return the ThreadGroup to put the new Thread into.
|
|---|
| 760 | **/
|
|---|
| 761 | public ThreadGroup getThreadGroup() {
|
|---|
| 762 | return Thread.currentThread().getThreadGroup();
|
|---|
| 763 | }
|
|---|
| 764 |
|
|---|
| 765 | public SecurityManager () {
|
|---|
| 766 | if (System.getSecurityManager () != null)
|
|---|
| 767 | throw new SecurityException ();
|
|---|
| 768 | }
|
|---|
| 769 | }
|
|---|
| 770 |
|
|---|
| 771 | class SecurityContext {
|
|---|
| 772 | Class[] classes;
|
|---|
| 773 | SecurityContext(Class[] classes) {
|
|---|
| 774 | this.classes = classes;
|
|---|
| 775 | }
|
|---|
| 776 | }
|
|---|