01: /*
02:
03: Copyright 2004, Martian Software, Inc.
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16:
17: */
18:
19: package com.martiansoftware.nailgun;
20:
21: import java.security.Permission;
22:
23: import java.io.PrintStream;
24:
25: /**
26: * Security manager which does nothing other than trap
27: * checkExit, or delegate all non-deprecated methods to
28: * a base manager.
29: *
30: * @author Pete Kirkham
31: *
32: */
33: public class NGSecurityManager extends SecurityManager {
34: private static final ThreadLocal EXIT = new InheritableThreadLocal();
35: final SecurityManager base;
36:
37: /**
38: * Construct an NGSecurityManager with the given base.
39: * @param base the base security manager, or null for no base.
40: */
41: public NGSecurityManager(SecurityManager base) {
42: this .base = base;
43: }
44:
45: public void checkExit(int status) {
46: if (base != null) {
47: base.checkExit(status);
48: }
49:
50: final PrintStream exit = (PrintStream) EXIT.get();
51:
52: if (exit != null) {
53: exit.println(status);
54: }
55:
56: throw new NGExitException(status);
57: }
58:
59: public void checkPermission(Permission perm) {
60: if (base != null) {
61: base.checkPermission(perm);
62: }
63: }
64:
65: public void checkPermission(Permission perm, Object context) {
66: if (base != null) {
67: base.checkPermission(perm, context);
68: }
69: }
70:
71: public static void setExit(PrintStream exit) {
72: EXIT.set(exit);
73: }
74: }
|