What is the AspectJ declarative syntax for overwritting an argument

后端 未结 2 1128
余生分开走
余生分开走 2021-01-01 07:18

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

But I can\'t figure out how to do it with the AspectJ declarative syn

2条回答
  •  情书的邮戳
    2021-01-01 08:03

    I got the annotation version working:

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

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

提交回复
热议问题