Hi everyone, I'm facing a problem with Spring MVC 2. 5: i want to annotate the methods of a controller, say for access control (yes, i know there are other methods around to do this, like filters and so on, but it's the point of the thread), for example:
Now, i have an aspect that check that every method annotated with "AT NeedAccessControl" should be checked before execution, like:Code:AT Controller public class MyController { AT NeedAccessControl AT RequestMapping public String anAction(ModelMap model){ //..do the business method return "myView"; } }
ok, the code of the aspect is never executed. I think that this caused by the way spring load the AT Controller beans: at context startup time maybe the controller are not loaded, and spring is not aware of that class (and it not "register" the annotated class methods with the aspect) -- but i dont have checked the spring code, so these are my assumptions.Code:AT Aspect public class AccessControlAspect{ AT Autowired //or injected directly, it's the same private SessionCheck sessionCheck; AT Before("needAccessControlMethods()") public void doAccessControl() throws UserNotAuthenticatedException { if(!sessionCheck.validSession()){ throw new UserNotAuthenticatedException(); } } AT Pointcut( "AT annotation(com.my.webapp.util.NeedAccessControl)" ) public void needAccessControlMethods(){} }
Question: it is possible to use the spring-aspect system with AT Controller annotated classes, or it is absolutely infeasible? or it's better if i just drop this thing and go for simple spring request interceptor?
(BTW i can also write a custom methodNameResolver that check if the resolved method is annotated with AT NeedAccessControl annotation, but spring do so already, and i think it will be a lot more slow than using the spring aspect system)
thanks in advance,
Francesco Zanitti
ps. ..well it's quite annoying that this forum doesn't let me write the 'AT' symbol![]()


Reply With Quote
