You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2013/02/27 19:52:37 UTC

svn commit: r1450913 - in /commons/sandbox/weaver/branches/mjb: example/src/main/java/org/apache/commons/weaver/privilizer/example/ example/src/test/java/org/apache/commons/weaver/privilizer/example/ modules/privilizer/api/src/main/java/org/apache/comm...

Author: mbenson
Date: Wed Feb 27 18:52:37 2013
New Revision: 1450913

URL: http://svn.apache.org/r1450913
Log:
add blueprint privilizing

Added:
    commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java   (with props)
    commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java   (with props)
    commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java   (with props)
    commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java   (with props)
Modified:
    commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java
    commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java
    commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java

Added: commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java?rev=1450913&view=auto
==============================================================================
--- commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java (added)
+++ commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java Wed Feb 27 18:52:37 2013
@@ -0,0 +1,42 @@
+/*
+ *  Copyright the original author or authors.
+ *
+ *  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.weaver.privilizer.example;
+
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
+@Privilizing({ @CallTo(Utils.class), @CallTo(value = Utils.More.class, methods = "getProperty") })
+public class UsingBlueprints {
+
+    public String utilsGetProperty() {
+        return Utils.getProperty();
+    }
+
+    public String utilsGetProperty(String key) {
+        return Utils.getProperty(key);
+    }
+
+    public String moreGetProperty() {
+        return Utils.More.getProperty();
+    }
+
+    public String moreGetTopStackElementClassName() {
+        return Utils.More.getTopStackElementClassName();
+    }
+
+    private void foo() {
+    }
+}

Propchange: commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java?rev=1450913&view=auto
==============================================================================
--- commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java (added)
+++ commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java Wed Feb 27 18:52:37 2013
@@ -0,0 +1,42 @@
+/*
+ *  Copyright the original author or authors.
+ *
+ *  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.weaver.privilizer.example;
+
+public class Utils {
+    public static class More {
+        private More() {
+        }
+
+        public static String getProperty() {
+            return Utils.getProperty("bar");
+        }
+
+        public static String getTopStackElementClassName() {
+            return Thread.currentThread().getStackTrace()[0].getClassName();
+        }
+    }
+
+    private Utils() {
+    }
+
+    public static String getProperty() {
+        return getProperty("foo");
+    }
+
+    public static String getProperty(String key) {
+        return System.getProperty(key);
+    }
+}

Propchange: commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java?rev=1450913&view=auto
==============================================================================
--- commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java (added)
+++ commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java Wed Feb 27 18:52:37 2013
@@ -0,0 +1,64 @@
+/*
+ *  Copyright the original author or authors.
+ *
+ *  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.weaver.privilizer.example;
+
+import static org.junit.Assert.*;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.junit.Test;
+
+public class UsingBlueprintsTest {
+
+    private UsingBlueprints usingBlueprints;
+
+    public void setUp() throws Exception {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            @Override
+            public Void run() {
+                System.setProperty("foo", "foo-value");
+                System.setProperty("bar", "bar-value");
+                System.setProperty("baz", "baz-value");
+                return null;
+            }
+        });
+        usingBlueprints = new UsingBlueprints();
+    }
+
+//    @Test
+    public void testUtilsGetProperty() {
+        assertEquals("foo", usingBlueprints.utilsGetProperty());
+    }
+
+//    @Test
+    public void testUtilsGetProperty(String key) {
+        assertEquals("foo-value", usingBlueprints.utilsGetProperty("foo"));
+        assertEquals("bar-value", usingBlueprints.utilsGetProperty("bar"));
+        assertEquals("baz-value", usingBlueprints.utilsGetProperty("baz"));
+    }
+
+//    @Test
+    public void testMoreGetProperty() {
+        assertEquals("bar-value", usingBlueprints.moreGetProperty());
+    }
+
+//    @Test
+    public void testMoreGetTopStackElementClassName() {
+        assertEquals(Utils.More.class.getName(), usingBlueprints.moreGetTopStackElementClassName());
+    }
+
+}

Propchange: commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java?rev=1450913&view=auto
==============================================================================
--- commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java (added)
+++ commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java Wed Feb 27 18:52:37 2013
@@ -0,0 +1,35 @@
+/*
+ *  Copyright the original author or authors.
+ *
+ *  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.weaver.privilizer;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that a certain set of method calls should be "blueprint privilized," i.e.,
+ * their method bodies should be (recursively) copied for privileged invocation
+ * per the privilizer policy with which the blueprint privilizer weaver is invoked.
+ */
+@Target(ElementType.TYPE)
+public @interface Privilizing {
+	public @interface CallTo {
+		Class<?> value();
+
+		String[] methods() default {};
+	}
+
+	CallTo[] value();
+}

Propchange: commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java?rev=1450913&r1=1450912&r2=1450913&view=diff
==============================================================================
--- commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java (original)
+++ commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java Wed Feb 27 18:52:37 2013
@@ -17,9 +17,6 @@ package org.apache.commons.weaver.privil
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
 
 import javassist.CannotCompileException;
 import javassist.ClassPool;
@@ -35,7 +32,6 @@ import org.apache.commons.lang3.Validate
  */
 public class FilesystemPrivilizer extends Privilizer<FilesystemPrivilizer> {
 
-
     private static ClassPool createClassPool(ClassLoader classpath, File target) {
         final ClassPool result = new ClassPool();
         try {
@@ -48,27 +44,12 @@ public class FilesystemPrivilizer extend
         return result;
     }
 
-    private static Set<Class<?>> getDeclaringClasses(Iterable<Method> methods) {
-        final Set<Class<?>> declaringClasses = new HashSet<Class<?>>();
-        for (final Method method : methods) {
-            declaringClasses.add(method.getDeclaringClass());
-        }
-        return declaringClasses;
-    }
-
-    private static Class<?> getOutermost(Class<?> type) {
-        Class<?> enclosing = type.getEnclosingClass();
-        return enclosing == null ? type : getOutermost(enclosing);
-    }
-
     private static File validTarget(File target) {
         Validate.notNull(target, "target");
         Validate.isTrue(target.isDirectory(), "not a directory");
         return target;
     }
 
-    private final ClassLoader classpath;
-
     private final File target;
 
     private final ClassFileWriter classFileWriter = new ClassFileWriter() {
@@ -80,29 +61,14 @@ public class FilesystemPrivilizer extend
 
     public FilesystemPrivilizer(ClassLoader classpath, File target) {
         super(createClassPool(classpath, target));
-        this.classpath = classpath;
         this.target = target;
     }
 
     public FilesystemPrivilizer(Policy policy, ClassLoader classpath, File target) {
         super(policy, createClassPool(classpath, target));
-        this.classpath = classpath;
         this.target = target;
     }
 
-    /**
-     * Weave all {@link Privileged} methods found.
-     * 
-     * @throws NotFoundException
-     * @throws IOException
-     * @throws CannotCompileException
-     * @throws ClassNotFoundException
-     */
-    public boolean weaveClass(Class<?> clazz)
-            throws NotFoundException, IOException, CannotCompileException, ClassNotFoundException, IllegalAccessException {
-        return weave(classPool.get(clazz.getName()));
-    }
-
     @Override
     protected ClassFileWriter getClassFileWriter() {
         return classFileWriter;

Modified: commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java?rev=1450913&r1=1450912&r2=1450913&view=diff
==============================================================================
--- commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java (original)
+++ commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java Wed Feb 27 18:52:37 2013
@@ -31,6 +31,7 @@ import java.util.logging.Logger;
 
 import javassist.CannotCompileException;
 import javassist.ClassPool;
+import javassist.CodeConverter;
 import javassist.CtClass;
 import javassist.CtField;
 import javassist.CtMethod;
@@ -39,12 +40,14 @@ import javassist.CtNewMethod;
 import javassist.CtPrimitiveType;
 import javassist.NotFoundException;
 import javassist.bytecode.Descriptor;
+import javassist.expr.ExprEditor;
+import javassist.expr.MethodCall;
 
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.lang3.text.StrBuilder;
-
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
 
 /**
  * Handles weaving of methods annotated with {@link Privileged}.
@@ -76,20 +79,18 @@ public abstract class Privilizer<SELF ex
         NEVER,
 
         /**
-         * Weaves such that the check for an active {@link SecurityManager} is
-         * done once only.
+         * Weaves such that the check for an active {@link SecurityManager} is done once only.
          */
         ON_INIT(generateName("hasSecurityManager")),
 
         /**
-         * Weaves such that the check for an active {@link SecurityManager} is
-         * done for each {@link Privileged} method execution.
+         * Weaves such that the check for an active {@link SecurityManager} is done for each {@link Privileged} method
+         * execution.
          */
         DYNAMIC(HAS_SECURITY_MANAGER_CONDITION),
 
         /**
-         * Weaves such that {@link Privileged} methods are always executed as
-         * such.
+         * Weaves such that {@link Privileged} methods are always executed as such.
          */
         ALWAYS;
 
@@ -170,17 +171,33 @@ public abstract class Privilizer<SELF ex
     }
 
     /**
+     * Weave all {@link Privileged} methods found.
+     * 
+     * @param privilizing
+     * 
+     * @throws NotFoundException
+     * @throws IOException
+     * @throws CannotCompileException
+     * @throws ClassNotFoundException
+     */
+    public boolean weaveClass(Class<?> clazz, Privilizing privilizing) throws NotFoundException, IOException,
+        CannotCompileException, ClassNotFoundException, IllegalAccessException {
+        return weave(classPool.get(clazz.getName()), privilizing);
+    }
+
+    /**
      * Weave the specified class.
      * 
      * @param type
+     * @param privilizing
      * @return whether any work was done
      * @throws NotFoundException
      * @throws IOException
      * @throws CannotCompileException
      * @throws ClassNotFoundException
      */
-    public boolean weave(CtClass type)
-            throws NotFoundException, IOException, CannotCompileException, ClassNotFoundException, IllegalAccessException {
+    private boolean weave(CtClass type, Privilizing privilizing) throws NotFoundException, IOException,
+        CannotCompileException, ClassNotFoundException, IllegalAccessException {
         reportSettings();
         final String policyName = generateName(POLICY_NAME);
         final String policyValue = toString(type.getAttribute(policyName));
@@ -205,8 +222,11 @@ public abstract class Privilizer<SELF ex
                 securityManager.setModifiers(Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL);
                 type.addField(securityManager, CtField.Initializer.byExpr(HAS_SECURITY_MANAGER_CONDITION));
             }
+
+            result = privilizeBlueprints(type, privilizing) | result;
+
             for (final CtMethod m : getPrivilegedMethods(type)) {
-                result |= weave(type, m);
+                result = weave(type, m) | result;
             }
             if (result) {
                 type.setAttribute(policyName, policy.name().getBytes(Charset.forName("UTF-8")));
@@ -217,6 +237,145 @@ public abstract class Privilizer<SELF ex
         return result;
     }
 
+    private boolean privilizeBlueprints(CtClass type, Privilizing annotation) throws CannotCompileException,
+        ClassNotFoundException, NotFoundException, IOException, IllegalAccessException {
+        boolean result = false;
+        if (annotation != null) {
+            for (CtMethod method : type.getDeclaredMethods()) {
+                result = privilizeBlueprints(type, method, annotation.value()) | result;
+            }
+        }
+        return result;
+    }
+
+    private boolean privilizeBlueprints(final CtClass type, final CtMethod method, final CallTo[] blueprintCalls)
+        throws CannotCompileException, ClassNotFoundException, NotFoundException, IOException, IllegalAccessException {
+        boolean result = false;
+
+        final List<CtMethod> blueprints = new ArrayList<CtMethod>();
+        class CollectBlueprints extends ExprEditor {
+            @Override
+            public void edit(MethodCall call) throws CannotCompileException {
+                super.edit(call);
+                CtMethod called;
+                try {
+                    called = call.getMethod();
+                    if (!Modifier.isStatic(called.getModifiers())) {
+                        return;
+                    }
+                } catch (NotFoundException e) {
+                    return;
+                }
+                for (CallTo callTo : blueprintCalls) {
+                    final Class<?> owner = callTo.value();
+                    if (owner.getName().equals(call.getClassName())) {
+                        if (callTo.methods().length > 0) {
+                            boolean found = false;
+                            for (String m : callTo.methods()) {
+                                found = StringUtils.equals(call.getMethodName(), m);
+                                if (found) {
+                                    break;
+                                }
+                            }
+                            if (!found) {
+                                continue;
+                            }
+                        }
+                        blueprints.add(called);
+                        break;
+                    }
+                }
+            }
+        }
+        method.instrument(new CollectBlueprints());
+
+        for (CtMethod blueprint : blueprints) {
+            final String name = importedMethodName(blueprint);
+
+            CtMethod copy = copyBlueprintTo(type, name, blueprint, blueprintCalls);
+            final CodeConverter converter = new CodeConverter();
+            converter.redirectMethodCall(blueprint, copy);
+            method.instrument(converter);
+            result = true;
+        }
+        return result;
+    }
+
+    private static String importedMethodName(CtMethod blueprint) {
+        return new StringBuilder(blueprint.getDeclaringClass().getName().replace('.', '_')).append('$')
+            .append(blueprint.getName()).toString();
+    }
+
+    /*
+     * This design is almost certainly non-optimal. Basically, we have:
+     * 
+     * for a declared method, look for calls to blueprint methods for each blueprint method, copy it when copying,
+     * inspect blueprint method's code and recursively copy in methods from the source class of *that particular method*
+     * because otherwise CtNewMethod will do it for us and we'll miss our window of opportunity now that we have a
+     * copied blueprint method, inspect it for blueprint calls from other classes and do this whole thing recursively.
+     * 
+     * It would *seem* that we could combine the recursion/copying of methods from all blueprint classes but I can't get
+     * my head around it right now. -MJB
+     */
+    private CtMethod copyBlueprintTo(final CtClass target, final String toName, final CtMethod method,
+        final CallTo[] blueprintCalls) throws ClassNotFoundException, NotFoundException, IOException,
+        IllegalAccessException {
+        if (!Modifier.isStatic(method.getModifiers())) {
+            return null;
+        }
+
+        try {
+            final CtMethod done = target.getDeclaredMethod(toName, method.getParameterTypes());
+            return done;
+        } catch (NotFoundException e1) {
+        }
+        final CtClass declaring = method.getDeclaringClass();
+
+        final List<CtMethod> calledBlueprints = new ArrayList<CtMethod>();
+        class CollectBlueprints extends ExprEditor {
+            @Override
+            public void edit(MethodCall m) throws CannotCompileException {
+                super.edit(m);
+                CtMethod called;
+                try {
+                    called = m.getMethod();
+                } catch (NotFoundException e) {
+                    return;
+                }
+                if (!called.equals(method) && called.getDeclaringClass().equals(declaring)) {
+                    calledBlueprints.add(called);
+                }
+            }
+        }
+        try {
+            method.instrument(new CollectBlueprints());
+
+            for (CtMethod blueprint : calledBlueprints) {
+                CtMethod local = copyBlueprintTo(target, importedMethodName(blueprint), blueprint, blueprintCalls);
+                if (local != null) {
+                    method.instrument(redirect(blueprint, local));
+                }
+            }
+            final CtMethod result = CtNewMethod.copy(method, importedMethodName(method), target, null);
+            result.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
+            target.addMethod(result);
+            // recurse:
+            privilizeBlueprints(target, result, blueprintCalls);
+            // privilize:
+            weave(target, result);
+
+            return result;
+        } catch (CannotCompileException e) {
+            return null;
+        }
+    }
+
+    private CodeConverter redirect(CtMethod origMethod, CtMethod substMethod) throws CannotCompileException {
+        final CodeConverter result = new CodeConverter();
+        result.redirectMethodCall(origMethod, substMethod);
+        return result;
+    }
+
     protected void debug(String message, Object... args) {
         log.fine(String.format(message, args));
     }
@@ -350,9 +509,9 @@ public abstract class Privilizer<SELF ex
         NotFoundException, IOException, IllegalAccessException {
         final AccessLevel accessLevel = AccessLevel.of(method.getModifiers());
         if (!permitMethodWeaving(accessLevel)) {
-            throw new IllegalAccessException("Method " + type.getName() + "#" +  toString(method)
-                                             + " must have maximum access level '" + getTargetAccessLevel()
-                                             + "' but is defined wider ('" + accessLevel + "')");
+            throw new IllegalAccessException("Method " + type.getName() + "#" + toString(method)
+                + " must have maximum access level '" + getTargetAccessLevel() + "' but is defined wider ('"
+                + accessLevel + "')");
         }
         if (AccessLevel.PACKAGE.compareTo(accessLevel) > 0) {
             warn("Possible security leak: granting privileges to %s method %s.%s", accessLevel, type.getName(),
@@ -462,4 +621,5 @@ public abstract class Privilizer<SELF ex
             debug("Weave policy == %s", policy);
         }
     }
+
 }

Modified: commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java?rev=1450913&r1=1450912&r2=1450913&view=diff
==============================================================================
--- commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java (original)
+++ commons/sandbox/weaver/branches/mjb/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java Wed Feb 27 18:52:37 2013
@@ -5,7 +5,6 @@ import java.lang.annotation.ElementType;
 import java.net.URLClassLoader;
 import java.util.List;
 import java.util.Properties;
-import java.util.logging.Logger;
 
 import org.apache.commons.weaver.model.ScanRequest;
 import org.apache.commons.weaver.model.ScanResult;
@@ -15,9 +14,8 @@ import org.apache.commons.weaver.spi.Wea
 import org.apache.commons.weaver.utils.URLArray;
 
 /**
- * Weaver which adds doPrivileged blocks for each method annotated with
- * {@link Privileged}. An instance of this class will automatically get picked
- * up by the {@link org.apache.commons.weaver.WeaveProcessor} via the
+ * Weaver which adds doPrivileged blocks for each method annotated with {@link Privileged}. An instance of this class
+ * will automatically get picked up by the {@link org.apache.commons.weaver.WeaveProcessor} via the
  * {@link java.util.ServiceLoader}.
  */
 public class PrivilizerWeaver implements Weaver {
@@ -25,9 +23,7 @@ public class PrivilizerWeaver implements
     public static final String CONFIG_ACCESS_LEVEL = CONFIG_WEAVER + "accessLevel";
     public static final String CONFIG_POLICY = CONFIG_WEAVER + "policy";
 
-    private static final Logger LOG = Logger.getLogger(PrivilizerWeaver.class.getName());
-
-    private FilesystemPrivilizer privilizer;
+    private Privilizer<FilesystemPrivilizer> privilizer;
 
     private Privilizer.Policy policy;
 
@@ -35,8 +31,6 @@ public class PrivilizerWeaver implements
 
     @Override
     public void configure(List<String> classPath, File target, Properties config) {
-        LOG.info("");
-
         String accessLevel = config.getProperty(CONFIG_ACCESS_LEVEL);
         if (accessLevel == null || accessLevel.length() == 0) {
             throw new IllegalArgumentException(CONFIG_ACCESS_LEVEL + " property is missing!");
@@ -65,18 +59,18 @@ public class PrivilizerWeaver implements
 
     @Override
     public ScanRequest getScanRequest() {
-        return new ScanRequest().add(WeaveInterest.of(Privileged.class, ElementType.METHOD));
+        return new ScanRequest().add(WeaveInterest.of(Privileged.class, ElementType.METHOD)).add(
+            WeaveInterest.of(Privilizing.class, ElementType.TYPE));
     }
 
     @Override
     public boolean process(ScanResult scanResult) {
         boolean result = false;
-        Iterable<WeavableClass<?>> classes = scanResult.getClasses();
-        for (WeavableClass<?> weavableClass : classes) {
+        for (WeavableClass<?> weavableClass : scanResult.getClasses()) {
             try {
-                if (privilizer.weaveClass(weavableClass.getTarget())) {
-                    result = true;
-                }
+                result =
+                    privilizer.weaveClass(weavableClass.getTarget(), weavableClass.getAnnotation(Privilizing.class))
+                        | result;
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }