home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / SecurityManager.java < prev    next >
Text File  |  1997-05-20  |  33KB  |  847 lines

  1. /*
  2.  * @(#)SecurityManager.java    1.48 97/03/10
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.lang;
  24.  
  25. import java.io.FileDescriptor;
  26. import java.util.Hashtable;
  27. import java.net.InetAddress;
  28. import java.lang.reflect.Member;
  29.  
  30. /**
  31.  * The security manager is an abstract class that allows 
  32.  * applications to implement a security policy. It allows an 
  33.  * application to determine, before performing a possibly unsafe or 
  34.  * sensitive operation, what the operation is and whether the 
  35.  * operation is being performed by a class created via a class loader 
  36.  * rather than installed locally. Classes loaded via a class loader 
  37.  * (especially if they have been downloaded over a network) may be 
  38.  * less trustworthy than classes from files installed locally. The 
  39.  * application can allow or disallow the operation. 
  40.  * <p>
  41.  * The <code>SecurityManager</code> class contains many methods with 
  42.  * names that begin with the word <code>check</code>. These methods 
  43.  * are called by various methods in the Java libraries before those 
  44.  * methods perform certain potentially sensitive operations. The 
  45.  * invocation of such a check method typically looks like this: 
  46.  * <p><blockquote><pre>
  47.  *     SecurityManager security = System.getSecurityManager();
  48.  *     if (security != null) {
  49.  *         security.check</code><i>XXX</i><code>(argument,  . . . );
  50.  *     }
  51.  * </pre></blockquote>
  52.  * <p>
  53.  * The security manager is thereby given an opportunity to prevent 
  54.  * completion of the operation by throwing an exception. A security 
  55.  * manager routine simply returns if the operation is permitted, but 
  56.  * throws a <code>SecurityException</code> if the operation is not 
  57.  * permitted. The only exception to this convention is 
  58.  * <code>checkTopLevelWindow</code>, which returns a 
  59.  * <code>boolean</code> value. 
  60.  * <p>
  61.  * The current security manager is set by the 
  62.  * <code>setSecurityManager</code> method in class 
  63.  * <code>System</code>. The current security manager is obtained 
  64.  * by the <code>getSecurityManager</code> method. 
  65.  * <p>
  66.  * The default implementation of each of the 
  67.  * <code>check</code><i>XXX</i> methods is to assume that the caller 
  68.  * does <i>not</i> have permission to perform the requested operation. 
  69.  *
  70.  * @author  Arthur van Hoff
  71.  * @version 1.48, 03/10/97
  72.  * @see     java.lang.ClassLoader
  73.  * @see     java.lang.SecurityException
  74.  * @see     java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
  75.  * @see     java.lang.System#getSecurityManager()
  76.  * @see     java.lang.System#setSecurityManager(java.lang.SecurityManager)
  77.  * @since   JDK1.0
  78.  */
  79. public abstract
  80. class SecurityManager {
  81.    /**
  82.      * This field is <code>true</code> if there is a security check in 
  83.      * progress; <code>false</code> otherwise. 
  84.      *
  85.      * @since   JDK1.0
  86.      */
  87.     protected boolean inCheck;
  88.  
  89.     /* 
  90.      * Have we been initialized. Effective against finalizer attacks.
  91.      */
  92.     private boolean initialized = false;
  93.  
  94.     /** 
  95.      * Tests if there is a security check in progress.
  96.      *
  97.      * @return  the value of the <code>inCheck</code> field. This field should
  98.      *          contain <code>true</code> if a security check is in progress;
  99.      *          <code>false</code> otherwise.
  100.      * @see     java.lang.SecurityManager#inCheck
  101.      * @since   JDK1.0
  102.      */
  103.     public boolean getInCheck() {
  104.     return inCheck;
  105.     }
  106.  
  107.     /**
  108.      * Constructs a new <code>SecurityManager</code>. An application is 
  109.      * not allowed to create a new security manager if there is already a 
  110.      * current security manager. 
  111.      *
  112.      * @exception  SecurityException  if a security manager already exists.
  113.      * @see        java.lang.System#getSecurityManager()
  114.      * @since      JDK1.0
  115.      */
  116.     protected SecurityManager() {
  117.     if (System.getSecurityManager() != null) {
  118.         throw new SecurityException("security manager already installed.");
  119.     }
  120.     initialized = true;
  121.     }
  122.  
  123.     /**
  124.      * Returns the current execution stack as an array of classes. 
  125.      * <p>
  126.      * The length of the array is the number of methods on the execution 
  127.      * stack. The element at index <code>0</code> is the class of the 
  128.      * currently executing method, the element at index <code>1</code> is 
  129.      * the class of that method's caller, and so on. 
  130.      *
  131.      * @return  the execution stack.
  132.      * @since   JDK1.0
  133.      */
  134.     protected native Class[] getClassContext();
  135.  
  136.     /**
  137.      * Returns an object describing the most recent class loader executing
  138.      * on the stack. 
  139.      *
  140.      * @return  the class loader of the most recent occurrence on the stack
  141.      *          of a method from a class defined using a class loader;
  142.      *          returns <code>null</code> if there is no occurrence on the
  143.      *          stack of a method from a class defined using a class loader.
  144.      * @since   JDK1.0
  145.      */
  146.     protected native ClassLoader currentClassLoader();
  147.  
  148.     /**
  149.      * Returns the current Class with a ClassLoader on the execution stack.
  150.      *
  151.      * @since   JDK1.1
  152.      */
  153.     protected Class currentLoadedClass() {
  154.     return currentLoadedClass0();    
  155.     }
  156.  
  157.     /**
  158.      * Returns the stack depth of the specified class. 
  159.      *
  160.      * @param   name   the fully qualified name of the class to search for.
  161.      * @return  the depth on the stack frame of the first occurrence of a
  162.      *          method from a class with the specified name;
  163.      *          <code>-1</code> if such a frame cannot be found.
  164.      * @since   JDK1.0
  165.      */
  166.     protected native int classDepth(String name);
  167.  
  168.     /**
  169.      * Returns the stack depth of the most recently executing method 
  170.      * from a class defined using a class loader. 
  171.      *
  172.      * @return  the depth on the stack frame of the most recent occurrence of a
  173.      *          method from a class defined using a class loader; returns
  174.      *          <code>-1</code> if there is no occurrence of a method from
  175.      *          a class defined using a class loader.
  176.      * @since   JDK1.0
  177.      */
  178.     protected native int classLoaderDepth();
  179.  
  180.     /**
  181.      * Tests if the specified String is in this Class. 
  182.      *
  183.      * @param   name   the fully qualified name of the class.
  184.      * @return  <code>true</code> if a method from a class with the specified
  185.      *          name is on the execution stack; <code>false</code> otherwise.
  186.      * @since   JDK1.0
  187.      */
  188.     protected boolean inClass(String name) {
  189.     return classDepth(name) >= 0;
  190.     }
  191.  
  192.     /**
  193.      * Tests if the current ClassLoader is equal to
  194.      * <code>null</code>.
  195.      *
  196.      * @return  <code>true</code> if a method from a class defined using a
  197.      *          class loader is on the execution stack.
  198.      * @since   JDK1.0
  199.      */
  200.     protected boolean inClassLoader() {
  201.     return currentClassLoader() != null;
  202.     }
  203.  
  204.     /**
  205.      * Creates an object that encapsulates the current execution 
  206.      * environment. The result of this method is used by the 
  207.      * three-argument <code>checkConnect</code> method and by the 
  208.      * two-argument <code>checkRead</code> method. 
  209.      * <p>
  210.      * These methods are needed because a trusted method may be called 
  211.      * on to read a file or open a socket on behalf of another method. 
  212.      * The trusted method needs to determine if the other (possibly 
  213.      * untrusted) method would be allowed to perform the operation on its 
  214.      * own. 
  215.      *
  216.      * @return  an implementation-dependent object that encapsulates
  217.      *          sufficient information about the current execution environment
  218.      *          to perform some security checks later.
  219.      * @see     java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object)
  220.      * @see     java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object)
  221.      * @since   JDK1.0
  222.      */
  223.     public Object getSecurityContext() {
  224.     return null;
  225.     }
  226.  
  227.     /**
  228.      * Throws a <code>SecurityException</code> if the 
  229.      * calling thread is not allowed to create a new class loader. 
  230.      * <p>
  231.      * The <code>checkCreateClassLoader</code> method for class 
  232.      * <code>SecurityManager</code> always throws a 
  233.      * <code>SecurityException</code>. 
  234.      *
  235.      * @exception  SecurityException  if the caller does not have permission
  236.      *             to create a new class loader.
  237.      * @see        java.lang.ClassLoader#ClassLoader()
  238.      * @since      JDK1.0
  239.      */
  240.     public void checkCreateClassLoader() {
  241.     throw new SecurityException();
  242.     }
  243.     
  244.     /**
  245.      * Throws a <code>SecurityException</code> if the 
  246.      * calling thread is not allowed to modify the thread argument. 
  247.      * <p>
  248.      * This method is invoked for the current security manager by the 
  249.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, 
  250.      * <code>setPriority</code>, <code>setName</code>, and 
  251.      * <code>setDaemon</code> methods of class <code>Thread</code>. 
  252.      * <p>
  253.      * The <code>checkAccess</code> method for class 
  254.      * <code>SecurityManager</code> always throws a 
  255.      * <code>SecurityException</code>. 
  256.      *
  257.      * @param      g   the thread to be checked.
  258.  
  259.      * @exception  SecurityException  if the caller does not have permission
  260.      *               to modify the thread.
  261.      * @see        java.lang.System#getSecurityManager()
  262.      * @see        java.lang.Thread#resume()
  263.      * @see        java.lang.Thread#setDaemon(boolean)
  264.      * @see        java.lang.Thread#setName(java.lang.String)
  265.      * @see        java.lang.Thread#setPriority(int)
  266.      * @see        java.lang.Thread#stop()
  267.      * @see        java.lang.Thread#suspend()
  268.      * @since      JDK1.0
  269.      */
  270.     public void checkAccess(Thread g) {
  271.     throw new SecurityException();
  272.     }
  273.  
  274.     /**
  275.      * Throws a <code>SecurityException</code> if the 
  276.      * calling thread is not allowed to modify the thread group argument. 
  277.      * <p>
  278.      * This method is invoked for the current security manager when a 
  279.      * new child thread or child thread group is created, and by the 
  280.      * <code>setDaemon</code>, <code>setMaxPriority</code>, 
  281.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, and 
  282.      * <code>destroy</code> methods of class <code>ThreadGroup</code>. 
  283.      * <p>
  284.      * The <code>checkAccess</code> method for class 
  285.      * <code>SecurityManager</code> always throws a 
  286.      * <code>SecurityException</code>. 
  287.      *
  288.      * @param      g   the thread group to be checked.
  289.      * @exception  SecurityException  if the caller does not have permission
  290.      *               to modify the thread group.
  291.      * @see        java.lang.System#getSecurityManager()
  292.      * @see        java.lang.ThreadGroup#destroy()
  293.      * @see        java.lang.ThreadGroup#resume()
  294.      * @see        java.lang.ThreadGroup#setDaemon(boolean)
  295.      * @see        java.lang.ThreadGroup#setMaxPriority(int)
  296.      * @see        java.lang.ThreadGroup#stop()
  297.      * @see        java.lang.ThreadGroup#suspend()
  298.      * @since      JDK1.0
  299.      */
  300.     public void checkAccess(ThreadGroup g) {
  301.     throw new SecurityException();
  302.     }
  303.  
  304.     /**
  305.      * Throws a <code>SecurityException</code> if the 
  306.      * calling thread is not allowed to cause the Java Virtual Machine to 
  307.      * halt with the specified status code. 
  308.      * <p>
  309.      * This method is invoked for the current security manager by the 
  310.      * <code>exit</code> method of class <code>Runtime</code>. A status 
  311.      * of <code>0</code> indicates success; other values indicate various 
  312.      * errors. 
  313.      * <p>
  314.      * The <code>checkExit</code> method for class 
  315.      * <code>SecurityManager</code> always throws a 
  316.      * <code>SecurityException</code>. 
  317.      *
  318.      * @param      status   the exit status.
  319.      * @exception  SecurityException  if the caller does not have permission
  320.      *               to halt the Java Virtual Machine with the specified status.
  321.      * @see        java.lang.Runtime#exit(int)
  322.      * @see        java.lang.System#getSecurityManager()
  323.      * @since      JDK1.0
  324.      */
  325.     public void checkExit(int status) {
  326.     throw new SecurityException();
  327.     }
  328.  
  329.     /**
  330.      * Throws a <code>SecurityException</code> if the 
  331.      * calling thread is not allowed to create a subprocss. 
  332.      * <p>
  333.      * This method is invoked for the current security manager by the 
  334.      * <code>exec</code> methods of class <code>Runtime</code>.
  335.      * <p>
  336.      * The <code>checkExec</code> method for class 
  337.      * <code>SecurityManager</code> always throws a 
  338.      * <code>SecurityException</code>. 
  339.      *
  340.      * @param      cmd   the specified system command.
  341.      * @exception  SecurityException  if the caller does not have permission
  342.      *               to create a subprocess.
  343.      * @see        java.lang.Runtime#exec(java.lang.String)
  344.      * @see        java.lang.Runtime#exec(java.lang.String, java.lang.String[])
  345.      * @see        java.lang.Runtime#exec(java.lang.String[])
  346.      * @see        java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
  347.      * @see        java.lang.System#getSecurityManager()
  348.      * @since      JDK1.0
  349.      */
  350.     public void checkExec(String cmd) {
  351.     throw new SecurityException();
  352.     }
  353.  
  354.     /**
  355.      * Throws a <code>SecurityException</code> if the 
  356.      * calling thread is not allowed to dynamic link the library code 
  357.      * specified by the string argument file. The argument is either a 
  358.      * simple library name or a complete filename. 
  359.      * <p>
  360.      * This method is invoked for the current security manager by 
  361.      * methods <code>load</code> and <code>loadLibrary</code> of class 
  362.      * <code>Runtime</code>. 
  363.      * <p>
  364.      * The <code>checkLink</code> method for class 
  365.      * <code>SecurityManager</code> always throws a 
  366.      * <code>SecurityException</code>. 
  367.      *
  368.      * @param      lib   the name of the library.
  369.      * @exception  SecurityException  if the caller does not have permission
  370.      *               to dynamically link the library.
  371.      * @see        java.lang.Runtime#load(java.lang.String)
  372.      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
  373.      * @see        java.lang.System#getSecurityManager()
  374.      * @since      JDK1.0
  375.      */
  376.     public void checkLink(String lib) {
  377.     throw new SecurityException();
  378.     }
  379.  
  380.     /**
  381.      * Throws a <code>SecurityException</code> if the 
  382.      * calling thread is not allowed to read from the specified file 
  383.      * descriptor. 
  384.      * <p>
  385.      * The <code>checkRead</code> method for class 
  386.      * <code>SecurityManager</code> always throws a 
  387.      * <code>SecurityException</code>. 
  388.      *
  389.      * @param      fd   the system-dependent file descriptor.
  390.      * @exception  SecurityException  if the caller does not have permission
  391.      *               to access the specified file descriptor.
  392.      * @see        java.io.FileDescriptor
  393.      * @since      JDK1.0
  394.      */
  395.     public void checkRead(FileDescriptor fd) {
  396.     throw new SecurityException();
  397.     }
  398.  
  399.     /**
  400.      * Throws a <code>SecurityException</code> if the 
  401.      * calling thread is not allowed to read the file specified by the 
  402.      * string argument. 
  403.      * <p>
  404.      * The <code>checkRead</code> method for class 
  405.      * <code>SecurityManager</code> always throws a 
  406.      * <code>SecurityException</code>. 
  407.      *
  408.      * @param      file   the system-dependent file name.
  409.      * @exception  SecurityException  if the caller does not have permission
  410.      *               to access the specified file.
  411.      * @since   JDK1.0
  412.      */
  413.     public void checkRead(String file) {
  414.     throw new SecurityException();
  415.     }
  416.  
  417.     /**
  418.      * Throws a <code>SecurityException</code> if the 
  419.      * specified security context is not allowed to read the file 
  420.      * specified by the string argument. The context must be a security 
  421.      * context returned by a previous call to 
  422.      * <code>getSecurityContext</code>. 
  423.      * <p>
  424.      * The <code>checkRead</code> method for class 
  425.      * <code>SecurityManager</code> always throws a 
  426.      * <code>SecurityException</code>. 
  427.      *
  428.      * @param      file      the system-dependent filename.
  429.      * @param      context   a system-dependent security context.
  430.      * @exception  SecurityException  if the specified security context does
  431.      *               not have permission to read the specified file.
  432.      * @see        java.lang.SecurityManager#getSecurityContext()
  433.      * @since      JDK1.0
  434.      */
  435.     public void checkRead(String file, Object context) {
  436.     throw new SecurityException();
  437.     }
  438.  
  439.     /**
  440.      * Throws a <code>SecurityException</code> if the 
  441.      * calling thread is not allowed to write to the specified file 
  442.      * descriptor. 
  443.      * <p>
  444.      * The <code>checkWrite</code> method for class 
  445.      * <code>SecurityManager</code> always throws a 
  446.      * <code>SecurityException</code>. 
  447.      *
  448.      * @param      fd   the system-dependent file descriptor.
  449.      * @exception  SecurityException  if the caller does not have permission
  450.      *               to access the specified file descriptor.
  451.      * @see        java.io.FileDescriptor
  452.      * @since      JDK1.0
  453.      */
  454.     public void checkWrite(FileDescriptor fd) {
  455.     throw new SecurityException();
  456.     }
  457.  
  458.     /**
  459.      * Throws a <code>SecurityException</code> if the 
  460.      * calling thread is not allowed to write to the file specified by 
  461.      * the string argument. 
  462.      * <p>
  463.      * The <code>checkWrite</code> method for class 
  464.      * <code>SecurityManager</code> always throws a 
  465.      * <code>SecurityException</code>. 
  466.      *
  467.      * @param      file   the system-dependent filename.
  468.      * @exception  SecurityException  if the caller does not have permission
  469.      *               to access the specified file.
  470.      * @since   JDK1.0
  471.      */
  472.     public void checkWrite(String file) {
  473.     throw new SecurityException();
  474.     }
  475.  
  476.     /**
  477.      * Throws a <code>SecurityException</code> if the 
  478.      * calling thread is not allowed to delete the specified file. 
  479.      * <p>
  480.      * This method is invoked for the current security manager by the 
  481.      * <code>delete</code> method of class <code>File</code>.
  482.      * <p>
  483.      * The <code>checkDelete</code> method for class 
  484.      * <code>SecurityManager</code> always throws a 
  485.      * <code>SecurityException</code>. 
  486.      *
  487.      * @param      file   the system-dependent filename.
  488.      * @exception  SecurityException  if the caller does not have permission
  489.      *               to delete the file.
  490.      * @see        java.io.File#delete()
  491.      * @see        java.lang.System#getSecurityManager()
  492.      * @since      JDK1.0
  493.      */
  494.     public void checkDelete(String file) {
  495.     throw new SecurityException();
  496.     }
  497.  
  498.     /**
  499.      * Throws a <code>SecurityException</code> if the 
  500.      * calling thread is not allowed to open a socket connection to the 
  501.      * specified host and port number. 
  502.      * <p>
  503.      * A port number of <code>-1</code> indicates that the calling 
  504.      * method is attempting to determine the IP address of the specified 
  505.      * host name. 
  506.      * <p>
  507.      * The <code>checkConnect</code> method for class 
  508.      * <code>SecurityManager</code> always throws a 
  509.      * <code>SecurityException</code>. 
  510.      *
  511.      * @param      host   the host name port to connect to.
  512.      * @param      port   the protocol port to connect to.
  513.      * @exception  SecurityException  if the caller does not have permission
  514.      *               to open a socket connection to the specified
  515.      *               <code>host</code> and <code>port</code>.
  516.      * @since      JDK1.0
  517.      */
  518.     public void checkConnect(String host, int port) {
  519.     throw new SecurityException();
  520.     }
  521.  
  522.     /**
  523.      * Throws a <code>SecurityException</code> if the 
  524.      * specified security context is not allowed to open a socket 
  525.      * connection to the specified host and port number. 
  526.      * <p>
  527.      * A port number of <code>-1</code> indicates that the calling 
  528.      * method is attempting to determine the IP address of the specified 
  529.      * host name. 
  530.      * <p>
  531.      * The <code>checkConnect</code> method for class 
  532.      * <code>SecurityManager</code> always throws a 
  533.      * <code>SecurityException</code>. 
  534.      *
  535.      * @param      host      the host name port to connect to.
  536.      * @param      port      the protocol port to connect to.
  537.      * @param      context   a system-dependent security context.
  538.      * @exception  SecurityException  if the specified security context does
  539.      *               not have permission to open a socket connection to the
  540.      *               specified <code>host</code> and <code>port</code>.
  541.      * @see        java.lang.SecurityManager#getSecurityContext()
  542.      * @since      JDK1.0
  543.      */
  544.     public void checkConnect(String host, int port, Object context) {
  545.     throw new SecurityException();
  546.     }
  547.  
  548.     /**
  549.      * Throws a <code>SecurityException</code> if the 
  550.      * calling thread is not allowed to wait for a connection request on 
  551.      * the specified local port number. 
  552.      * <p>
  553.      * The <code>checkListen</code> method for class 
  554.      * <code>SecurityManager</code> always throws a 
  555.      * <code>SecurityException</code>. 
  556.      *
  557.      * @param      port   the local port.
  558.      * @exception  SecurityException  if the caller does not have permission
  559.      *               to listen on the specified port.
  560.      * @since   JDK1.0
  561.      */
  562.     public void checkListen(int port) {
  563.     throw new SecurityException();
  564.     }
  565.  
  566.     /**
  567.      * Throws a <code>SecurityException</code> if the 
  568.      * calling thread is not permitted to accept a socket connection from 
  569.      * the specified host and port number. 
  570.      * <p>
  571.      * This method is invoked for the current security manager by the 
  572.      * <code>accept</code> method of class <code>ServerSocket</code>. 
  573.      * <p>
  574.      * The <code>checkAccept</code> method for class 
  575.      * <code>SecurityManager</code> always throws a
  576.      * <code>SecurityException</code>. 
  577.      *
  578.      * @param      host   the host name of the socket connection.
  579.      * @param      port   the port number of the socket connection.
  580.      * @exception  SecurityException  if the caller does not have permission
  581.      *               to accept the connection.
  582.      * @see        java.lang.System#getSecurityManager()
  583.      * @see        java.net.ServerSocket#accept()
  584.      * @since      JDK1.0
  585.      */
  586.     public void checkAccept(String host, int port) {
  587.     throw new SecurityException();
  588.     }
  589.  
  590.     /**
  591.      * Tests if current execution context is allowed to use
  592.      * (join/leave/send/receive) IP multicast.
  593.      *
  594.      * @param      multicast  Internet group address to be used.
  595.      * @exception  SecurityException  if a security error has occurred.
  596.      * @since      JDK1.1
  597.      */
  598.     public void checkMulticast(InetAddress maddr) {
  599.     throw new SecurityException();
  600.     }
  601.  
  602.     /**
  603.      * Tests to see if current execution context is allowed to use
  604.      * (join/leave/send/receive) IP multicast.
  605.      *
  606.      * @param      multicast  Internet group address to be used.
  607.      * @param      ttl        value in use, if it is multicast send.
  608.      * @exception  SecurityException  if a security error has occurred.
  609.      * @since      JDK1.1
  610.      */
  611.     public void checkMulticast(InetAddress maddr, byte ttl) {
  612.     throw new SecurityException();
  613.     }
  614.  
  615.     /**
  616.      * Throws a <code>SecurityException</code> if the 
  617.      * calling thread is not allowed to access or modify the system 
  618.      * properties. 
  619.      * <p>
  620.      * This method is used by the <code>getProperties</code> and 
  621.      * <code>setProperties</code> methods of class <code>System</code>. 
  622.      * <p>
  623.      * The <code>checkPropertiesAccess</code> method for class 
  624.      * <code>SecurityManager</code> always throws a 
  625.      * <code>SecurityException</code>. 
  626.      *
  627.      * @exception  SecurityException  if the caller does not have permission
  628.      *               to access or modify the system properties.
  629.      * @see        java.lang.System#getProperties()
  630.      * @see        java.lang.System#setProperties(java.util.Properties)
  631.      * @since      JDK1.0
  632.      */
  633.     public void checkPropertiesAccess() {
  634.     throw new SecurityException();
  635.     }
  636.  
  637.     /**
  638.      * Throws a <code>SecurityException</code> if the 
  639.      * calling thread is not allowed to access the system property with 
  640.      * the specified <code>key</code> name. 
  641.      * <p>
  642.      * This method is used by the <code>getProperty</code> method of 
  643.      * class <code>System</code>. 
  644.      * <p>
  645.      * The <code>checkPropertiesAccess</code> method for class 
  646.      * <code>SecurityManager</code> always throws a 
  647.      * <code>SecurityException</code>. 
  648.      *
  649.      * @param      key   a system property key.
  650.      * @exception  SecurityException  if the caller does not have permission
  651.      *               to access the specified system property.
  652.      * @see        java.lang.System#getProperty(java.lang.String)
  653.      * @since      JDK1.0
  654.      */
  655.     public void checkPropertyAccess(String key) {
  656.     throw new SecurityException();
  657.     }
  658.  
  659.     /**
  660.      * Returns <code>false</code> if the calling 
  661.      * thread is not trusted to bring up the top-level window indicated 
  662.      * by the <code>window</code> argument. In this case, the caller can 
  663.      * still decide to show the window, but the window should include 
  664.      * some sort of visual warning. If the method returns 
  665.      * <code>true</code>, then the window can be shown without any 
  666.      * special restrictions. 
  667.      * <p>
  668.      * See class <code>Window</code> for more information on trusted and 
  669.      * untrusted windows. 
  670.      * <p>
  671.      * The <code>checkSetFactory</code> method for class 
  672.      * <code>SecurityManager</code> always returns <code>false</code>. 
  673.      *
  674.      * @param      window   the new window that is being created.
  675.      * @return     <code>true</code> if the caller is trusted to put up
  676.      *             top-level windows; <code>false</code> otherwise.
  677.      * @exception  SecurityException  if creation is disallowed entirely.
  678.      * @see        java.awt.Window
  679.      * @since      JDK1.0
  680.      */
  681.     public boolean checkTopLevelWindow(Object window) {
  682.     return false;
  683.     }
  684.  
  685.     /**
  686.      * Tests if a client can initiate a print job request.
  687.      *
  688.      * @since   JDK1.1
  689.      */
  690.     public void checkPrintJobAccess() {
  691.       throw new SecurityException();
  692.     }
  693.  
  694.     /**
  695.      * Tests if a client can get access to the system clipboard.
  696.      *
  697.      * @since   JDK1.1
  698.      */
  699.     public void checkSystemClipboardAccess() {
  700.       throw new SecurityException();
  701.     }
  702.  
  703.     /**
  704.      * Tests if a client can get access to the AWT event queue.
  705.      *
  706.      * @since   JDK1.1
  707.      */
  708.     public void checkAwtEventQueueAccess() {
  709.       throw new SecurityException();
  710.     }
  711.  
  712.     /**
  713.      * Throws a <code>SecurityException</code> if the 
  714.      * calling thread is not allowed to access the package specified by 
  715.      * the argument. 
  716.      * <p>
  717.      * This method is used by the <code>loadClass</code> method of class 
  718.      * loaders. 
  719.      * <p>
  720.      * The <code>checkPackageAccess</code> method for class 
  721.      * <code>SecurityManager</code> always throws a 
  722.      * <code>SecurityException</code>. 
  723.      *
  724.      * @param      pkg   the package name.
  725.      * @exception  SecurityException  if the caller does not have permission
  726.      *               to access the specified package.
  727.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  728.      * @since      JDK1.0
  729.      */
  730.     public void checkPackageAccess(String pkg) {
  731.     throw new SecurityException();
  732.     }
  733.  
  734.     /**
  735.      * Throws a <code>SecurityException</code> if the 
  736.      * calling thread is not allowed to define classes in the package 
  737.      * specified by the argument. 
  738.      * <p>
  739.      * This method is used by the <code>loadClass</code> method of some 
  740.      * class loaders. 
  741.      * <p>
  742.      * The <code>checkPackageDefinition</code> method for class 
  743.      * <code>SecurityManager</code> always throws a 
  744.      * <code>SecurityException</code>. 
  745.      *
  746.      * @param      pkg   the package name.
  747.      * @exception  SecurityException  if the caller does not have permission
  748.      *               to define classes in the specified package.
  749.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  750.      * @since      JDK1.0
  751.      */
  752.     public void checkPackageDefinition(String pkg) {
  753.     throw new SecurityException();
  754.     }
  755.  
  756.     /**
  757.      * Throws a <code>SecurityException</code> if the 
  758.      * calling thread is not allowed to set the socket factory used by 
  759.      * <code>ServerSocket</code> or <code>Socket</code>, or the stream 
  760.      * handler factory used by <code>URL</code>. 
  761.      * <p>
  762.      * The <code>checkSetFactory</code> method for class 
  763.      * <code>SecurityManager</code> always throws a 
  764.      * <code>SecurityException</code>. 
  765.      *
  766.      * @exception  SecurityException  if the caller does not have permission
  767.      *               to specify a socket factory or a stream handler factory.
  768.      * @see        java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory)
  769.      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
  770.      * @see        java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
  771.      * @since      JDK1.0
  772.      */
  773.     public void checkSetFactory() {
  774.     throw new SecurityException();
  775.     }
  776.  
  777.     /**
  778.      * Tests if a client is allowed to access members. If access is
  779.      * denied, throw a SecurityException.
  780.      * The default policy is to deny all accesses.
  781.      *
  782.      * @since JDK1.1
  783.      */
  784.     public void checkMemberAccess(Class clazz, int which) {
  785.     throw new SecurityException();
  786.     }
  787.  
  788.     /**
  789.      * Tests access to certain operations for a security API
  790.      * action.
  791.      *
  792.      * @since   JDK1.1
  793.      */
  794.     public void checkSecurityAccess(String action) {
  795.     throw new SecurityException();
  796.     }
  797.  
  798.     private native Class currentLoadedClass0();
  799.  
  800.     /**
  801.      * Returns the thread group into which to instantiate any new
  802.      * thread being created at the time this is being called.
  803.      * By default, it returns the thread group of the current
  804.      * thread. This should be overriden by specific security
  805.      * manager to return the appropriate thread group.
  806.      *
  807.      * @since   JDK1.1
  808.      */
  809.     public ThreadGroup getThreadGroup() {
  810.     return Thread.currentThread().getThreadGroup();
  811.     }
  812.  
  813. }    
  814.  
  815. class NullSecurityManager extends SecurityManager {
  816.     public void checkCreateClassLoader() { } 
  817.     public void checkAccess(Thread g) { }
  818.     public void checkAccess(ThreadGroup g) { }
  819.     public void checkExit(int status) { }
  820.     public void checkExec(String cmd) { }
  821.     public void checkLink(String lib) { }
  822.     public void checkRead(FileDescriptor fd) { }
  823.     public void checkRead(String file) { }
  824.     public void checkRead(String file, Object context) { }
  825.     public void checkWrite(FileDescriptor fd) { }
  826.     public void checkWrite(String file) { }
  827.     public void checkDelete(String file) { }
  828.     public void checkConnect(String host, int port) { }
  829.     public void checkConnect(String host, int port, Object context) { }
  830.     public void checkListen(int port) { }
  831.     public void checkAccept(String host, int port) { }
  832.     public void checkMulticast(InetAddress maddr) { }
  833.     public void checkMulticast(InetAddress maddr, byte ttl) { }
  834.     public void checkPropertiesAccess() { }
  835.     public void checkPropertyAccess(String key) { }
  836.     public void checkPropertyAccess(String key, String def) { }
  837.     public boolean checkTopLevelWindow(Object window) { return true; }
  838.     public void checkPrintJobAccess() { }
  839.     public void checkSystemClipboardAccess() { }
  840.     public void checkAwtEventQueueAccess() { }
  841.     public void checkPackageAccess(String pkg) { }
  842.     public void checkPackageDefinition(String pkg) { }
  843.     public void checkSetFactory() { }
  844.     public void checkMemberAccess(Class clazz, int which) { }
  845.     public void checkSecurityAccess(String provider) { }
  846. }    
  847.