KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > martiansoftware > nailgun > NGSecurityManager


1 /*
2
3 Copyright 2004, Martian Software, Inc.
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 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 JavaDoc;
22
23 import java.io.PrintStream JavaDoc;
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 JavaDoc {
34         private static final ThreadLocal JavaDoc EXIT = new InheritableThreadLocal JavaDoc();
35         final SecurityManager JavaDoc 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 JavaDoc 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 JavaDoc exit = (PrintStream JavaDoc)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 JavaDoc perm) {
60                 if (base != null) {
61                         base.checkPermission(perm);
62                 }
63         }
64    
65         public void checkPermission(Permission JavaDoc perm, Object JavaDoc context) {
66                 if (base != null) {
67                         base.checkPermission(perm, context);
68                 }
69         }
70         
71         public static void setExit (PrintStream JavaDoc exit) {
72                 EXIT.set(exit);
73         }
74 }
Popular Tags