|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| NoExitSecurityManager.java | 100% | 100% | 75% | 92.3% |
|
||||||||||||||
| 1 |
package abbot;
|
|
| 2 |
|
|
| 3 |
public abstract class NoExitSecurityManager extends SecurityManager { |
|
| 4 |
private Exception creation;
|
|
| 5 | 31 |
public NoExitSecurityManager() {
|
| 6 |
class CreationLocationException extends Exception { } |
|
| 7 | 31 |
creation = new CreationLocationException();
|
| 8 |
} |
|
| 9 |
|
|
| 10 | 0 |
public void checkPermission(java.security.Permission perm, |
| 11 |
Object context) {
|
|
| 12 |
// allow everything
|
|
| 13 |
} |
|
| 14 | 7124 |
public void checkPermission(java.security.Permission perm) { |
| 15 |
// allow everything
|
|
| 16 |
} |
|
| 17 | 3 |
public void checkExit(int status) { |
| 18 |
// We only want to disallow Runtime.halt/Runtime.exit
|
|
| 19 |
// Anything else is ok (e.g. System.runFinalizersOnExit; some VMs do a
|
|
| 20 |
// check there as well -- 1.3 and prior, I think)
|
|
| 21 | 3 |
String stack = Log.getStack(Log.FULL_STACK); |
| 22 | 3 |
if (stack.indexOf("java.lang.Runtime.exit") != -1 |
| 23 |
|| stack.indexOf("java.lang.Runtime.halt") != -1) {
|
|
| 24 | 2 |
exitCalled(status); |
| 25 | 2 |
String msg = "Application exit denied";
|
| 26 | 2 |
Log.log(msg + " from security manager "
|
| 27 |
+ "created at " + Log.getStack(Log.FULL_STACK, creation));
|
|
| 28 | 2 |
throw new ExitException(msg, status); |
| 29 |
} |
|
| 30 |
} |
|
| 31 |
/** Implement this method to do any context-specific cleanup. This
|
|
| 32 |
hook is provided since it may not always be possible to catch the
|
|
| 33 |
ExitException explicitly (like when it's caught by someone else, or
|
|
| 34 |
thrown from the event dispatch thread).
|
|
| 35 |
*/
|
|
| 36 |
protected abstract void exitCalled(int status); |
|
| 37 |
} |
|
| 38 |
|
|
||||||||||