/Users/lyon/j4p/src/javagroup/process/ProcessSecurityManager.java
|
1 /*
2 * Copyright (C) 1997 Luke Gorrie
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
17 * MA 02139, USA.
18 */
19
20 package javagroup.process;
21
22 import javagroup.util.WindowResource;
23
24 import java.awt.*;
25 import java.io.FileDescriptor;
26 import java.net.InetAddress;
27
28 /**
29 * SecurityManager facilitating process identification.
30 *
31 * @author Luke Gorrie
32 */
33 public class ProcessSecurityManager extends SecurityManager {
34
35 protected ProcessManager _manager;
36
37 public ProcessSecurityManager(ProcessManager manager) {
38 _manager = manager;
39 }
40
41 ProcessSecurityManager() {
42 super();
43 }
44
45 void setProcessManager(ProcessManager manager) {
46 _manager = manager;
47 }
48
49 public JProcess getCurrentProcess() {
50 ThreadGroup group = getThreadGroup();
51
52 JProcess match = null;
53
54 match = _manager.getProcessFor(group);
55
56 if (match != null) {
57 return match;
58 }
59
60 Class[] class_context = getClassContext();
61 for (int i = 0; i < class_context.length; i++) {
62 ClassLoader loader = class_context[i].getClassLoader();
63 if (loader != null) {
64 match = _manager.getProcessFor(loader);
65 if (match != null)
66 return match;
67 }
68 }
69
70 return null;
71
72 }
73
74 public void checkCreateClassLoader() {
75 }
76
77 public void checkAccess(Thread g) {
78 }
79
80 public void checkAccess(ThreadGroup g) {
81 }
82
83 public void checkExit(int status) {
84
85 JProcess process = getCurrentProcess();
86 if (process != null)
87 _manager.kill(process.getPid());
88
89 throw new SecurityException();
90 }
91
92 public void checkExec(String cmd) { /* DEBUG throw new SecurityException(); */
93 }
94
95 public void checkLink(String lib) {
96 }
97
98 public void checkRead(FileDescriptor fd) {
99 }
100
101 public void checkRead(String file) {
102 }
103
104 public void checkRead(String file, Object context) {
105 }
106
107 public void checkWrite(FileDescriptor fd) {
108 }
109
110 public void checkWrite(String file) {
111 }
112
113 public void checkDelete(String file) {
114 }
115
116 public void checkConnect(String host, int port) {
117 }
118
119 public void checkConnect(String host, int port, Object context) {
120 }
121
122 public void checkListen(int port) {
123 }
124
125 public void checkAccept(String host, int port) {
126 }
127
128 public void checkMulticast(InetAddress maddr) {
129 }
130
131
132 public void checkPropertiesAccess() {
133 }
134
135 public void checkPropertyAccess(String key) {
136 }
137
138 public void checkPropertyAccess(String key, String def) {
139 }
140
141 public boolean checkTopLevelWindow(Object obj) {
142
143 Window window = null;
144 if (obj instanceof Window)
145 window = (Window) obj;
146 JProcess process = _manager.getCurrentProcess();
147 if ((process != null) && (window != null)) {
148 process.registerAndBindToResource(new WindowResource(window));
149 }
150
151 return true;
152
153 }
154
155 public void checkPrintJobAccess() {
156 }
157
158 public void checkSystemClipboardAccess() {
159 }
160
161 public void checkAwtEventQueueAccess() {
162 }
163
164 public void checkPackageAccess(String pkg) {
165 }
166
167 public void checkPackageDefinition(String pkg) {
168 }
169
170 public void checkSetFactory() {
171 }
172
173 public void checkMemberAccess(Class clazz, int which) {
174 }
175
176 public void checkSecurityAccess(String provider) {
177 }
178 }
179