之前已经使用注释语法对此进行了回答:Aspectj覆盖方法的参数
但我无法弄清楚如何使用AspectJ声明语法来实现它.以下应该在方法中的每个字符串前添加"Poop",但事实并非如此.
public aspect UserInputSanitizerAdvisor {
pointcut unSafeString() : execution(@RequestMapping * * (..));
Object around() : unSafeString() {
//thisJoinPoint.getArgs();
//proceed();
System.out.println("I'm Around");
Object[] args = thisJoinPoint.getArgs();
if (args != null) {
for (int i = 0; i < args.length; i++) {
Object o = args[i];
if (o != null && o instanceof String) {
String s = (String) o;
args[i] = "poop: " + s;
}
}
}
return proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何给出"proceed()"所有的论点.
我得到了注释版本:
@SuppressWarnings("unused")
@Aspect
public class UserInputSanitizerAdivsor {
@Around("execution(@RequestMapping * * (..))")
public Object check(final ProceedingJoinPoint jp) throws Throwable {
Object[] args = jp.getArgs();
if (args != null) {
for (int i = 0; i < args.length; i++) {
Object o = args[i];
if (o != null && o instanceof String) {
String s = (String) o;
args[i] = UserInputSanitizer.sanitize(s);
}
}
}
return jp.proceed(args);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我对所有的Spring MVC控制器都有XSS保护.我希望得到aspectJ语法.
| 归档时间: |
|
| 查看次数: |
4053 次 |
| 最近记录: |