I have the following code:
class OrderController {
@AllowedScopes({ORDER_CREATE})
@PostMapping("/create")
public CreateOrderResponse createOrder(@Valid @RequestBody OrderRequest request){
}
}
@Aspect
@Component
public class AllowedScopeAspect {
@Pointcut("@annotation(allowedScopes)")
private void callAtAllowedScopes(AllowedScopes allowedScopes) {
// just a pointcut signature
}
@Before(value = "callAtAllowedScopes(allowedScopes)", argNames = "jp,allowedScopes")
public void validateScope(JoinPoint jp, AllowedScopes allowedScopes) {
...
}
}
Aspect code validates if user have required scope. The problem is Aspect code is executed after request body validation. If validation is not OKAY, it is returning validation error. if passes, returning 403 error.
How can I execute aspect code before data binding and validation or control handler stage?