sysModel
Class MBSSecurityManager

java.lang.Object
  extended by java.lang.SecurityManager
      extended by sysModel.MBSSecurityManager

public class MBSSecurityManager
extends java.lang.SecurityManager

Special security manager that does not permit fish to call System.exit() or System.setSecurityManager().

Author:
Mathias Ricken

Field Summary
private  MBSClassLoader _classLoader
          Class loader.
private  java.lang.String _classPath
          Class path.
private  java.lang.String[] _classPathDirs
          Class path directories.
private  boolean _drJava
          True if DrJava is present.
private  java.lang.ThreadGroup _fishThreadGroup
          Fish thread group.
private  boolean _isProtected
          Flag if actions are protected.
private  java.lang.String _pathSep
          Path separator.
private  java.util.Stack<java.lang.Boolean> _protectionFlagStack
          Stack of protection flags.
private  java.lang.SecurityManager _sm
          SecurityManager to delegate to.
 
Fields inherited from class java.lang.SecurityManager
inCheck
 
Constructor Summary
MBSSecurityManager(boolean drJava)
          Constructor.
 
Method Summary
 void checkAccess(java.lang.Thread t)
          Throws a SecurityException if the calling thread is not allowed to modify the thread argument.
 void checkAccess(java.lang.ThreadGroup g)
          Throws a SecurityException if the calling thread is not allowed to modify the thread group argument.
 void checkExit(int status)
          Throws a SecurityException if the calling thread is not allowed to cause the Java Virtual Machine to halt with the specified status code.
 void checkPermission(java.security.Permission perm)
          Throws a SecurityException if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.
 java.lang.ClassLoader getClassLoader()
          Return the class loader.
 java.lang.ThreadGroup getFishThreadGroup()
          Get the thread group the fish are run in.
protected  boolean isFishCaller()
          Returns true if a fish is somewhere on the call stack.
protected  boolean isOnClassPath(java.lang.String filename)
          Returns true if the filename is on the class path.
 boolean isProtected()
          Get the protection flag.
 void popProtected()
          Pops the top protection flag from the stack and sets it as new value.
 void pushProtected(boolean isProtected)
          Push the current protection flag onto the stack and set a new value.
 void setProtected(boolean isProtected)
          Set the protection flag.
 
Methods inherited from class java.lang.SecurityManager
checkAccept, 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, currentClassLoader, currentLoadedClass, getClassContext, getInCheck, getSecurityContext, getThreadGroup, inClass, inClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_drJava

private boolean _drJava
True if DrJava is present.


_isProtected

private boolean _isProtected
Flag if actions are protected.


_sm

private java.lang.SecurityManager _sm
SecurityManager to delegate to.


_classPath

private java.lang.String _classPath
Class path.


_pathSep

private java.lang.String _pathSep
Path separator.


_classPathDirs

private java.lang.String[] _classPathDirs
Class path directories.


_fishThreadGroup

private java.lang.ThreadGroup _fishThreadGroup
Fish thread group.


_classLoader

private MBSClassLoader _classLoader
Class loader.


_protectionFlagStack

private java.util.Stack<java.lang.Boolean> _protectionFlagStack
Stack of protection flags.

Constructor Detail

MBSSecurityManager

public MBSSecurityManager(boolean drJava)
Constructor.

Parameters:
drJava - true if DrJava is running
Method Detail

setProtected

public void setProtected(boolean isProtected)
Set the protection flag.

Parameters:
isProtected - true if actions are to be protected

isProtected

public boolean isProtected()
Get the protection flag.

Returns:
true if actions are to be protected

pushProtected

public void pushProtected(boolean isProtected)
Push the current protection flag onto the stack and set a new value.

Parameters:
isProtected - true if actions are to be protected

popProtected

public void popProtected()
Pops the top protection flag from the stack and sets it as new value.


isOnClassPath

protected boolean isOnClassPath(java.lang.String filename)
Returns true if the filename is on the class path.

Parameters:
filename - filename to test
Returns:
true if on classpath

isFishCaller

protected boolean isFishCaller()
Returns true if a fish is somewhere on the call stack.

Returns:
true if fish is a caller

checkPermission

public void checkPermission(java.security.Permission perm)
Throws a SecurityException if the requested access, specified by the given permission, is not permitted based on the security policy currently in effect.

This method calls AccessController.checkPermission with the given permission.

Overrides:
checkPermission in class java.lang.SecurityManager
Parameters:
perm - the requested permission.
Throws:
java.lang.SecurityException - if access is not permitted based on the current security policy.
java.lang.NullPointerException - if the permission argument is null.
Since:
1.2

checkAccess

public void checkAccess(java.lang.Thread t)
Throws a SecurityException if the calling thread is not allowed to modify the thread argument.

This method is invoked for the current security manager by the stop, suspend, resume, setPriority, setName, and setDaemon methods of class Thread.

If the thread argument is a system thread (belongs to the thread group with a null parent) then this method calls checkPermission with the RuntimePermission("modifyThread") permission. If the thread argument is not a system thread, this method just returns silently.

Applications that want a stricter policy should override this method. If this method is overridden, the method that overrides it should additionally check to see if the calling thread has the RuntimePermission("modifyThread") permission, and if so, return silently. This is to ensure that code granted that permission (such as the SDK itself) is allowed to manipulate any thread.

If this method is overridden, then super.checkAccess should be called by the first statement in the overridden method, or the equivalent security check should be placed in the overridden method.

Overrides:
checkAccess in class java.lang.SecurityManager
Parameters:
t - the thread to be checked.
Throws:
java.lang.SecurityException - if the calling thread does not have permission to modify the thread.
java.lang.NullPointerException - if the thread argument is null.
See Also:
resume, setDaemon, setName, setPriority, stop, suspend, checkPermission

checkAccess

public void checkAccess(java.lang.ThreadGroup g)
Throws a SecurityException if the calling thread is not allowed to modify the thread group argument.

This method is invoked for the current security manager when a new child thread or child thread group is created, and by the setDaemon, setMaxPriority, stop, suspend, resume, and destroy methods of class ThreadGroup.

If the thread group argument is the system thread group ( has a null parent) then this method calls checkPermission with the RuntimePermission("modifyThreadGroup") permission. If the thread group argument is not the system thread group, this method just returns silently.

Applications that want a stricter policy should override this method. If this method is overridden, the method that overrides it should additionally check to see if the calling thread has the RuntimePermission("modifyThreadGroup") permission, and if so, return silently. This is to ensure that code granted that permission (such as the SDK itself) is allowed to manipulate any thread.

If this method is overridden, then super.checkAccess should be called by the first statement in the overridden method, or the equivalent security check should be placed in the overridden method.

Overrides:
checkAccess in class java.lang.SecurityManager
Parameters:
g - the thread group to be checked.
Throws:
java.lang.SecurityException - if the calling thread does not have permission to modify the thread group.
java.lang.NullPointerException - if the thread group argument is null.
See Also:
destroy, resume, setDaemon, setMaxPriority, stop, suspend, checkPermission

checkExit

public void checkExit(int status)
Throws a SecurityException if the calling thread is not allowed to cause the Java Virtual Machine to halt with the specified status code.

This method is invoked for the current security manager by the exit method of class Runtime. A status of 0 indicates success; other values indicate various errors.

This method calls checkPermission with the RuntimePermission("exitVM") permission.

If you override this method, then you should make a call to super.checkExit at the point the overridden method would normally throw an exception.

Overrides:
checkExit in class java.lang.SecurityManager
Parameters:
status - the exit status.
Throws:
java.lang.SecurityException - if the calling thread does not have permission to halt the Java Virtual Machine with the specified status.
See Also:
exit, checkPermission

getFishThreadGroup

public java.lang.ThreadGroup getFishThreadGroup()
Get the thread group the fish are run in.

Returns:
fish thread group

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the class loader.

Returns:
class loader