PDA

View Full Version : selective request interceptor by URL


assaf
Sep 30th, 2004, 10:22 AM
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 (http://www.springframework.org/docs/reference/mvc.html#mvc-handlermapping-interceptor) applies the interceptor to all requests independent of the URL.

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

davison
Sep 30th, 2004, 11:30 AM
You could use a different handler mapping strategy...

<beans>
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<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.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/login.action">myController</prop>
</props>
</property>
</bean>

<bean id="myInterceptor" class="com.foo.bar.Interceptor"/>
<beans>

Regards,

assaf
Sep 30th, 2004, 11:46 AM
I should have guessed as much! Thanks!

- Assaf