home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / SecurityManager.java < prev    next >
Text File  |  1996-05-03  |  10KB  |  326 lines

  1. /*
  2.  * @(#)SecurityManager.java    1.26 95/12/22  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. import java.io.FileDescriptor;
  23.  
  24. /**
  25.  * An abstract class that can be subclassed
  26.  * to implement a security policy. It allows the inspection of
  27.  * the classloaders on the execution stack.
  28.  *
  29.  * @author    Arthur van Hoff
  30.  * @version     1.26, 22 Dec 1995
  31.  */
  32. public abstract
  33. class SecurityManager {
  34.     protected boolean inCheck;
  35.  
  36.     /** 
  37.      * Returns whether there is a security check in progress.
  38.      */
  39.     public boolean getInCheck() {
  40.     return inCheck;
  41.     }
  42.  
  43.     /**
  44.      * Constructs a new SecurityManager.
  45.      * @exception SecurityException If the security manager cannot be
  46.      * created.
  47.      */
  48.     protected SecurityManager() {
  49.     if (System.getSecurityManager() != null) {
  50.         throw new SecurityException("can't create SecurityManager");
  51.     }
  52.     }
  53.     
  54.     /**
  55.      * Gets the context of this Class.  
  56.      */
  57.     protected native Class[] getClassContext();
  58.  
  59.     /**
  60.      * The current ClassLoader on the execution stack.
  61.      */
  62.     protected native ClassLoader currentClassLoader();
  63.  
  64.     /**
  65.      * Return the position of the stack frame containing the
  66.      * first occurrence of the named class.
  67.      * @param name classname of the class to search for
  68.      */
  69.     protected native int classDepth(String name);
  70.  
  71.     /**
  72.      * 
  73.      */
  74.     protected native int classLoaderDepth();
  75.  
  76.     /**
  77.      * Returns true if the specified String is in this Class. 
  78.      * @param name the name of the class
  79.      */
  80.     protected boolean inClass(String name) {
  81.     return classDepth(name) >= 0;
  82.     }
  83.  
  84.     /**
  85.      * Returns a boolean indicating whether or not the current ClassLoader
  86.      * is equal to null.
  87.      */
  88.     protected boolean inClassLoader() {
  89.     return currentClassLoader() != null;
  90.     }
  91.  
  92.     /**
  93.      * Returns an implementation-dependent Object which encapsulates
  94.      * enough information about the current execution environment
  95.      * to perform some of the security checks later.
  96.      */
  97.     public Object getSecurityContext() {
  98.     return null;
  99.     }
  100.  
  101.     /**
  102.      * Checks to see if the ClassLoader has been created.
  103.      * @exception SecurityException If a security error has occurred.
  104.      */
  105.     public void checkCreateClassLoader() {
  106.     throw new SecurityException();
  107.     }
  108.     
  109.     /**
  110.      * Checks to see if the specified Thread is allowed to modify
  111.      * the Thread group.
  112.      * @param g the Thread to be checked
  113.      * @exception SecurityException If the current Thread is not
  114.      * allowed to access this Thread group.
  115.      */
  116.     public void checkAccess(Thread g) {
  117.     throw new SecurityException();
  118.     }
  119.  
  120.     /**
  121.      * Checks to see if the specified Thread group is allowed to 
  122.      * modify this group.
  123.      * @param g the Thread group to be checked
  124.      * @exception  SecurityException If the current Thread group is 
  125.      * not allowed to access this Thread group.
  126.      */
  127.     public void checkAccess(ThreadGroup g) {
  128.     throw new SecurityException();
  129.     }
  130.  
  131.     /**
  132.      * Checks to see if the system has exited the virtual 
  133.      * machine with an exit code.
  134.      * @param status exit status, 0 if successful, other values
  135.      * indicate various error types.
  136.      * @exception  SecurityException If a security error has occurred.
  137.      */
  138.     public void checkExit(int status) {
  139.     throw new SecurityException();
  140.     }
  141.  
  142.     /**
  143.      * Checks to see if the system command is executed by 
  144.      * trusted code.
  145.      * @param cmd the specified system command
  146.      * @exception  SecurityException If a security error has occurred.
  147.      */
  148.     public void checkExec(String cmd) {
  149.     throw new SecurityException();
  150.     }
  151.  
  152.     /**
  153.      * Checks to see if the specified linked library exists.
  154.      * @param lib the name of the library
  155.      * @exception  SecurityException If the library does not exist.
  156.      */
  157.     public void checkLink(String lib) {
  158.     throw new SecurityException();
  159.     }
  160.  
  161.     /**
  162.      * Checks to see if an input file with the specified
  163.      * file descriptor object gets created.
  164.      * @param fd the system dependent file descriptor
  165.      * @exception  SecurityException If a security error has occurred.
  166.      */
  167.     public void checkRead(FileDescriptor fd) {
  168.     throw new SecurityException();
  169.     }
  170.  
  171.     /**
  172.      * Checks to see if an input file with the specified system dependent
  173.      * file name gets created.
  174.      * @param file the system dependent file name
  175.      * @exception  SecurityException If the file is not found.
  176.      */
  177.     public void checkRead(String file) {
  178.     throw new SecurityException();
  179.     }
  180.  
  181.     /**
  182.      * Checks to see if the current context or the indicated context are
  183.      * both allowed to read the given file name.
  184.      * @param file the system dependent file name
  185.      * @param context the alternate execution context which must also
  186.      * be checked
  187.      * @exception  SecurityException If the file is not found.
  188.      */
  189.     public void checkRead(String file, Object context) {
  190.     throw new SecurityException();
  191.     }
  192.  
  193.     /**
  194.      * Checks to see if an output file with the specified 
  195.      * file descriptor object gets created.
  196.      * @param fd the system dependent file descriptor
  197.      * @exception  SecurityException If a security error has occurred.
  198.      */
  199.     public void checkWrite(FileDescriptor fd) {
  200.     throw new SecurityException();
  201.     }
  202.  
  203.     /**
  204.      * Checks to see if an output file with the specified system dependent
  205.      * file name gets created.
  206.      * @param file the system dependent file name
  207.      * @exception  SecurityException If the file is not found.
  208.      */
  209.     public void checkWrite(String file) {
  210.     throw new SecurityException();
  211.     }
  212.  
  213.     /**
  214.      * Checks to see if a file with the specified system dependent
  215.      * file name can be deleted.
  216.      * @param file the system dependent file name
  217.      * @exception  SecurityException If the file is not found.
  218.      */
  219.     public void checkDelete(String file) {
  220.     throw new SecurityException();
  221.     }
  222.  
  223.     /**
  224.      * Checks to see if a socket has connected to the specified port on the
  225.      * the specified host.
  226.      * @param host the host name port to connect to
  227.      * @param port the protocol port to connect to
  228.      * @exception  SecurityException If a security error has occurred.
  229.      */
  230.     public void checkConnect(String host, int port) {
  231.     throw new SecurityException();
  232.     }
  233.  
  234.     /**
  235.      * Checks to see if the current execution context and the indicated
  236.      * execution context are both allowed to connect to the indicated
  237.      * host and port.
  238.      */
  239.     public void checkConnect(String host, int port, Object context) {
  240.     throw new SecurityException();
  241.     }
  242.  
  243.     /**
  244.      * Checks to see if a server socket is listening to the specified local
  245.      * port that it is bounded to.
  246.      * @param port the protocol port to connect to
  247.      * @exception  SecurityException If a security error has occurred.
  248.      */
  249.     public void checkListen(int port) {
  250.     throw new SecurityException();
  251.     }
  252.  
  253.     /**
  254.      * Checks to see if a socket connection to the specified port on the 
  255.      * specified host has been accepted.
  256.      * @param host the host name to connect to
  257.      * @param port the protocol port to connect to
  258.      * @exception  SecurityException If a security error has occurred.
  259.      */
  260.     public void checkAccept(String host, int port) {
  261.     throw new SecurityException();
  262.     }
  263.  
  264.     /**
  265.      * Checks to see who has access to the System properties.
  266.      * @exception  SecurityException If a security error has occurred.
  267.      */
  268.     public void checkPropertiesAccess() {
  269.     throw new SecurityException();
  270.     }
  271.  
  272.     /**
  273.      * Checks to see who has access to the System property named by <i>key</i>.
  274.      * @param key the System property that the caller wants to examine
  275.      * @exception  SecurityException If a security error has occurred.
  276.      */
  277.     public void checkPropertyAccess(String key) {
  278.     throw new SecurityException();
  279.     }
  280.  
  281.     /**
  282.      * Checks to see who has access to the System property named by <i>key</i>
  283.      * and <i>def</i>.
  284.      * @param key the System property that the caller wants to examine
  285.      * @param def default value to return if this property is not defined
  286.      * @exception  SecurityException If a security error has occurred.
  287.      */
  288.     public void checkPropertyAccess(String key, String def) {
  289.     throw new SecurityException();
  290.     }
  291.  
  292.     /**
  293.      * Checks to see if top-level windows can be created by the
  294.      * caller. A return of false means that the window creation is
  295.      * allowed but the window should indicate some sort of visual
  296.      * warning. Returning true means the creation is allowed with no
  297.      * special restrictions. To disallow the creation entirely, this
  298.      * method should throw a SecurityException.
  299.      * @param window the new window that's being created.
  300.      */
  301.     public boolean checkTopLevelWindow(Object window) {
  302.     return false;
  303.     }
  304.  
  305.     /**
  306.      * Checks to see if an applet can access a package.
  307.      */
  308.     public void checkPackageAccess(String pkg) {
  309.     throw new SecurityException();
  310.     }
  311.  
  312.     /**
  313.      * Checks to see if an applet can define classes in a package.
  314.      */
  315.     public void checkPackageDefinition(String pkg) {
  316.     throw new SecurityException();
  317.     }
  318.  
  319.     /**
  320.      * Checks to see if an applet can set a networking-related object factory.
  321.      */
  322.     public void checkSetFactory() {
  323.     throw new SecurityException();
  324.     }
  325. }    
  326.