prefixMethod appeared only in 5.0.6 (AFAIR). Now it's possible to implement method transformation. Here is working code from our project:

// Add to transform method
for (TransformMethodSignature method : transformation.findMethodsWithAnnotation(Secured.class)) {
   transformMethod(transformation, method);
}


   // Add the following method to worker
   private void transformMethod(final ClassTransformation transformation,
           final TransformMethodSignature method) {
       // Security checker
final String interField = transformation.addInjectedField(SecurityChecker.class,
               "_$checker", securityChecker);

       // Attribute definition
final Secured annotation = transformation.getMethodAnnotation(method, Secured.class); final String configField = createConfigAttributeDefinitionField(transformation,
               annotation);

       final String tokenField = transformation.addField(Modifier.PRIVATE,
"org.acegisecurity.intercept.InterceptorStatusToken", "token");

       // Extend method with security checks.
       StringBuilder prefixBody = new StringBuilder();
       prefixBody.append(tokenField);
       prefixBody.append(" = ");
       prefixBody.append(interField);
       prefixBody.append(".checkBefore(");
       prefixBody.append(configField);
       prefixBody.append(");\n");
       transformation.prefixMethod(method, prefixBody.toString());

       StringBuilder suffixBody = new StringBuilder();
       suffixBody.append("    $_ = ");
       suffixBody.append(interField);
       suffixBody.append(".checkAfter(");
       suffixBody.append(tokenField);
       suffixBody.append(", $_);\n");
       transformation.extendMethod(method, suffixBody.toString());
   }



ryanskow wrote:
Judging by the commented out line in AcegiWorker:
//transformation.renameAndExtendMethod(method, newMethodName,
methodBody.toString());

I'm guessing there is an issue with renaming and extending the method.  Did
that method exist at one point and suddenly go away or has method security
never been functional?  I was able to somewhat get things to work by doing:
        transformation.prefixMethod(method,
"System.out.println(\"PREFIX!!!!!\");\n"+
                "org.acegisecurity.intercept.InterceptorStatusToken token =
"
                + interField + ".checkBefore(" + configField + ");\n");

The problem with that is that the checkAfter is never invoked.  For my test
application I didn't see any negative ramifications of that, but I'm
guessing it was there for a reason.

I was also able to hack it to get the checkAfter in there as well, but then
the Tapestry injection mechanism stopped working for the methods that get
moved and replaced with the instrumented security method.  If interested, I
can send you my hack...  If you have other specific issues you have
encountered, let me know and I'll try to take a look.


Robin Helgelin wrote:
Thanks. I've began working on this, but I got stuck and haven't had
much time to look at it. I'll try to get time to work on it.

--
        regards,
        Robin

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
WBR,
Ivan S. Dubrov

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to