Announcement Announcement Module
Collapse
No announcement yet.
selective request interceptor by URL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • selective request interceptor by URL

    I'd like to write an interceptor that checks if the user is logged in, but only apply it (declaratively if possible) to certain URLs.

    e.g. if the user enters /login.action the interceptor is not applied, but if he enters /search.action it is.

    The method described in the documentation applies the interceptor to all requests independent of the URL.

    What's the best way of going about this?
    Best regards,
    Assaf

  • #2
    You could use a different handler mapping strategy...

    Code:
    <beans>
        <bean id="handlerMapping" 
              class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">            
            <property name="interceptors">
                <list>
                    <ref bean="myInterceptor"/>
                </list>
            </property>
            <property name="mappings">
                <props>
                    <prop key="/search.action">myController</prop>
                </props>
            </property>
        </bean>
    
        <bean id="handlerMapping2" 
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">            
            <property name="mappings">
                <props>
                    <prop key="/login.action">myController</prop>
                </props>
            </property>
        </bean>
        
        <bean id="myInterceptor" class="com.foo.bar.Interceptor"/>    
    <beans>
    Regards,

    Comment


    • #3
      I should have guessed as much! Thanks!

      - Assaf

      Comment

      Working...
      X