I want to create an annotation which uses an around aspect to scrub parameters with that annotation.
For example, a method could look like:
public void setName(@Scrubbed String name) { ... }
or perhaps
public void setFullName(@Scrubbed String firstName, @Scrubbed String lastName) { ... }
What I would like to do is something along these lines:
Object around(String arg) : call(* *(.., @Scrubbed (String), ..)) {
return proceed(this.scrubString(arg));
}
However, I want to handle any number of arguments in any order. What I have working, but it seems like a hack is this:
Object around() : call(public * *(.., @Scrubbed (String), ..)) {
Method method = MethodSignature.class.cast(thisJoinPoint.getSignature()).getMethod();
Object[] args = thisJoinPoint.getArgs();
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
for (int argIndex = 0; argIndex < args.length; argIndex++) {
for (Annotation paramAnnotation : parameterAnnotations[argIndex]) {
if (!(paramAnnotation instanceof Scrubbed)) {
continue;
}
args[argIndex] = this.scrubString((String)args[argIndex]);
}
}
try {
return method.invoke(thisJoinPoint.getTarget(), args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
I am basically using the joinPoint to gain access to reflection information, and end up using method.invoke instead of proceed().
I would love to be able to access ProceedingJoinPoint and call the proceed(Ojbect[] args) method it provides, but I don't know how to do that using native aspectj syntax.
Any ideas. I supposed I could use annotation @AJ aspectj syntax, but the rest of our aspects are using native syntax.