Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Protecting the joinpoints from being woven?

Here's a runtime aspect that will raise an exception if a method annotated with @Critical (made up annotation) calls any other methods that are advised.

public aspect PreventAdvice {
public pointcut disallowed():
adviceexecution() &&
cflow(execution (@Critical * *.*(..))) &&
!within(PreventAdvice);  // prevent an infinite recursion...
before(): disallowed() {
throw new RuntimeException("Disallowed! "+thisJoinPoint);
}
}

Your automated testing regime will have to catch any violations before deploying to production ;) I don't know of a robust way to accomplish the same thing with a "declare error" statement, but that would be ideal.

It's really useful to think through what a "critical section" means in terms of AspectJ's join point model. In this example, I'm specifically saying I don't want any advice executed while inside @Critical methods. Note that this wouldn't prevent before or after advise for calls to @Critical methods. I'm assuming that's okay. For example, it might be fine to have advice that logs that the program is about to enter a @Critical method and log after it returns.
 
You don't have to use a method (or class) annotation of course, but doing so keeps this aspect generic and robust as the underlying code gets refactored.

dean
On Feb 23, 2008, at 8:43 AM, Kunal Pathak wrote:

Hello All,

I am just curious to know that is there any way (may be specifying some kind of annotation) to protect the joinpoint from being woven? The reason behind my question is “security”.

Thanks,
Kunal.


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Dean Wampler, Ph.D.
dean at objectmentor.com
See also:
http://aquarium.rubyforge.org     AOP for Ruby
http://www.contract4j.org         Design by Contract for Java5




Back to the top