'How to make validation on url parameter In All controllers - Spring application Using in aspect j

I have a spring application, I want to add high-level validation against all calls to every controller, that will validate path variable value for permission manners

example:

@RestController
@RequestMapping(value = "/user/{userId}", produces = "application/json")
public class ValidationController {


    @PostMapping(value = "/update-status")
    @ResponseBody
    public void updateStatus(@PathVariable Integer userId) {
        ////////some code;
    }
}


Solution 1:[1]

Should be something similar to

@Component
@Aspect
@Order(1)
public class ValidationTokenInterceptor {
    
    @Around("@within(controller)")
    public Object checkController(ProceedingJoinPoint thisJoinPoint, Controller controller) throws Throwable { 
                Object[] args = thisJoinPoint.getArgs();
        MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getStaticPart().getSignature();
        Method method = methodSignature.getMethod();
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        assert args.length == parameterAnnotations.length;
        for (int argIndex = 0; argIndex < args.length; argIndex++) {
            for (Annotation annotation : parameterAnnotations[argIndex]) {
                if (!(annotation instanceof RequestParam))
                    continue;
                RequestParam requestParam = (RequestParam) annotation;
                if (! "accessToken".equals(requestParam.value()))
                    continue;
                System.out.println("  " + requestParam.value() + " = " + args[argIndex]);
            }
        }
        joinPoint.proceed(joinPoint.getArgs());
    }   
}

Credit also to this answer: Retrieve parameter value from ProceedingJoinPoint

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 İsmail Y.