001: /*
002: * TestSecurityContext.java
003: *
004: * Created on October 13, 2006, 5:25 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009: /*
010: * Licensed to the Apache Software Foundation (ASF) under one
011: * or more contributor license agreements. See the NOTICE file
012: * distributed with this work for additional information
013: * regarding copyright ownership. The ASF licenses this file
014: * to you under the Apache License, Version 2.0 (the
015: * "License"); you may not use this file except in compliance
016: * with the License. You may obtain a copy of the License at
017: *
018: * http://www.apache.org/licenses/LICENSE-2.0
019: *
020: * Unless required by applicable law or agreed to in writing,
021: * software distributed under the License is distributed on an
022: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023: * KIND, either express or implied. See the License for the
024: * specific language governing permissions and limitations
025: * under the License.
026: */
027: package org.apache.openjpa.persistence.kernel;
028:
029: import java.io.FileDescriptor;
030: import java.net.InetAddress;
031: import java.security.Permission;
032:
033: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
034:
035: import org.apache.openjpa.persistence.OpenJPAEntityManager;
036:
037: public class TestSecurityContext extends BaseKernelTest {
038:
039: private SecurityManager oldManager;
040: private StrictSecurityManager ssm;
041:
042: /**
043: * Creates a new instance of TestSecurityContext
044: */
045: public TestSecurityContext() {
046: }
047:
048: public TestSecurityContext(String name) {
049: super (name);
050: }
051:
052: public void setUp() {
053: oldManager = System.getSecurityManager();
054: // System.setSecurityManager (ssm = new StrictSecurityManager ());
055: }
056:
057: public void tearDown() throws Exception {
058: System.setSecurityManager(oldManager);
059: oldManager = null;
060: super .tearDown();
061: }
062:
063: public void testInSecureClassLoader() {
064: OpenJPAEntityManager pm = getPM();
065: startTx(pm);
066: pm.createExtent(RuntimeTest1.class, true).iterator().hasNext();
067: endTx(pm);
068: endEm(pm);
069: }
070:
071: public class StrictSecurityManager extends SecurityManager {
072:
073: private void debug(String msg) {
074: // log.debug (msg);
075: }
076:
077: public void checkAccept(String host, int port) {
078: debug("checkAccept: " + host + "," + port);
079: super .checkAccept(host, port);
080: }
081:
082: public void checkAccess(Thread t) {
083: debug("checkAccess: " + t);
084: super .checkAccess(t);
085: }
086:
087: public void checkAccess(ThreadGroup g) {
088: debug("checkAccess: " + g);
089: super .checkAccess(g);
090: }
091:
092: public void checkAwtEventQueueAccess() {
093: debug("checkAwtEventQueueAccess");
094: super .checkAwtEventQueueAccess();
095: }
096:
097: public void checkConnect(String host, int port) {
098: debug("checkConnect: " + host + "," + port);
099: super .checkConnect(host, port);
100: }
101:
102: public void checkConnect(String host, int port, Object context) {
103: debug("checkConnect: " + host + "," + port + "," + context);
104: super .checkConnect(host, port, context);
105: }
106:
107: public void checkCreateClassLoader() {
108: debug("checkCreateClassLoader");
109: super .checkCreateClassLoader();
110: }
111:
112: public void checkDelete(String file) {
113: debug("checkDelete: " + file);
114: super .checkDelete(file);
115: }
116:
117: public void checkExec(String cmd) {
118: debug("checkExec: " + cmd);
119: super .checkExec(cmd);
120: }
121:
122: public void checkExit(int status) {
123: debug("checkExit: " + status);
124: super .checkExit(status);
125: }
126:
127: public void checkLink(String lib) {
128: debug("checkLink: " + lib);
129: super .checkLink(lib);
130: }
131:
132: public void checkListen(int port) {
133: debug("checkListen: " + port);
134: super .checkListen(port);
135: }
136:
137: public void checkMemberAccess(Class clazz, int which) {
138: debug("checkMemberAccess: " + clazz + "," + which);
139: super .checkMemberAccess(clazz, which);
140: }
141:
142: public void checkMulticast(InetAddress maddr) {
143: debug("checkMulticast: " + maddr);
144: super .checkMulticast(maddr);
145: }
146:
147: public void checkMulticast(InetAddress maddr, byte ttl) {
148: debug("checkMulticast: " + maddr + "," + ttl);
149: super .checkMulticast(maddr, ttl);
150: }
151:
152: public void checkPackageAccess(String pkg) {
153: debug("checkPackageAccess: " + pkg);
154: super .checkPackageAccess(pkg);
155: }
156:
157: public void checkPackageDefinition(String pkg) {
158: debug("checkPackageDefinition: " + pkg);
159: super .checkPackageDefinition(pkg);
160: }
161:
162: public void checkPermission(Permission perm) {
163: debug("checkPermission: " + perm);
164: super .checkPermission(perm);
165: }
166:
167: public void checkPermission(Permission perm, Object context) {
168: debug("checkPermission: " + perm + "," + context);
169: super .checkPermission(perm, context);
170: }
171:
172: public void checkPrintJobAccess() {
173: debug("checkPrintJobAccess");
174: super .checkPrintJobAccess();
175: }
176:
177: public void checkPropertiesAccess() {
178: debug("checkPropertiesAccess");
179: super .checkPropertiesAccess();
180: }
181:
182: public void checkPropertyAccess(String key) {
183: debug("checkPropertyAccess: " + key);
184: super .checkPropertyAccess(key);
185: }
186:
187: public void checkRead(FileDescriptor fd) {
188: debug("checkRead: " + fd);
189: super .checkRead(fd);
190: }
191:
192: public void checkRead(String file) {
193: debug("checkRead: " + file);
194: super .checkRead(file);
195: }
196:
197: public void checkRead(String file, Object context) {
198: debug("checkRead: " + file + "," + context);
199: super .checkRead(file, context);
200: }
201:
202: public void checkSecurityAccess(String target) {
203: debug("checkSecurityAccess: " + target);
204: super .checkSecurityAccess(target);
205: }
206:
207: public void checkSetFactory() {
208: debug("checkSetFactory");
209: super .checkSetFactory();
210: }
211:
212: public void checkSystemClipboardAccess() {
213: debug("checkSystemClipboardAccess");
214: super .checkSystemClipboardAccess();
215: }
216:
217: public boolean checkTopLevelWindow(Object window) {
218: debug("checkTopLevelWindow: " + window);
219: return super .checkTopLevelWindow(window);
220: }
221:
222: public void checkWrite(FileDescriptor fd) {
223: debug("checkWrite: " + fd);
224: super .checkWrite(fd);
225: }
226:
227: public void checkWrite(String file) {
228: debug("checkWrite: " + file);
229: super .checkWrite(file);
230: }
231:
232: protected int classDepth(String name) {
233: debug("classDepth: " + name);
234: return super .classDepth(name);
235: }
236:
237: protected int classLoaderDepth() {
238: debug("classLoaderDepth");
239: return super .classLoaderDepth();
240: }
241:
242: protected ClassLoader currentClassLoader() {
243: debug("currentClassLoader");
244: return super .currentClassLoader();
245: }
246:
247: protected Class currentLoadedClass() {
248: debug("currentLoadedClass");
249: return super .currentLoadedClass();
250: }
251:
252: protected Class[] getClassContext() {
253: debug("getClassContext");
254: return super .getClassContext();
255: }
256:
257: public boolean getInCheck() {
258: debug("getInCheck");
259: return super .getInCheck();
260: }
261:
262: public Object getSecurityContext() {
263: debug("getSecurityContext");
264: return super .getSecurityContext();
265: }
266:
267: public ThreadGroup getThreadGroup() {
268: debug("getThreadGroup");
269: return super .getThreadGroup();
270: }
271:
272: protected boolean inClass(String name) {
273: debug("inClass: " + name);
274: return super .inClass(name);
275: }
276:
277: protected boolean inClassLoader() {
278: debug("inClassLoader");
279: return super.inClassLoader();
280: }
281: }
282: }
|