home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / lang / securit1.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  7.8 KB  |  263 lines

  1. /*
  2.  * @(#)SecurityManager.java    1.20 95/10/26  
  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. /**
  23.  * Security Manager. An abstract class that can be subclassed
  24.  * to implement a security policy. It allows the inspection of
  25.  * the classloaders on the execution stack.
  26.  *
  27.  * @author    Arthur van Hoff
  28.  * @version     1.20, 10/26/95
  29.  */
  30. public abstract
  31. class SecurityManager {
  32.     protected boolean inCheck;
  33.  
  34.     /** 
  35.      * Returns whether there is a security check in progress.
  36.      */
  37.     public boolean getInCheck() {
  38.     return inCheck;
  39.     }
  40.  
  41.     /**
  42.      * Constructs a new SecurityManager.
  43.      * @exception SecurityException If the security manager cannot be
  44.      * created.
  45.      */
  46.     protected SecurityManager() {
  47.     if (System.getSecurityManager() != null) {
  48.         throw new SecurityException("can't create SecurityManager");
  49.     }
  50.     }
  51.     
  52.     /**
  53.      * Gets the context of this Class.  
  54.      */
  55.     protected native Class[] getClassContext();
  56.  
  57.     /**
  58.      * The current ClassLoader on the execution stack.
  59.      */
  60.     protected native ClassLoader currentClassLoader();
  61.  
  62.     /**
  63.      * Return the position of the stack frame containing the
  64.      * first occurrence of the named class.
  65.      * @param name classname of the class to search for
  66.      */
  67.     protected native int classDepth(String name);
  68.  
  69.     /**
  70.      * 
  71.      */
  72.     protected native int classLoaderDepth();
  73.  
  74.     /**
  75.      * Returns true if the specified String is in this Class. 
  76.      * @param name the name of the class
  77.      */
  78.     protected boolean inClass(String name) {
  79.     return classDepth(name) >= 0;
  80.     }
  81.  
  82.     /**
  83.      * Returns a boolean indicating whether or not the current ClassLoader
  84.      * is equal to null.
  85.      */
  86.     protected boolean inClassLoader() {
  87.     return currentClassLoader() != null;
  88.     }
  89.  
  90.     /**
  91.      * Checks to see if the ClassLoader has been created.
  92.      * @exception SecurityException If a security error has occurred.
  93.      */
  94.     public void checkCreateClassLoader() {
  95.     throw new SecurityException();
  96.     }
  97.     
  98.     /**
  99.      * Checks to see if the specified Thread is allowed to modify
  100.      * the Thread group.
  101.      * @param g the Thread to be checked
  102.      * @exception SecurityException If the current Thread is not
  103.      * allowed to access this Thread group.
  104.      */
  105.     public void checkAccess(Thread g) {
  106.     throw new SecurityException();
  107.     }
  108.  
  109.     /**
  110.      * Checks to see if the specified Thread group is allowed to 
  111.      * modify this group.
  112.      * @param g the Thread group to be checked
  113.      * @exception  SecurityException If the current Thread group is 
  114.      * not allowed to access this Thread group.
  115.      */
  116.     public void checkAccess(ThreadGroup g) {
  117.     throw new SecurityException();
  118.     }
  119.  
  120.     /**
  121.      * Checks to see if the system has exited the virtual 
  122.      * machine with an exit code.
  123.      * @param status exit status, 0 if successful, other values
  124.      * indicate various error types.
  125.      * @exception  SecurityException If a security error has occurred.
  126.      */
  127.     public void checkExit(int status) {
  128.     throw new SecurityException();
  129.     }
  130.  
  131.     /**
  132.      * Checks to see if the system command is executed by 
  133.      * trusted code.
  134.      * @param cmd the specified system command
  135.      * @exception  SecurityException If a security error has occurred.
  136.      */
  137.     public void checkExec(String cmd) {
  138.     throw new SecurityException();
  139.     }
  140.  
  141.     /**
  142.      * Checks to see if the specified linked library exists.
  143.      * @param lib the name of the library
  144.      * @exception  SecurityException If the library does not exist.
  145.      */
  146.     public void checkLink(String lib) {
  147.     throw new SecurityException();
  148.     }
  149.  
  150.     /**
  151.      * Checks to see if an input file with the specified system dependent
  152.      * file descriptor gets created.
  153.      * @param fd the system dependent file descriptor
  154.      * @exception  SecurityException If a security error has occurred.
  155.      */
  156.     public void checkRead(int fd) {
  157.     throw new SecurityException();
  158.     }
  159.  
  160.     /**
  161.      * Checks to see if an input file with the specified system dependent
  162.      * file name gets created.
  163.      * @param file the system dependent file name
  164.      * @exception  SecurityException If the file is not found.
  165.      */
  166.     public void checkRead(String file) {
  167.     throw new SecurityException();
  168.     }
  169.  
  170.     /**
  171.      * Checks to see if an output file with the specified system dependent
  172.      * file descriptor gets created.
  173.      * @param fd the system dependent file descriptor
  174.      * @exception  SecurityException If a security error has occurred.
  175.      */
  176.     public void checkWrite(int fd) {
  177.     throw new SecurityException();
  178.     }
  179.  
  180.     /**
  181.      * Checks to see if an output file with the specified system dependent
  182.      * file name gets created.
  183.      * @param file the system depepndent file name
  184.      * @exception  SecurityException If the file is not found.
  185.      */
  186.     public void checkWrite(String file) {
  187.     throw new SecurityException();
  188.     }
  189.  
  190.     /**
  191.      * Checks to see if a socket has connected to the specified port on the
  192.      * the specified host.
  193.      * @param host the host name port to connect to
  194.      * @param port the protocol port to connect to
  195.      * @exception  SecurityException If a security error has occurred.
  196.      */
  197.     public void checkConnect(String host, int port) {
  198.     throw new SecurityException();
  199.     }
  200.  
  201.     /**
  202.      * Checks to see if a server socket is listening to the specified local
  203.      * port that it is bounded to.
  204.      * @param port the protocol port to connect to
  205.      * @exception  SecurityException If a security error has occurred.
  206.      */
  207.     public void checkListen(int port) {
  208.     throw new SecurityException();
  209.     }
  210.  
  211.     /**
  212.      * Checks to see if a socket connection to the specified port on the 
  213.      * specified host has been accepted.
  214.      * @param host the host name to connect to
  215.      * @param port the protocol port to connect to
  216.      * @exception  SecurityException If a security error has occurred.
  217.      */
  218.     public void checkAccept(String host, int port) {
  219.     throw new SecurityException();
  220.     }
  221.  
  222.     /**
  223.      * Checks to see who has access to the System properties.
  224.      * @exception  SecurityException If a security error has occurred.
  225.      */
  226.     public void checkPropertiesAccess() {
  227.     throw new SecurityException();
  228.     }
  229.  
  230.     /**
  231.      * Checks to see if top-level windows can be created by the
  232.      * caller. A return of false means that the window creation is
  233.      * allowed but the window should indicate some sort of visual
  234.      * warning. Returning true means the creation is allowed with no
  235.      * special restrictions. To disallow the creation entirely, this
  236.      * method should throw a SecurityException.
  237.      */
  238.     public boolean checkTopLevelWindow() {
  239.     return false;
  240.     }
  241.  
  242.     /**
  243.      * Check if an applet can access a package.
  244.      */
  245.     public void checkPackageAccess(String pkg) {
  246.     throw new SecurityException();
  247.     }
  248.  
  249.     /**
  250.      * Check if an applet can define classes in a package.
  251.      */
  252.     public void checkPackageDefinition(String pkg) {
  253.     throw new SecurityException();
  254.     }
  255.  
  256.     /**
  257.      * Check if an applet can set a networking-related object factory.
  258.      */
  259.     public void checkSetFactory() {
  260.     throw new SecurityException();
  261.     }
  262. }    
  263.