tags:

views:

114

answers:

1

Is there a way to put advice on any method with a parameter of a given type. I'm planning to use this for a class that needs input filtering.

As an example:

@Filtered
class Unsafe {
    public void doStuff (String input) { ... }

    public void doMoreStuff (String input, int value, String name) { ... }
}

I want to write advice that applies to any string parameter of the methods in this class, such that I can replace their contents with a safe, escaped, version (to prevent e.g. SQL injection).

Is it possible to write such a pointcut?

A: 

Since you can have more than one string, in different places, I don't see how you can do it, but, both classes should call the same method that will write to the database. At that point you can use an around to change the string to make it safe and pass that one instead.

James Black
Yes, I could do it on the database layer too, but that still doesn't prevent me from cross-side-scripting injection. Therefore I wanted to do this on the facade that first accepts input from the web. Tricky.
Ruben Vermeersch
Why not put an annotation by each method that is unfiltered, such as @Unfiltered, and then you can write an aspect for that annotation, but you may still need to know which parameters to target.
James Black