Announcement Announcement Module
Collapse
No announcement yet.
Unable tointercept methods MultiActionController subclass Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable tointercept methods MultiActionController subclass

    The methods on the SimpleController (subclass of MultiactionController) does not get intercepted.
    I want to intercept all methods in SimpleController to enable method level security.
    Any help appreciated.

    Thanks
    Vasanth.



    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
    - DispatcherServlet application context for the Spring web MVC
    -->
    <beans>

    <!-- ========================= DEFINITIONS OF PUBLIC CONTROLLERS ========================= -->

    <bean id="simpleControllerResolver" class="org.springframework.web.servlet.mvc.multiac tion.PropertiesMethodNameResolver">
    <property name="mappings">
    <props>
    <prop key="/simpleController/testRequest.do">testRequest</prop>
    </props>
    </property>
    </bean>

    <bean id="simpleController" class="com.sample.web.SimpleController">
    <property name="methodNameResolver"><ref local="simpleControllerResolver"/></property>
    <property name="sample"><value>EAF Sample</value></property>
    <property name="handlerConfigs">
    <map>
    <entry key="handleRequest">
    <ref local="handleRequestConfig"/>
    </entry>
    </map>
    </property>
    </bean>

    <bean id="securityLogicBean" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target">
    <ref local="simpleController"/>
    </property>
    <property name="interceptorNames">
    <list>
    <value>methodSecurityAdvisor</value>
    </list>
    </property>
    </bean>

    <bean id="methodSecurityAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <ref local="methodSecurityAdvice"/>
    </property>
    <property name="pattern">
    <value>.*</value>
    </property>
    </bean>

    <bean id="methodSecurityAdvice" class="com.eaf2.security.MethodSecurityAdvice"/>
    </beans>
    [/color]

  • #2
    I do not see any HandlerMapping in your servlet.xml. That means Spring will use a default HandlerMapping that forwards to simpleController, which is not what you want to do.
    You can configure a SimpleUrlHandlerMapping and register securityLogicBean as its default handler. This way, simpleController methods will be intercepted:
    Code:
    <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="defaultHandler"><ref local="simpleController"/></property>
    </bean>
    HTH

    Comment


    • #3
      Thanks Irbouho -
      I had split the servlet.xml in 2 files - app-servlet.xml and controller.xml
      the default handler was in app-servlet.xml
      I tried combining both in a single file app-servlet.xml and it still does not intercept the methods on the controller.
      here is what I now have in the servlet.xml (after combining controller.xml)
      And I am still unable to intercept methods on the controller.
      =========Begin
      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

      <!--
      - DispatcherServlet application context for the Spring web MVC
      -->
      <beans>

      <!-- ========================= VIEW DEFINITIONS ========================= -->

      <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
      <property name="viewClass"><value>org.springframework.web.se rvlet.view.JstlView</value></property>
      <property name="prefix"><value>/WEB-INF/jsp/</value></property>
      <property name="suffix"><value>.jsp</value></property>
      </bean>

      <!-- ========================= DEFINITIONS OF PUBLIC CONTROLLERS ========================= -->
      <!--
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
      <property name="interceptors">
      <list>
      <ref bean="sessionInitializerInterceptor"/>
      </list>
      </property>
      <property name="mappings">
      <props>
      <prop key="/simpleController/*.do">simpleController</prop>
      </props>
      </property>
      </bean>
      -->
      <bean id="handlerMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
      <property name="interceptors">
      <list>
      <ref bean="sessionInitializerInterceptor"/>
      </list>
      </property>
      <property name="defaultHandler"><ref local="simpleController"/></property>
      </bean>

      <!-- <bean id="sessionInitializerInterceptor" class="com.eaf2.web.interceptor.SessionInitializer Interceptor"/> -->
      <bean id="serviceManagerLoader" class="com.eaf2.service.internal.ServiceManagerLoa der"/>


      <!-- begin app specific -->
      <bean id="sessionInitializerInterceptor" class="com.eaf2.web.interceptor.SessionInitializer Interceptor"/>

      <bean id="simpleControllerResolver" class="org.springframework.web.servlet.mvc.multiac tion.PropertiesMethodNameResolver">
      <property name="mappings">
      <props>
      <prop key="/simpleController/testRequest.do">testRequest</prop>
      </props>
      </property>
      </bean>

      <bean id="simpleController" class="com.sample.web.SimpleController">
      <property name="methodNameResolver"><ref local="simpleControllerResolver"/></property>
      <property name="sample"><value>EAF Sample</value></property>
      </bean>


      <bean id="securityLogicBean" class="org.springframework.aop.framework.ProxyFact oryBean">
      <!--
      <property name="proxyInterfaces">
      <value>com.sample.web.ISimpleController</value>
      </property>
      -->
      <property name="target">
      <ref local="simpleController"/>
      </property>
      <property name="interceptorNames">
      <list>
      <value>methodSecurityAdvisor</value>
      </list>
      </property>
      </bean>

      <bean id="methodSecurityAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
      <property name="advice">
      <ref local="methodSecurityAdvice"/>
      </property>
      <property name="pattern">
      <value>.*</value>
      </property>
      </bean>

      <bean id="methodSecurityAdvice" class="com.eaf2.security.MethodSecurityAdvice"/>
      </beans>
      =========End

      Comment


      • #4
        Just a quick thought, shouldn't the default handler be <property name="defaultHandler"><ref local="securityLogicBean"/></property> instead of <property name="defaultHandler"><ref local="simpleController"/></property> . Else, I think you're pointing to the non advised controller ...

        HTH

        Olivier

        Comment


        • #5
          Good catch.
          Thanks Olivier - it works.
          Thanks again Irbouho

          Originally posted by ojolly
          Just a quick thought, shouldn't the default handler be <property name="defaultHandler"><ref local="securityLogicBean"/></property> instead of <property name="defaultHandler"><ref local="simpleController"/></property> . Else, I think you're pointing to the non advised controller ...

          HTH

          Olivier

          Comment

          Working...
          X