title: Block access by IP Address Range on Tomcat 7 when accessing URL
body: <p>How do you configure the web.xml file on tomcat/application such that the following can be achieved:</p>
  
  <p><strong>Allowed:</strong></p>
  
  <ul>
  <li>localhost/app/foo/bar/*</li>
  </ul>
  
  <p><strong>Disallowed:</strong></p>
  
  <ul>
  <li>localhost/app/foo</li>
  </ul>
  
  <p>Is there a way to do it without changing the source code? Changing the web.xml file is ok.</p>
  
  <p>I've read <a href="http://www.jvmhost.com/articles/block-ip-address-apache-tomcat-filter" rel="nofollow noreferrer">http://www.jvmhost.com/articles/block-ip-address-apache-tomcat-filter</a> but this alone doesn't solve the problem.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;Remote IP Filter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.catalina.filters.RemoteAddrFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;deny&lt;/param-name&gt;
          &lt;param-value&gt;^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$&lt;/param-value&gt;
      &lt;/init-param&gt;
  
      &lt;init-param&gt;
          &lt;param-name&gt;denyStatus&lt;/param-name&gt;
          &lt;param-value&gt;403&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;filter&gt;
      &lt;filter-name&gt;Allow quickview&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.catalina.filters.RemoteAddrFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;allow&lt;/param-name&gt;
          &lt;param-value&gt;^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$&lt;/param-value&gt;
      &lt;/init-param&gt;
  
      &lt;init-param&gt;
          &lt;param-name&gt;denyStatus&lt;/param-name&gt;
          &lt;param-value&gt;403&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;Allow quickview&lt;/filter-name&gt;
      &lt;url-pattern&gt;/foo/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;Remote IP Filter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>Thanks!</p>