diff --git a/src/test/org/apache/commons/logging/security/MockSecurityManager.java b/src/test/org/apache/commons/logging/security/MockSecurityManager.java new file mode 100644 index 0000000..5a4c601 --- /dev/null +++ b/src/test/org/apache/commons/logging/security/MockSecurityManager.java @@ -0,0 +1,85 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.logging.security; + +import java.io.FilePermission; +import java.security.Permission; +import java.util.PropertyPermission; + + +/** + * Custom implementation of a security manager, so we can control the + * security environment for tests in this package. + *
+ * Note that we don't want to refuse permission to any junit method; otherwise
+ * any call to an assert will not be able to output its data!
+ */
+public class MockSecurityManager extends SecurityManager {
+ public void checkPermission(Permission p) throws SecurityException {
+ // System.out.println("\n\ntesting permission:" + p.getClass() + ":"+ p);
+
+ // allow read-only access to files, as this is needed to load classes!
+ if (p instanceof FilePermission) {
+ FilePermission fp = (FilePermission) p;
+ if (fp.getActions().equals("read")) {
+ return;
+ }
+ }
+
+ Exception e = new Exception();
+ e.fillInStackTrace();
+ StackTraceElement[] stack = e.getStackTrace();
+
+ boolean isControlled = false;
+ // start at 1 to skip the entry in the stack for this method
+ for(int i=1; i