Spring The capabilities of AOP are quite large, and this makes it easy to add cool and useful annotations to the controllers. For example, I wrote an @Authenticated annotation, which either allows authenticated users to go to the controller method, or redirects to the login page. Interesting stuff.
However, Spring controllers can return all kinds of types. They can return String, ModelAndView, or even void objects. My code base has methods that use all three types. However, I would like to modify the @Authenticated annotation to render and return the specific page I was hoping to do by returning a ModelAndView object. The only way to achieve this is by requiring all my controller methods to return a ModelAndView?
An example of a controller that I would like to have:
@Controller public class MyController() { @Authenticated @RequestMapping("/myscore") public String myScorePage(ModelMap model) { return "myScorePage"; } @Authenticated @RequestMapping("/anotherPage") public ModelAndView something() { return new ModelAndView("anotherPage",someModelStuff()); } } @Aspect public class NotVeryUsefulAspect { @Around("@annotation(Authenticate)") public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { if( isAuthenticated() ) { return pjp.proceed(); } else { return } } }
source share