edu.rice.cs.util
Class PreventExitSecurityManager

java.lang.Object
  |
  +--java.lang.SecurityManager
        |
        +--edu.rice.cs.util.PreventExitSecurityManager

public class PreventExitSecurityManager
extends SecurityManager

A security manager to prevent exiting the VM indiscriminately. This manager disallows System.exit (unless you call exitVM(int)). It also disallows setting a security manager, since this would override the exit prevention! If this security manager is enabled and an exit is attempted, either via System.exit or via exitVM(int) when exiting is blocked, a ExitingNotAllowedException will be thrown.

Version:
$Id: PreventExitSecurityManager.java,v 1.3 2002/02/08 14:22:22 brianstoler Exp $

Field Summary
private  boolean _blockExit
          Are we in exit blocking mode?
private  boolean _exitAttempted
          Has an unauthorized exit been attempted?
private  SecurityManager _parent
           
private  boolean _timeToDeactivate
          Is it time to unset this security manager?
private  boolean _timeToExit
          Is it time to exit, for real?
private static Permission SET_MANAGER_PERM
           
 
Fields inherited from class java.lang.SecurityManager
accessClipboardPermission, allPermission, checkAwtEventQueuePermission, checkMemberAccessPermission, createClassLoaderPermission, inCheck, initialized, localListenPermission, packageAccess, packageAccessValid, packageDefinition, packageDefinitionValid, rootGroup, threadGroupPermission, threadPermission, topLevelWindowPermission
 
Constructor Summary
private PreventExitSecurityManager(SecurityManager parent)
          Creates a PreventExitSecurityManager, delegating all permission checks except for exiting to the given parent manager.
 
Method Summary
static PreventExitSecurityManager activate()
          Creates a new exit-preventing security manager, using the previous security manager to delegate to.
 void checkExit(int status)
           
 void checkPermission(Permission perm)
          Disallow setting security manager, but otherwise delegate to parent.
 void deactivate()
          Removes this security manager.
 boolean exitAttempted()
          Returns whether a System.exit was attempted since the last time this method was called.
 void exitVM(int status)
          Exits the VM unless exiting is presently blocked.
 void setBlockExit(boolean b)
          Sets whether exiting the VM is unconditionally blocked or not.
 
Methods inherited from class java.lang.SecurityManager
, checkAccept, checkAccess, checkAccess, checkAwtEventQueueAccess, checkConnect, checkConnect, checkCreateClassLoader, checkDelete, checkExec, checkLink, checkListen, checkMemberAccess, checkMulticast, checkMulticast, checkPackageAccess, checkPackageDefinition, checkPermission, checkPrintJobAccess, checkPropertiesAccess, checkPropertyAccess, checkRead, checkRead, checkRead, checkSecurityAccess, checkSetFactory, checkSystemClipboardAccess, checkTopLevelWindow, checkWrite, checkWrite, classDepth, classLoaderDepth, classLoaderDepth0, currentClassLoader, currentClassLoader0, currentLoadedClass, currentLoadedClass0, getClassContext, getInCheck, getPackages, getRootGroup, getSecurityContext, getThreadGroup, hasAllPermission, inClass, inClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SET_MANAGER_PERM

private static final Permission SET_MANAGER_PERM

_parent

private final SecurityManager _parent

_exitAttempted

private boolean _exitAttempted
Has an unauthorized exit been attempted?

_timeToExit

private boolean _timeToExit
Is it time to exit, for real?

_blockExit

private boolean _blockExit
Are we in exit blocking mode?

_timeToDeactivate

private boolean _timeToDeactivate
Is it time to unset this security manager?
Constructor Detail

PreventExitSecurityManager

private PreventExitSecurityManager(SecurityManager parent)
Creates a PreventExitSecurityManager, delegating all permission checks except for exiting to the given parent manager.
Parameters:
parent - SecurityManager to delegate permission to This may be null, signifying to allow all.
Method Detail

activate

public static PreventExitSecurityManager activate()
Creates a new exit-preventing security manager, using the previous security manager to delegate to.

deactivate

public void deactivate()
Removes this security manager.

exitVM

public void exitVM(int status)
Exits the VM unless exiting is presently blocked. Blocking exit is used in test cases that want to see if we try to exit.

setBlockExit

public void setBlockExit(boolean b)
Sets whether exiting the VM is unconditionally blocked or not. It's useful to block exiting to allow test cases to pretend to exit, just to make sure it would have exited under certain conditions.
Parameters:
b - If true, exiting will never be allowed until set false.

exitAttempted

public boolean exitAttempted()
Returns whether a System.exit was attempted since the last time this method was called.

checkPermission

public void checkPermission(Permission perm)
Disallow setting security manager, but otherwise delegate to parent.
Overrides:
checkPermission in class SecurityManager

checkExit

public void checkExit(int status)
Overrides:
checkExit in class SecurityManager