什么是覆盖参数的AspectJ声明性语法 [英] What is the AspectJ declarative syntax for overwritting an argument

查看:206
本文介绍了什么是覆盖参数的AspectJ声明性语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前已经使用注释语法解答了这个问题: Aspectj覆盖了一个参数方法

This has been answered before with annotation syntax: Aspectj overwrite an argument of a method

但我无法弄清楚如何使用AspectJ声明性语法。
以下内容应在方法中的每个字符串前添加Poop,但不包括。

But I can't figure out how to do it with the AspectJ declarative syntax. The following should add "Poop" in front of each string in the method but it does not.

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();
    }

}

我无法弄清楚给proceed()所有参数。

I can't figure out how to give "proceed()" all the arguments.

推荐答案

我得到了注释版本:

@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);
    }
}

现在我对所有Spring MVC控制器都有XSS保护。我希望得到aspectJ语法。

Now I have XSS protection for all my Spring MVC controllers. I was hoping to get the aspectJ syntax working though.

这篇关于什么是覆盖参数的AspectJ声明性语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆