Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally enable/disable filter in web.xml

I'm using Spring MVC. I have a web.xml and a myapp.xml. In the myapp.xml I'm taking advantage of the spring beans profile. So, I've got two profiles dev and test. Each has different beans that get initiated based on the environment variable.

I'm wondering if something similar can be done in web.xml? In web.xml I've got the following which I only want to enable when the environment variable is test

<filter>
    <filter-name>springSecurity</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurity</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

How can I do this?

like image 634
birdy Avatar asked Sep 16 '13 15:09

birdy


People also ask

What is the use of filter in Web XML?

The filter element of a web. xml file defines a filter instance. The filter element always contains a filter-name element and a filter-class element, and may contain initialization parameters. The filter-name element declares a name for this particular filter instance.


1 Answers

In your case you already use DelegatingFilterProxy that delegates actual processing to a Spring bean named springSecurity.

So, you need to replace your Spring Security configuration with a no-op implementation of Filter declared as springSecurity in your dev profile.

like image 67
axtavt Avatar answered Sep 24 '22 20:09

axtavt