Announcement Announcement Module
Collapse
No announcement yet.
Can't apply security interceptors when using Controller annotations? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't apply security interceptors when using Controller annotations?

    I have a project written using the inheritance & XML config method for controllers:

    Code:
    public class MyController extends SimpleFormController...
    then in my app-servlet.xml I configure the controller with some security interceptors:

    Code:
    	<bean id="myController"
    		class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="target">
    			<ref local="myControllerTarget" />
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>LoginAdvisor</value>
    				<value>AdminAdvisor</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="myControllerTarget" class="com.app.ui.controllers.MyController" />
    
    	<bean
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
    		id="urlMapping">
    		<prop key="/somePage.html">myController</prop>
    This all works perfectly. I am still building this app for the client, however, and I've started to use Spring's new annotation driven controller system plus @Resource/Autowiring + @RequestMapping, @ModelAttribute, etc so I don't need any XML config.

    I got the two methods to work well together except for those security interceptors. I've been pulling my hair out on this one for a while.. At first I was looking for a way to apply the LoginAdvisor, AdminAdvisor, etc. via some nice annotation on the Controller, but at this point I'd settle for anything.

    When I try to take my new-style controllers (using @Controller, @RequestMapping) and make a <bean> entry for them + urlMapping entry + wrap them like before, it simply won't resolve. I even tried taking out the @Controller but it won't work because I think the @RequestMapping and the manual urlMapping entry are conflicting.

  • #2
    Use normal aop to apply the stuff you want instead of an Interceptor. Don't use a ProxyFactoryBean. I suggest you read Chapter 6 of the reference guide.

    If you want to minimize the amount of XML you want to write an @Aspect, if you are fine with some xml simply use an aop:config block.

    Comment

    Working...
    X