home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / lang / SecurityManager.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  46.3 KB  |  1,187 lines

  1. /*
  2.  * @(#)SecurityManager.java    1.81 98/03/18
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang;
  16.  
  17. import java.security.*;
  18. import java.io.FileDescriptor;
  19. import java.io.File;
  20. import java.io.FilePermission;
  21. import java.awt.AWTPermission;
  22. import java.util.PropertyPermission;
  23. import java.lang.RuntimePermission;
  24. import java.net.SocketPermission;
  25. import java.net.NetPermission;
  26. import java.util.Hashtable;
  27. import java.net.InetAddress;
  28. import java.lang.reflect.Member;
  29. import java.lang.reflect.*;
  30. import java.net.URL;
  31.  
  32. /**
  33.  * The security manager is a class that allows 
  34.  * applications to implement a security policy. It allows an 
  35.  * application to determine, before performing a possibly unsafe or 
  36.  * sensitive operation, what the operation is and whether the 
  37.  * operation is being performed by a class created via a class loader 
  38.  * rather than installed locally. Classes loaded via a class loader 
  39.  * (especially if they have been downloaded over a network) may be 
  40.  * less trustworthy than classes from files installed locally. The 
  41.  * application can allow or disallow the operation. 
  42.  * <p>
  43.  * The <code>SecurityManager</code> class contains many methods with 
  44.  * names that begin with the word <code>check</code>. These methods 
  45.  * are called by various methods in the Java libraries before those 
  46.  * methods perform certain potentially sensitive operations. The 
  47.  * invocation of such a check method typically looks like this: 
  48.  * <p><blockquote><pre>
  49.  *     SecurityManager security = System.getSecurityManager();
  50.  *     if (security != null) {
  51.  *         security.check<i>XXX</i>(argument,  . . . );
  52.  *     }
  53.  * </pre></blockquote>
  54.  * <p>
  55.  * The security manager is thereby given an opportunity to prevent 
  56.  * completion of the operation by throwing an exception. A security 
  57.  * manager routine simply returns if the operation is permitted, but 
  58.  * throws a <code>SecurityException</code> if the operation is not 
  59.  * permitted. The only exception to this convention is 
  60.  * <code>checkTopLevelWindow</code>, which returns a 
  61.  * <code>boolean</code> value. 
  62.  * <p>
  63.  * The current security manager is set by the 
  64.  * <code>setSecurityManager</code> method in class 
  65.  * <code>System</code>. The current security manager is obtained 
  66.  * by the <code>getSecurityManager</code> method. 
  67.  * <p>
  68.  * As of JDK 1.2, the default implementation of each of the 
  69.  * <code>check</code><i>XXX</i> methods is to use the AccessController
  70.  * to determine if the caller has permission to perform the requested
  71.  * operation.
  72.  * <p> 
  73.  * The special method 
  74.  * <a href = "#checkPermission(java.security.Permission)">checkPermission</a>
  75.  * determines whether an access request indicated by a specified
  76.  * permission should be granted or denied. The 
  77.  * default implementation calls
  78.  * 
  79.  * <pre>
  80.  *   AccessController.checkPermission(perm);
  81.  * </pre>
  82.  *
  83.  * <p> 
  84.  * If a requested access is allowed, 
  85.  * <code>checkPermission</code> returns quietly. If denied, a 
  86.  * SecurityException is thrown. 
  87.  * <p> 
  88.  * Note that the <code>checkPermission</code> method with
  89.  * just a single permission argument always performs security checks
  90.  * within the context of the currently executing thread.
  91.  * Sometimes a security check that should be made within a given context
  92.  * will actually need to be done from within a
  93.  * <i>different</i> context (for example, from within a worker thread).
  94.  * The <a href = "#getSecurityContext">getSecurityContext</a> method and 
  95.  * the <a href = "#checkPermission(java.security.Permission, java.lang.Object)">checkPermission</a>
  96.  * method that includes a context argument are provided 
  97.  * for this situation. The 
  98.  * <code>getSecurityContext</code> method returns a "snapshot"
  99.  * of the current calling context. (The default implementation 
  100.  * returns an AccessControlContext object.) A sample call is
  101.  * the following:
  102.  * 
  103.  * <pre>
  104.  *   Object context = null;
  105.  *   SecurityManager sm = System.getSecurityManager();
  106.  *   if (sm != null) context = sm.getSecurityContext(); 
  107.  * </pre>
  108.  * 
  109.  * <p>
  110.  * The <code>checkPermission</code> method
  111.  * that takes a context object (in addition to a permission) 
  112.  * makes access decisions based on that context,
  113.  * rather than that of the current execution thread.
  114.  * Code within a different context can thus call that method,
  115.  * passing the permission and the
  116.  * previously-saved context object. A sample call (using the
  117.  * SecurityManager <code>sm</code> obtained as in the previous example) 
  118.  * is the following:
  119.  * 
  120.  * <pre>
  121.  *   if (sm != null) sm.checkPermission(permission, context);
  122.  * </pre> 
  123.  *
  124.  * <p>Permissions fall into these categories: File, Socket, Net, 
  125.  * Security, Runtime, Property, and AWT. The classes managing these various
  126.  * permission categories are <code>java.io.FilePermission</code>,
  127.  * <code>java.net.SocketPermission</code>, 
  128.  * <code>java.net.NetPermission</code>, 
  129.  * <code>java.security.SecurityPermission</code>,
  130.  * <code>java.lang.RuntimePermission</code>, 
  131.  * <code>java.util.PropertyPermission</code>, and
  132.  * <code>java.awt.AWTPermission</code>. 
  133.  * 
  134.  * <p>All but the first two (FilePermission and SocketPermission) are 
  135.  * subclasses of <code>java.security.BasicPermission</code>, which itself 
  136.  * is an abstract subclass of the
  137.  * top-level class for permissions, which is 
  138.  * <code>java.security.Permission</code>. BasicPermission defines the 
  139.  * functionality needed for all permissions that contain a name 
  140.  * that follows the hierarchical property naming convention 
  141.  * (for example, "exit", "setFactory", "print.queueJob", etc). 
  142.  * An asterisk 
  143.  * may appear at the end of the name, following a ".", or by itself, to 
  144.  * signify a wildcard match. For example: "a.*" or "*" is valid, 
  145.  * "*a" or "a*b" is not valid.
  146.  *
  147.  * <p>FilePermission and SocketPermission are subclasses of the
  148.  * top-level class for permissions 
  149.  * (<code>java.security.Permission</code>). Classes like these
  150.  * that have a more complicated name syntax than that used by
  151.  * BasicPermission subclass directly from Permission rather than from
  152.  * BasicPermission. For example, 
  153.  * for a <code>java.io.FilePermission</code> object, the permission name is
  154.  * the pathname of a file (or directory).
  155.  *
  156.  * <p>Some of the permission classes have an "actions" list that tells 
  157.  * the actions that are permitted for the object.  For example, 
  158.  * for a <code>java.io.FilePermission</code> object, the actions list
  159.  * (such as "read, write") specifies which actions are granted for the
  160.  * specified file (or for files in the specified directory).
  161.  * 
  162.  * <p>Other permission classes are for "named" permissions - 
  163.  * ones that contain a name but no actions list; you either have the
  164.  * named permission or you don't.
  165.  * 
  166.  * <p>Note: There is also a <code>java.security.AllPermission</code>
  167.  * permission that implies all permissions. It exists to simplify the work
  168.  * of system administrators who might need to perform multiple
  169.  * tasks that require all (or numerous) permissions.
  170.  * 
  171.  * <p>The permission namespace is organized
  172.  * in the manner shown below. For each category, the category name
  173.  * is given, followed by an indented list of permission names
  174.  * (such as "createClassLoader" and "exit") and permission name 
  175.  * types in braces (such as "{property name}" to represent an
  176.  * actual property name). Each permission name (or name type)
  177.  * is followed by the name in parentheses of the SecurityManager
  178.  * class(es) that handle that kind of permission.
  179.  * <pre>
  180.  * RuntimePermission
  181.  *    createClassLoader  (checkCreateClassLoader)
  182.  *    exit (checkExit)
  183.  *    setFactory (checkSetFactory)
  184.  *    setIO (java.lang.System.{setIn,setOut,SetErr})
  185.  *    thread (checkAccess(Thread), checkAccess(ThreadGroup))
  186.  *    fileDescriptor.read (checkRead(FileDescriptor))
  187.  *    fileDescriptor.write (checkWrite(FileDescriptor))
  188.  *    loadLibrary.{library name} (checkLink)
  189.  *    package.access.{package name}  (checkPackageAccess)
  190.  *    package.define.{package name} (checkPackageDefinition)
  191.  *    reflect.declared.{class name} (checkMemberAccess)
  192.  *    print.queueJob (checkPrintJobAccess)
  193.  * NetPermission
  194.  *    multicast (checkMulticast)
  195.  *    Authenticator.setDefault
  196.  *    Authenticator.requestPasswordAuthentication
  197.  * PropertyPermission
  198.  *    * (checkPropertiesAccess)
  199.  *    {property name} (checkPropertyAccess)
  200.  * AWTPermission
  201.  *    topLevelWindow (checkTopLevelWindow)
  202.  *    systemClipboard (checkSystemClipboardAccess)
  203.  *    eventQueue (checkAwtEventQueueAccess)
  204.  * SecurityPermission
  205.  *    {action} (checkSecurityAccess)
  206.  * FilePermission
  207.  *    {file or directory pathname} (checkExec, 
  208.  *        checkRead(String), checkWrite(String), checkDelete}
  209.  * SocketPermission
  210.  *    {host:port} {checkConnect, checkListen, checkAccept}
  211.  * </pre> 
  212.  *
  213.  * @author  Arthur van Hoff
  214.  * @author  Roland Schemers
  215.  *
  216.  * @version 1.81, 03/18/98
  217.  * @see     java.lang.ClassLoader
  218.  * @see     java.lang.SecurityException
  219.  * @see     java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
  220.  * @see     java.lang.System#getSecurityManager()
  221.  * @see     java.lang.System#setSecurityManager(java.lang.SecurityManager)
  222.  * @see     java.security.AccessController
  223.  * @see     java.security.AccessControlContext
  224.  * @see     java.security.AccessControlException
  225.  * @see     java.security.Permission
  226.  * @see     java.security.BasicPermission
  227.  * @see     java.io.FilePermission
  228.  * @see     java.net.SocketPermission
  229.  * @see     java.util.PropertyPermission
  230.  * @see     java.lang.RuntimePermission
  231.  * @see     java.awt.AWTPermission
  232.  * @see     java.security.Policy
  233.  * @see     java.security.SecurityPermission
  234.  * @see     java.security.ProtectionDomain
  235.  *
  236.  * @since   JDK1.0
  237.  */
  238. public 
  239. class SecurityManager {
  240.  
  241.     /**
  242.      * This field is <code>true</code> if there is a security check in 
  243.      * progress; <code>false</code> otherwise.
  244.      *
  245.      * @deprecated This type of security checking is not recommended.
  246.      *  It is recommended that the <code>checkPermission</code>
  247.      *  call be used instead.
  248.      */
  249.     protected boolean inCheck;
  250.  
  251.     /* 
  252.      * Have we been initialized. Effective against finalizer attacks.
  253.      */
  254.     private boolean initialized = false;
  255.  
  256.     // static permissions. Create here and used in the various
  257.     // check permission calls
  258.  
  259.     private static final RuntimePermission createClassLoaderPermission = 
  260.                   new RuntimePermission("createClassLoader");
  261.  
  262.     private static final RuntimePermission threadPermission = 
  263.                   new RuntimePermission("thread");
  264.  
  265.     private static final PropertyPermission propertiesPermission = 
  266.                   new PropertyPermission("*", "read,write");
  267.  
  268.     private static final AWTPermission topLevelWindowPermission = 
  269.                   new AWTPermission("topLevelWindow");
  270.  
  271.     /** 
  272.      * Tests if there is a security check in progress.
  273.      *
  274.      * @return the value of the <code>inCheck</code> field. This field 
  275.      *          should contain <code>true</code> if a security check is
  276.      *          in progress,
  277.      *          <code>false</code> otherwise.
  278.      * @see     java.lang.SecurityManager#inCheck
  279.      * @deprecated This type of security checking is not recommended.
  280.      *  It is recommended that the <code>checkPermission</code>
  281.      *  call be used instead.
  282.      */
  283.     public boolean getInCheck() {
  284.     return inCheck;
  285.     }
  286.  
  287.     /**
  288.      * Constructs a new <code>SecurityManager</code>. An application is 
  289.      * not allowed to create a new security manager if there is already a 
  290.      * current security manager. 
  291.      *
  292.      * @exception  SecurityException  if a security manager already exists.
  293.      * @see        java.lang.System#getSecurityManager()
  294.      */
  295.     public SecurityManager() {
  296.     synchronized(SecurityManager.class) {
  297.         if (System.getSecurityManager() != null) {
  298.         throw new 
  299.           SecurityException("security manager already installed.");
  300.         }
  301.         initialized = true;
  302.     }
  303.     }
  304.  
  305.     /**
  306.      * Returns the current execution stack as an array of classes. 
  307.      * <p>
  308.      * The length of the array is the number of methods on the execution 
  309.      * stack. The element at index <code>0</code> is the class of the 
  310.      * currently executing method, the element at index <code>1</code> is 
  311.      * the class of that method's caller, and so on. 
  312.      *
  313.      * @return  the execution stack.
  314.      */
  315.     protected native Class[] getClassContext();
  316.  
  317.     /**
  318.      * Returns an object describing the most recent class loader executing
  319.      * on the stack. 
  320.      *
  321.      * @return  the class loader of the most recent occurrence on the stack
  322.      *          of a method from a class defined using a class loader;
  323.      *          returns <code>null</code> if there is no occurrence on the
  324.      *          stack of a method from a class defined using a class loader.
  325.      */
  326.     protected native ClassLoader currentClassLoader();
  327.  
  328.     /**
  329.      * Returns the current Class with a ClassLoader on the execution stack.
  330.      *
  331.      * @since   JDK1.1
  332.      */
  333.     protected Class currentLoadedClass() {
  334.     return currentLoadedClass0();    
  335.     }
  336.  
  337.     /**
  338.      * Returns the stack depth of the specified class. 
  339.      *
  340.      * @param   name   the fully qualified name of the class to search for.
  341.      * @return  the depth on the stack frame of the first occurrence of a
  342.      *          method from a class with the specified name;
  343.      *          <code>-1</code> if such a frame cannot be found.
  344.      * @deprecated This type of security checking is not recommended.
  345.      *  It is recommended that the <code>checkPermission</code>
  346.      *  call be used instead.
  347.      *
  348.      */
  349.     protected native int classDepth(String name);
  350.  
  351.     /**
  352.      * Returns the stack depth of the most recently executing method 
  353.      * from a class defined using a class loader. 
  354.      *
  355.      * @return the depth on the stack frame of the most recent occurrence of
  356.      *          a method from a class defined using a class loader; returns
  357.      *          <code>-1</code> if there is no occurrence of a method from
  358.      *          a class defined using a class loader.
  359.      * @deprecated This type of security checking is not recommended.
  360.      *  It is recommended that the <code>checkPermission</code>
  361.      *  call be used instead.
  362.      */
  363.     protected native int classLoaderDepth();
  364.  
  365.     /**
  366.      * Tests if a method from a class with the specified
  367.      *         name is on the execution stack. 
  368.      *
  369.      * @param  name   the fully qualified name of the class.
  370.      * @return <code>true</code> if a method from a class with the specified
  371.      *         name is on the execution stack; <code>false</code> otherwise.
  372.      * @deprecated This type of security checking is not recommended.
  373.      *  It is recommended that the <code>checkPermission</code>
  374.      *  call be used instead.
  375.      */
  376.     protected boolean inClass(String name) {
  377.     return classDepth(name) >= 0;
  378.     }
  379.  
  380.     /**
  381.      * Tests if a method from a class defined using a
  382.      *          class loader is on the execution stack.
  383.      *
  384.      * @return  <code>true</code> if a method from a class defined using a
  385.      *          class loader is on the execution stack.
  386.      *
  387.      * @deprecated This type of security checking is not recommended.
  388.      *  It is recommended that the <code>checkPermission</code>
  389.      *  call be used instead.
  390.      */
  391.     protected boolean inClassLoader() {
  392.     return currentClassLoader() != null;
  393.     }
  394.  
  395.     /**
  396.      * Creates an object that encapsulates the current execution 
  397.      * environment. The result of this method is used, for example, by the 
  398.      * three-argument <code>checkConnect</code> method and by the 
  399.      * two-argument <code>checkRead</code> method. 
  400.      * <p> The default implementation of this method is to return 
  401.      * an <code>AccessControlContext</code> object.
  402.      * <p>
  403.      * These methods are needed because a trusted method may be called 
  404.      * on to read a file or open a socket on behalf of another method. 
  405.      * The trusted method needs to determine if the other (possibly 
  406.      * untrusted) method would be allowed to perform the operation on its 
  407.      * own. 
  408.      *
  409.      * @return  an implementation-dependent object that encapsulates
  410.      *          sufficient information about the current execution environment
  411.      *          to perform some security checks later.
  412.      * @see     java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object)
  413.      * @see     java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object)
  414.      */
  415.     public Object getSecurityContext() {
  416.     return AccessController.getContext();
  417.     }
  418.  
  419.     /**
  420.      * Throws a <code>SecurityException</code> if the requested
  421.      * access, specified by the given permission, is not permitted based
  422.      * on the security policy currently in effect.  
  423.      * <p>
  424.      * The <code>checkPermission</code> method for class
  425.      * <code>SecurityManager</code> calls
  426.      * <code>AccessController.checkPermission</code> with the
  427.      * given permission.
  428.      *
  429.      * @param     perm   the requested permission
  430.      * @exception SecurityException if access is not permitted based on
  431.      *          the current security policy.
  432.      * @since     JDK1.2
  433.      */
  434.     public void checkPermission(Permission perm) {
  435.     java.security.AccessController.checkPermission(perm);
  436.     }
  437.  
  438.     /**
  439.      * Throws a <code>SecurityException</code> if the
  440.      * specified security context is denied access to the resource
  441.      * specified by the given permission.
  442.      * The context must be a security 
  443.      * context returned by a previous call to 
  444.      * <code>getSecurityContext</code> and the access control
  445.      * decision is based upon the configured security policy for
  446.      * that security context.
  447.      * <p>
  448.      * If <code>context</code> is an instance of 
  449.      * <code>AccessControlContext</code> then the
  450.      * <code>AccessControlContext.checkPermission</code> method will
  451.      * be invoked with the specified permission.
  452.      * <p>
  453.      * If <code>context</code> is not an instance of 
  454.      * <code>AccessControlContext</code> then a
  455.      * <code>SecurityException</code> is thrown. 
  456.      *
  457.      * @param      perm      the specified permission
  458.      * @param      context   a system-dependent security context.
  459.      * @exception  SecurityException  if the specified security context is
  460.      *            denied access to the resource specified by the
  461.      *            given permission.     
  462.      * @see        java.lang.SecurityManager#getSecurityContext()
  463.      * @since      JDK1.2
  464.      */
  465.     public void checkPermission(Permission perm, Object context) {
  466.     if (context instanceof AccessControlContext) {
  467.         ((AccessControlContext)context).checkPermission(perm);
  468.     } else {
  469.         throw new SecurityException();
  470.     }
  471.     }
  472.  
  473.     /**
  474.      * Throws a <code>SecurityException</code> if the 
  475.      * calling thread is not allowed to create a new class loader. 
  476.      * <p>
  477.      * The <code>checkCreateClassLoader</code> method for class 
  478.      * <code>SecurityManager</code> calls
  479.      * <code>checkPermission</code> with the
  480.      * <code>RuntimePermission("createClassLoader")</code>
  481.      * permission.
  482.      *
  483.      * @exception SecurityException if the caller does not have permission
  484.      *             to create a new class loader.
  485.      * @see        java.lang.ClassLoader#ClassLoader()
  486.      */
  487.     public void checkCreateClassLoader() {
  488.     checkPermission(createClassLoaderPermission);
  489.     }
  490.     
  491.     /**
  492.      * Throws a <code>SecurityException</code> if the 
  493.      * calling thread is not allowed to modify the thread argument. 
  494.      * <p>
  495.      * This method is invoked for the current security manager by the 
  496.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, 
  497.      * <code>setPriority</code>, <code>setName</code>, and 
  498.      * <code>setDaemon</code> methods of class <code>Thread</code>. 
  499.      * <p>
  500.      * The <code>checkAccess</code> method for class 
  501.      * <code>SecurityManager</code> first sees if the current
  502.      * thread's ThreadGroup is a parent of <code>t</code>'s ThreadGroup.
  503.      * If so, it returns. If not it calls
  504.      * <code>checkPermission</code> with the
  505.      * <code>RuntimePermission("thread")</code> permission.
  506.      *
  507.      * @param      t   the thread to be checked.
  508.      * @exception  SecurityException  if the caller does not have 
  509.      *             permission to modify the thread.
  510.      * @see        java.lang.System#getSecurityManager()
  511.      * @see        java.lang.Thread#resume()
  512.      * @see        java.lang.Thread#setDaemon(boolean)
  513.      * @see        java.lang.Thread#setName(java.lang.String)
  514.      * @see        java.lang.Thread#setPriority(int)
  515.      * @see        java.lang.Thread#stop()
  516.      * @see        java.lang.Thread#suspend()
  517.      */
  518.     public void checkAccess(Thread t) {
  519.         ThreadGroup ctg = Thread.currentThread().getThreadGroup();
  520.         if (!ctg.parentOf(t.getThreadGroup())) {
  521.               checkPermission(threadPermission);
  522.         }
  523.     }
  524.  
  525.     /**
  526.      * Throws a <code>SecurityException</code> if the 
  527.      * calling thread is not allowed to modify the thread group argument. 
  528.      * <p>
  529.      * This method is invoked for the current security manager when a 
  530.      * new child thread or child thread group is created, and by the 
  531.      * <code>setDaemon</code>, <code>setMaxPriority</code>, 
  532.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, and 
  533.      * <code>destroy</code> methods of class <code>ThreadGroup</code>. 
  534.      * <p>
  535.      *
  536.      * The <code>checkAccess</code> method for class 
  537.      * <code>SecurityManager</code> first sees if the current
  538.      * thread's ThreadGroup is a parent of <code>t</code>'s ThreadGroup.
  539.      * If so, it returns. If not it calls
  540.      * <code>checkPermission</code> with the
  541.      * <code>RuntimePermission("thread")</code> permission.
  542.      *
  543.      * @param      g   the thread group to be checked.
  544.      * @exception  SecurityException  if the caller does not have
  545.      *             permission to modify the thread group.
  546.      * @see        java.lang.System#getSecurityManager()
  547.      * @see        java.lang.ThreadGroup#destroy()
  548.      * @see        java.lang.ThreadGroup#resume()
  549.      * @see        java.lang.ThreadGroup#setDaemon(boolean)
  550.      * @see        java.lang.ThreadGroup#setMaxPriority(int)
  551.      * @see        java.lang.ThreadGroup#stop()
  552.      * @see        java.lang.ThreadGroup#suspend()
  553.      */
  554.     public void checkAccess(ThreadGroup g) {
  555.         ThreadGroup ctg = Thread.currentThread().getThreadGroup();
  556.         if (!ctg.parentOf(g)) {
  557.               checkPermission(threadPermission);
  558.         }
  559.     }
  560.  
  561.     /**
  562.      * Throws a <code>SecurityException</code> if the 
  563.      * calling thread is not allowed to cause the Java Virtual Machine to 
  564.      * halt with the specified status code. 
  565.      * <p>
  566.      * This method is invoked for the current security manager by the 
  567.      * <code>exit</code> method of class <code>Runtime</code>. A status 
  568.      * of <code>0</code> indicates success; other values indicate various 
  569.      * errors. 
  570.      * <p>
  571.      * The <code>checkExit</code> method for class 
  572.      * <code>SecurityManager</code> calls
  573.      * <code>checkPermission</code> with the
  574.      * <code>RuntimePermission("exit")</code> permission.
  575.      *
  576.      * @param      status   the exit status.
  577.      * @exception SecurityException if the caller does not have permission
  578.      *              to halt the Java Virtual Machine with the specified status.
  579.      * @see        java.lang.Runtime#exit(int)
  580.      * @see        java.lang.System#getSecurityManager()
  581.      */
  582.     public void checkExit(int status) {
  583.     checkPermission(new RuntimePermission("exit"));
  584.     }
  585.  
  586.     /**
  587.      * Throws a <code>SecurityException</code> if the 
  588.      * calling thread is not allowed to create a subprocess. 
  589.      * <p>
  590.      * This method is invoked for the current security manager by the 
  591.      * <code>exec</code> methods of class <code>Runtime</code>.
  592.      * <p>
  593.      * The <code>checkExec</code> method for class 
  594.      * <code>SecurityManager</code> calls
  595.      * <code>checkPermission</code> with the
  596.      * <code>FilePermission(cmd,"execute")</code> permission.
  597.      *
  598.      * @param      cmd   the specified system command.
  599.      * @exception SecurityException if the caller does not have permission
  600.      *               to create a subprocess.
  601.      * @see        java.lang.Runtime#exec(java.lang.String)
  602.      * @see        java.lang.Runtime#exec(java.lang.String, java.lang.String[])
  603.      * @see        java.lang.Runtime#exec(java.lang.String[])
  604.      * @see        java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
  605.      * @see        java.lang.System#getSecurityManager()
  606.      */
  607.     public void checkExec(String cmd) {
  608.     File f = new File(cmd);
  609.     if (f.isAbsolute()) {
  610.         checkPermission(new FilePermission(cmd, "execute"));
  611.     } else {
  612.         checkPermission(new FilePermission("<<ALL FILES>>", "execute"));
  613.     }
  614.     }
  615.  
  616.     /**
  617.      * Throws a <code>SecurityException</code> if the 
  618.      * calling thread is not allowed to dynamic link the library code 
  619.      * specified by the string argument file. The argument is either a 
  620.      * simple library name or a complete filename. 
  621.      * <p>
  622.      * This method is invoked for the current security manager by 
  623.      * methods <code>load</code> and <code>loadLibrary</code> of class 
  624.      * <code>Runtime</code>. 
  625.      * <p>
  626.      * The <code>checkLink</code> method for class 
  627.      * <code>SecurityManager</code> calls
  628.      * <code>checkPermission</code> with the
  629.      * <code>RuntimePermission("loadLibrary."+lib)</code> permission.
  630.      *
  631.      * @param      lib   the name of the library.
  632.      * @exception  SecurityException if the caller does not have
  633.      *             permission to dynamically link the library.
  634.      * @see        java.lang.Runtime#load(java.lang.String)
  635.      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
  636.      * @see        java.lang.System#getSecurityManager()
  637.      */
  638.     public void checkLink(String lib) {
  639.         checkPermission(new RuntimePermission("loadLibrary."+lib));
  640.     }
  641.  
  642.     /**
  643.      * Throws a <code>SecurityException</code> if the 
  644.      * calling thread is not allowed to read from the specified file 
  645.      * descriptor. 
  646.      * <p>
  647.      * The <code>checkRead</code> method for class 
  648.      * <code>SecurityManager</code> calls
  649.      * <code>checkPermission</code> with the
  650.      * <code>RuntimePermission("fileDescriptor.read")</code>
  651.      * permission.
  652.      *
  653.      * @param      fd   the system-dependent file descriptor.
  654.      * @exception  SecurityException  if the caller does not have
  655.      *             permission to access the specified file descriptor.
  656.      * @see        java.io.FileDescriptor
  657.      */
  658.     public void checkRead(FileDescriptor fd) {
  659.           checkPermission(new RuntimePermission("fileDescriptor.read"));
  660.     }
  661.  
  662.     /**
  663.      * Throws a <code>SecurityException</code> if the 
  664.      * calling thread is not allowed to read the file specified by the 
  665.      * string argument. 
  666.      * <p>
  667.      * The <code>checkRead</code> method for class 
  668.      * <code>SecurityManager</code> calls
  669.      * <code>checkPermission</code> with the
  670.      * <code>FilePermission(file,"read")</code> permission.
  671.      *
  672.      * @param      file   the system-dependent file name.
  673.      * @exception  SecurityException if the caller does not have 
  674.      *             permission to access the specified file.
  675.      */
  676.     public void checkRead(String file) {
  677.     checkPermission(new FilePermission(file, "read"));
  678.     }
  679.  
  680.     /**
  681.      * Throws a <code>SecurityException</code> if the 
  682.      * specified security context is not allowed to read the file 
  683.      * specified by the string argument. The context must be a security 
  684.      * context returned by a previous call to 
  685.      * <code>getSecurityContext</code>. 
  686.      * <p> If <code>context</code> is an instance of 
  687.      * <code>AccessControlContext</code> then the
  688.      * <code>AccessControlContext.checkPermission</code> method will
  689.      * be invoked with the <code>FilePermission(file,"read")</code> permission.
  690.      * <p> If <code>context</code> is not an instance of 
  691.      * <code>AccessControlContext</code> then a
  692.      * <code>SecurityException</code> is thrown. 
  693.      *
  694.      * @param      file      the system-dependent filename.
  695.      * @param      context   a system-dependent security context.
  696.      * @exception  SecurityException  if the specified security context does
  697.      *               not have permission to read the specified file.
  698.      * @see        java.lang.SecurityManager#getSecurityContext()
  699.      */
  700.     public void checkRead(String file, Object context) {
  701.     if (context instanceof AccessControlContext) {
  702.         ((AccessControlContext)context).checkPermission(
  703.                    new FilePermission(file, "read"));
  704.     } else{
  705.         throw new SecurityException();
  706.     }
  707.     }
  708.  
  709.     /**
  710.      * Throws a <code>SecurityException</code> if the 
  711.      * calling thread is not allowed to write to the specified file 
  712.      * descriptor. 
  713.      * <p>
  714.      * The <code>checkWrite</code> method for class 
  715.      * <code>SecurityManager</code>  calls
  716.      * <code>checkPermission</code> with the
  717.      * <code>RuntimePermission("fileDescriptor.write")</code>
  718.      * permission.
  719.      *
  720.      * @param      fd   the system-dependent file descriptor.
  721.      * @exception SecurityException  if the caller does not have
  722.      *             permission to access the specified file descriptor.
  723.      * @see        java.io.FileDescriptor
  724.      */
  725.     public void checkWrite(FileDescriptor fd) {
  726.           checkPermission(new RuntimePermission("fileDescriptor.write"));
  727.  
  728.     }
  729.  
  730.     /**
  731.      * Throws a <code>SecurityException</code> if the 
  732.      * calling thread is not allowed to write to the file specified by 
  733.      * the string argument. 
  734.      * <p>
  735.      * The <code>checkWrite</code> method for class 
  736.      * <code>SecurityManager</code> calls
  737.      * <code>checkPermission</code> with the
  738.      * <code>FilePermission(file,"write")</code> permission.
  739.      *
  740.      * @param      file   the system-dependent filename.
  741.      * @exception  SecurityException  if the caller does not 
  742.      *             have permission to access the specified file.
  743.      */
  744.     public void checkWrite(String file) {
  745.     checkPermission(new FilePermission(file, "write"));
  746.     }
  747.  
  748.     /**
  749.      * Throws a <code>SecurityException</code> if the 
  750.      * calling thread is not allowed to delete the specified file. 
  751.      * <p>
  752.      * This method is invoked for the current security manager by the 
  753.      * <code>delete</code> method of class <code>File</code>.
  754.      * <p>
  755.      * The <code>checkDelete</code> method for class 
  756.      * <code>SecurityManager</code>  calls
  757.      * <code>checkPermission</code> with the
  758.      * <code>FilePermission(file,"delete")</code> permission.
  759.      *
  760.      * @param      file   the system-dependent filename.
  761.      * @exception  SecurityException if the caller does not 
  762.      *             have permission to delete the file.
  763.      *
  764.      * @see        java.io.File#delete()
  765.      * @see        java.lang.System#getSecurityManager()
  766.      */
  767.     public void checkDelete(String file) {
  768.     checkPermission(new FilePermission(file, "delete"));
  769.     }
  770.  
  771.     /**
  772.      * Throws a <code>SecurityException</code> if the 
  773.      * calling thread is not allowed to open a socket connection to the 
  774.      * specified host and port number. 
  775.      * <p>
  776.      * A port number of <code>-1</code> indicates that the calling 
  777.      * method is attempting to determine the IP address of the specified 
  778.      * host name. 
  779.      * <p>
  780.      * The <code>checkConnect</code> method for class 
  781.      * <code>SecurityManager</code> calls
  782.      * <code>checkPermission</code> with the
  783.      * <code>SocketPermission(host+":"+port,"connect")</code> permission if
  784.      * the port is not equal to -1. If the port is equal to -1, then
  785.      * it calls <code>checkPermission</code> with the
  786.      * <code>SocketPermission(host,"resolve")</code> permission.
  787.      *
  788.      * @param      host   the host name port to connect to.
  789.      * @param      port   the protocol port to connect to.
  790.      * @exception  SecurityException  if the caller does not have
  791.      *             permission to open a socket connection to the specified
  792.      *               <code>host</code> and <code>port</code>.
  793.      */
  794.     public void checkConnect(String host, int port) {
  795.     if (port == -1) {
  796.         checkPermission(new SocketPermission(host,"resolve"));
  797.     } else {
  798.         checkPermission(new SocketPermission(host+":"+port,"connect"));
  799.     }
  800.     }
  801.  
  802.     /**
  803.      * Throws a <code>SecurityException</code> if the 
  804.      * specified security context is not allowed to open a socket 
  805.      * connection to the specified host and port number. 
  806.      * <p>
  807.      * A port number of <code>-1</code> indicates that the calling 
  808.      * method is attempting to determine the IP address of the specified 
  809.      * host name. 
  810.      *
  811.      * <p> If <code>context</code> is an instance of 
  812.      * <code>AccessControlContext</code> then the
  813.      * <code>AccessControlContext.checkPermission</code> method will
  814.      * be invoked with the
  815.      * <code>SocketPermission(host+":"+port,"connect")</code> permission if
  816.      * the port is not equal to -1. If the port is equal to -1, then
  817.      * it calls <code>checkPermission</code> with the
  818.      * <code>SocketPermission(host,"resolve")</code> permission.
  819.      *
  820.      * <p> If <code>context</code> is not an instance of 
  821.      * <code>AccessControlContext</code> then a
  822.      * <code>SecurityException</code> is thrown.
  823.      *
  824.      * @param      host      the host name port to connect to.
  825.      * @param      port      the protocol port to connect to.
  826.      * @param      context   a system-dependent security context.
  827.      * @exception  SecurityException  if the specified security context does
  828.      *               not have permission to open a socket connection to the
  829.      *               specified <code>host</code> and <code>port</code>.
  830.      * @see        java.lang.SecurityManager#getSecurityContext()
  831.      */
  832.     public void checkConnect(String host, int port, Object context) {
  833.     if (context instanceof AccessControlContext) {
  834.         if (port == -1) {
  835.         ((AccessControlContext)context).checkPermission(
  836.                      new SocketPermission(host,"resolve"));
  837.         } else {
  838.         ((AccessControlContext)context).checkPermission(
  839.                 new SocketPermission(host+":"+port,"connect"));
  840.         }
  841.     } else{
  842.         throw new SecurityException();
  843.     }
  844.     }
  845.  
  846.     /**
  847.      * Throws a <code>SecurityException</code> if the 
  848.      * calling thread is not allowed to wait for a connection request on 
  849.      * the specified local port number. 
  850.      * <p>
  851.      * If port is not 0, the <code>checkListen</code> method for class 
  852.      * <code>SecurityManager</code> calls
  853.      * <code>checkPermission</code> with the
  854.      * <code>SocketPermission("localhost:"+port,"listen")</code>.
  855.      * If port is zero, calls <code>checkPermission</code>
  856.      * with <code>SocketPermission("localhost:1024-","listen").</code>
  857.      *
  858.      * @param      port   the local port.
  859.      * @exception  SecurityException  if the caller does not have 
  860.      *             permission to listen on the specified port.
  861.      */
  862.     public void checkListen(int port) {
  863.     if (port == 0) {
  864.         checkPermission(localListenPermission);
  865.     } else {
  866.         checkPermission(new SocketPermission("localhost:"+port,"listen"));
  867.     }
  868.     }
  869.  
  870.     private static final SocketPermission localListenPermission = 
  871.                          new SocketPermission("localhost:1024-","listen");
  872.     /**
  873.      * Throws a <code>SecurityException</code> if the 
  874.      * calling thread is not permitted to accept a socket connection from 
  875.      * the specified host and port number. 
  876.      * <p>
  877.      * This method is invoked for the current security manager by the 
  878.      * <code>accept</code> method of class <code>ServerSocket</code>. 
  879.      * <p>
  880.      * The <code>checkAccept</code> method for class 
  881.      * <code>SecurityManager</code> calls
  882.      * <code>checkPermission</code> with the
  883.      * <code>SocketPermission(host+":"+port,"accept")</code> permission.
  884.      * <P>
  885.      *
  886.      * @param      host   the host name of the socket connection.
  887.      * @param      port   the port number of the socket connection.
  888.      * @exception  SecurityException  if the caller does not have 
  889.      *             permission to accept the connection.
  890.      * @see        java.lang.System#getSecurityManager()
  891.      * @see        java.net.ServerSocket#accept()
  892.      */
  893.     public void checkAccept(String host, int port) {
  894.     checkPermission(new SocketPermission(host+":"+port,"accept"));
  895.     }
  896.  
  897.     /**
  898.      * Tests if current execution context is allowed to use
  899.      * (join/leave/send/receive) IP multicast.
  900.      * <p>
  901.      * The <code>checkMulticast</code> method for class 
  902.      * <code>SecurityManager</code> calls
  903.      * <code>checkPermission</code> with the
  904.      * <code>RuntimePermission("multicast")</code>
  905.      * permission.
  906.      *
  907.      * @param      maddr  Internet group address to be used.
  908.      * @exception  SecurityException  if a security error has occurred.
  909.      * @since      JDK1.1
  910.      */
  911.     public void checkMulticast(InetAddress maddr) {
  912.           checkPermission(new NetPermission("multicast"));
  913.     }
  914.  
  915.     /**
  916.      * Tests to see if current execution context is allowed to use
  917.      * (join/leave/send/receive) IP multicast.
  918.      * <p>
  919.      * The <code>checkMulticast</code> method for class 
  920.      * <code>SecurityManager</code> calls
  921.      * <code>checkPermission</code> with the
  922.      * <code>RuntimePermission("multicast")</code>
  923.      * permission.
  924.      * <p>
  925.      *
  926.      * @param      maddr  Internet group address to be used.
  927.      * @param      ttl        value in use, if it is multicast send.
  928.      * @exception  SecurityException  if a security error has occurred.
  929.      * @since      JDK1.1
  930.      */
  931.     public void checkMulticast(InetAddress maddr, byte ttl) {
  932.           checkPermission(new NetPermission("multicast"));
  933.     }
  934.  
  935.     /**
  936.      * Throws a <code>SecurityException</code> if the 
  937.      * calling thread is not allowed to access or modify the system 
  938.      * properties. 
  939.      * <p>
  940.      * This method is used by the <code>getProperties</code> and 
  941.      * <code>setProperties</code> methods of class <code>System</code>. 
  942.      * <p>
  943.      * The <code>checkPropertiesAccess</code> method for class 
  944.      * <code>SecurityManager</code> calls
  945.      * <code>checkPermission</code> with the
  946.      * <code>PropertyPermission("*", "read,write")</code> permission.
  947.      * <p>
  948.      *
  949.      * @exception  SecurityException  if the caller does not have 
  950.      *             permission to access or modify the system properties.
  951.      * @see        java.lang.System#getProperties()
  952.      * @see        java.lang.System#setProperties(java.util.Properties)
  953.      */
  954.     public void checkPropertiesAccess() {
  955.           checkPermission(propertiesPermission);
  956.     }
  957.  
  958.     /**
  959.      * Throws a <code>SecurityException</code> if the 
  960.      * calling thread is not allowed to access the system property with 
  961.      * the specified <code>key</code> name. 
  962.      * <p>
  963.      * This method is used by the <code>getProperty</code> method of 
  964.      * class <code>System</code>. 
  965.      * <p>
  966.      * The <code>checkPropertyAccess</code> method for class 
  967.      * <code>SecurityManager</code> calls
  968.      * <code>checkPermission</code> with the
  969.      * <code>PropertyPermission(key, "read")</code> permission.
  970.      * <p>
  971.      *
  972.      * @param      key   a system property key.
  973.      * @exception  SecurityException  if the caller does not have 
  974.      *             permission to access the specified system property.
  975.      * @see        java.lang.System#getProperty(java.lang.String)
  976.      */
  977.  
  978.     public void checkPropertyAccess(String key) {
  979.           checkPermission(new PropertyPermission(key,"read"));
  980.     }
  981.  
  982.     /**
  983.      * Returns <code>false</code> if the calling 
  984.      * thread is not trusted to bring up the top-level window indicated 
  985.      * by the <code>window</code> argument. In this case, the caller can 
  986.      * still decide to show the window, but the window should include 
  987.      * some sort of visual warning. If the method returns 
  988.      * <code>true</code>, then the window can be shown without any 
  989.      * special restrictions. 
  990.      * <p>
  991.      * See class <code>Window</code> for more information on trusted and 
  992.      * untrusted windows. 
  993.      * <p>
  994.      * This method calls
  995.      * <code>checkPermission</code> with the
  996.      * <code>AWTPermission("topLevelWindow")</code> permission,
  997.      * and returns true if an SecurityException is not thrown, otherwise
  998.      * it returns false.
  999.      *
  1000.      * @param      window   the new window that is being created.
  1001.      * @return     <code>true</code> if the caller is trusted to put up
  1002.      *             top-level windows; <code>false</code> otherwise.
  1003.      * @exception  SecurityException  if creation is disallowed entirely.
  1004.      * @see        java.awt.Window
  1005.      */
  1006.     public boolean checkTopLevelWindow(Object window) {
  1007.     try {
  1008.         checkPermission(topLevelWindowPermission);    
  1009.         return true;
  1010.     } catch (SecurityException se) {
  1011.         // just return false
  1012.     }
  1013.     return false;
  1014.     }
  1015.  
  1016.     /**
  1017.      * Tests if a client can initiate a print job request.
  1018.      *
  1019.      * This method calls
  1020.      * <code>checkPermission</code> with the
  1021.      * <code>RuntimePermission("print.queueJob")</code> permission.
  1022.      * <p>
  1023.      *
  1024.      * @exception  SecurityException  if the caller does not have 
  1025.      *             permission to initiate a print job request.
  1026.      * @since   JDK1.1
  1027.      */
  1028.     public void checkPrintJobAccess() {
  1029.           checkPermission(new RuntimePermission("print.queueJob"));
  1030.     }
  1031.  
  1032.     /**
  1033.      * Tests if a client can get access to the system clipboard.
  1034.      * <p>
  1035.      * This method calls <code>checkPermission</code> with the
  1036.      * <code>AWTPermission("systemClipboard")</code> 
  1037.      * permission.
  1038.      *
  1039.      * @since   JDK1.1
  1040.      * @exception  SecurityException  if the caller does not have 
  1041.      *             permission to accesss the system clipboard.
  1042.      */
  1043.     public void checkSystemClipboardAccess() {
  1044.     checkPermission(new AWTPermission("systemClipboard"));
  1045.     }
  1046.  
  1047.     /**
  1048.      * Tests if a client can get access to the AWT event queue.
  1049.      * <p>
  1050.      * This method calls <code>checkPermission</code> with the
  1051.      * <code>AWTPermission("eventQueue")</code> permission.
  1052.      *
  1053.      * @since   JDK1.1
  1054.      * @exception  SecurityException  if the caller does not have 
  1055.      *             permission to accesss the AWT event queue.
  1056.      */
  1057.     public void checkAwtEventQueueAccess() {
  1058.           checkPermission(new AWTPermission("eventQueue"));
  1059.     }
  1060.  
  1061.     /**
  1062.      * Throws a <code>SecurityException</code> if the 
  1063.      * calling thread is not allowed to access the package specified by 
  1064.      * the argument. 
  1065.      * <p>
  1066.      * This method is used by the <code>loadClass</code> method of class 
  1067.      * loaders. 
  1068.      * <p>
  1069.      * The <code>checkPackageAccess</code> method for class 
  1070.      * <code>SecurityManager</code>  calls
  1071.      * <code>checkPermission</code> with the
  1072.      * <code>RuntimePermission("package.access."+pkg)</code>
  1073.      * permission.
  1074.      *
  1075.      * @param      pkg   the package name.
  1076.      * @exception  SecurityException  if the caller does not have
  1077.      *             permission to access the specified package.
  1078.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  1079.      */
  1080.     public void checkPackageAccess(String pkg) {
  1081.           checkPermission(new RuntimePermission("package.access."+pkg));
  1082.     }
  1083.  
  1084.     /**
  1085.      * Throws a <code>SecurityException</code> if the 
  1086.      * calling thread is not allowed to define classes in the package 
  1087.      * specified by the argument. 
  1088.      * <p>
  1089.      * This method is used by the <code>loadClass</code> method of some 
  1090.      * class loaders. 
  1091.      * <p>
  1092.      * The <code>checkPackageDefinition</code> method for class 
  1093.      * <code>SecurityManager</code> calls
  1094.      * <code>checkPermission</code> with the
  1095.      * <code>RuntimePermission("package.define."+pkg)</code>
  1096.      * permission.
  1097.      *
  1098.      *
  1099.      * @param      pkg   the package name.
  1100.      * @exception  SecurityException  if the caller does not have
  1101.      *             permission to define classes in the specified package.
  1102.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  1103.      */
  1104.     public void checkPackageDefinition(String pkg) {
  1105.           checkPermission(new RuntimePermission("package.define."+pkg));
  1106.     }
  1107.  
  1108.     /**
  1109.      * Throws a <code>SecurityException</code> if the 
  1110.      * calling thread is not allowed to set the socket factory used by 
  1111.      * <code>ServerSocket</code> or <code>Socket</code>, or the stream 
  1112.      * handler factory used by <code>URL</code>. 
  1113.      * <p>
  1114.      * The <code>checkSetFactory</code> method for class 
  1115.      * <code>SecurityManager</code> calls
  1116.      * <code>checkPermission</code> with the
  1117.      * <code>RuntimePermission("setFactory")</code> permission.
  1118.      * <p>
  1119.      *
  1120.      * @exception  SecurityException  if the caller does not have 
  1121.      *             permission to specify a socket factory or a stream 
  1122.      *             handler factory.
  1123.      *
  1124.      * @see        java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory)
  1125.      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
  1126.      * @see        java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
  1127.      */
  1128.     public void checkSetFactory() {
  1129.           checkPermission(new RuntimePermission("setFactory"));
  1130.     }
  1131.  
  1132.     /**
  1133.      * Tests if a client is allowed to access members. If access is
  1134.      * denied, throw a SecurityException.
  1135.      * The default policy is to allow access to PUBLIC members, as well
  1136.      * as access to classes that have the same class loader as the caller.
  1137.      * In all other cases call <code>checkPermission</code> 
  1138.      * with the <code>RuntimePermission("reflect.declared."+clazz.getName())
  1139.      * </code> permission.
  1140.      * 
  1141.      * @exception  SecurityException if the caller does not have
  1142.      *             permission. 
  1143.      * @since JDK1.1
  1144.      */
  1145.     public void checkMemberAccess(Class clazz, int which) {
  1146.     if (which != Member.PUBLIC) {
  1147.         if (currentClassLoader() != clazz.getClassLoader()) {
  1148.         checkPermission(
  1149.            new RuntimePermission("reflect.declared."+clazz.getName()));
  1150.         }
  1151.     }
  1152.     }
  1153.  
  1154.     /**
  1155.      * Tests access to certain operations for a security API
  1156.      * action.
  1157.      *
  1158.      * <p>
  1159.      * This method calls
  1160.      * <code>checkPermission</code> with the
  1161.      * <code>SecurityPermission(action)</code>
  1162.      * permission.
  1163.      * <p>
  1164.      * @since   JDK1.1
  1165.      * @param action the security API action to check against.
  1166.      */
  1167.     public void checkSecurityAccess(String action) {
  1168.     checkPermission(new SecurityPermission(action));
  1169.     }
  1170.  
  1171.     private native Class currentLoadedClass0();
  1172.  
  1173.     /**
  1174.      * Returns the thread group into which to instantiate any new
  1175.      * thread being created at the time this is being called.
  1176.      * By default, it returns the thread group of the current
  1177.      * thread. This should be overriden by a specific security
  1178.      * manager to return the appropriate thread group.
  1179.      *
  1180.      * @since   JDK1.1
  1181.      */
  1182.     public ThreadGroup getThreadGroup() {
  1183.     return Thread.currentThread().getThreadGroup();
  1184.     }
  1185.  
  1186. }    
  1187.