From bb422ca92588a3dbdb4dbc78af0e881364a98d77 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 2 May 2011 18:39:45 +0000 Subject: [PATCH] 328099: currently inactive examples of how we might turn on a security manager for tests --- .../org/aspectj/tools/ajc/AjcTestCase.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java index 2a4d0e7d2..7a9066a4a 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java @@ -13,18 +13,24 @@ package org.aspectj.tools.ajc; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FilePermission; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.ReflectPermission; import java.net.URL; import java.net.URLClassLoader; +import java.security.Permission; +import java.security.Policy; +import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.PropertyPermission; import java.util.StringTokenizer; import junit.framework.TestCase; @@ -622,7 +628,14 @@ public class AjcTestCase extends TestCase { command.append(" "); command.append(args[i]); } - +// try { +// // Enable the security manager +// Policy.setPolicy(new MyPolicy()); +// SecurityManager sm = new SecurityManager(); +// System.setSecurityManager(sm); +// } catch (SecurityException se) { +// // SecurityManager already set +// } ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); ClassLoader contexClassLoader = Thread.currentThread().getContextClassLoader(); @@ -654,6 +667,15 @@ public class AjcTestCase extends TestCase { // the main method threw an exception... fail("Exception thrown by " + className + ".main(String[]) :" + invTgt.getTargetException()); } finally { + +// try { +// // Enable the security manager +// SecurityManager sm = new SecurityManager(); +// System.setSecurityManager(null); +// } catch (SecurityException se) { +// se.printStackTrace(); +// // SecurityManager already set +// } Thread.currentThread().setContextClassLoader(contexClassLoader); stopCapture(baosErr, baosOut); lastRunResult = new RunResult(command.toString(), new String(baosOut.toByteArray()), new String(baosErr.toByteArray())); @@ -661,6 +683,36 @@ public class AjcTestCase extends TestCase { return lastRunResult; } +// static class MyPolicy extends Policy { +// +// @Override +// public boolean implies(ProtectionDomain domain, Permission permission) { +// // if (permission != SecurityConstants.GET_POLICY_PERMISSION) { +// // // System.out.println(domain + " " + permission.getName()); +// // System.out.println(permission.getName()); +// // } +// // if (true) { +// // return true; +// // } +// if (permission instanceof PropertyPermission) { +// return true; +// } +// if (permission instanceof RuntimePermission) { +// return true; +// } +// if (permission instanceof FilePermission) { +// // System.out.println(permission); +// return true; +// } +// if (permission instanceof ReflectPermission) { +// return true; +// } +// // System.out.println(permission); +// return super.implies(domain, permission); +// // return true; +// } +// } + /* * Must create weaving class loader reflectively using new parent so we don't have a reference to a World loaded from CLASSPATH * which won't be able to resolve Java 5 specific extensions and may cause ClassCastExceptions -- 2.39.5