I have a basic Spring MVC controller that looks like this:
@Controller
public void MyController {
@RequestMapping("/secret")
public String show() {
return "secret.jsp";
}
}
I am going to have several similar URLs that can only be reached by signed-in users. Since this is a cross-cutting concern, I’d like to use AOP, and I’d like to make this work via annotations. In other words, I’d like to throw a @RequiresLogin annotation on every controller method that needs to be secret.
AnnotationMethodHandlerAdapter supports the concept of interceptors, which seems on the surface like the right way to go for this. However, I want to know which method is going to be invoked so that I can check it for my @RequiresLogin annotation. I see that there’s an “Object handler” parameter that’s passed in, but I’m not sure how to turn that into a Class and Method that will be invoked.
Ideas?
As axtavt writes correctly, Spring-AOP works well with controllers if using proxy-target-class. But there is also the possibility of using JDK proxies if you follow some (tedious) conventions:
Source: 15.3.2 Mapping requests with @RequestMapping