Hello,

I am new to tomcat and I need to filter the URLs to accept all clients for
part of a URL and reject for all clients another part of this URL.

In details, I want:

/abc/def/xyz/*   :     accepts all
/abc/def/*        :      reject if URL does  not match /abc/def/xyz*


I found that the order in which the filters are done is explained in this
link (
https://stackoverflow.com/questions/17086712/servlet-filters-order-of-execution
).

Based on this, I did the following 2 filters:

1) Accept All :     this one is the most precise url-pattern and is listed
1st. When matching, I hope to accept all IP addresses

2) Block All  :      this one is more general and should match the rest of
the URL when the 1st fitler does not match. I hope to reject all the IP in
this case

Here are the filters, in the order that I add them in web.xml :

<filter>
  <filter-name>Accept All</filter-name>
  <filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
  <init-param>
    <param-name>allow</param-name>
    <param-value>\d+\.\d+\.\d+\.\d+</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>Accept All</filter-name>
  <url-pattern>/abc/def/xyz/*</url-pattern>
</filter-mapping>

<filter>
  <filter-name>Block All</filter-name>
  <filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
  <init-param>
    <param-name>deny</param-name>
    <param-value>\d+\.\d+\.\d+\.\d+</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>Block All</filter-name>
  <url-pattern>/abc/def/*</url-pattern>
</filter-mapping>


The result is that all URLs  (  i.e.  /abc/def/* ) are jected and
/abc/def/xyz/*  is never accepted.

Is there a way to do what I am trying to do ?

Thank you

Gilbert

Reply via email to