You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Erik Price <ep...@ptc.com> on 2003/01/22 20:38:05 UTC

using multiple filters

I would like to use a filter on every servlet and JSP in my webapp to 
verify that the user is logged in (by checking the user's session for a 
value), except for "index.jsp" and "error.jsp" (error.jsp is for things 
like invalid messages, etc).

I would also like to use a filter on certain servlets to perform Form 
Validation using org.apache.commons.validator.

Is testing the URL the most elegant way to achieve the former 
(determining when the SecurityFilter should be in effect and when it 
shouldn't)?  And to use the latter (a form validation filter) do I need 
to register it in the same FilterChain as the the SecurityFilter?  Or 
can there be two separate, disparate filters for a given resource?


Thanks for any insight, it's kind of a confusing topic to me.



Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using multiple filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 22 Jan 2003, Erik Price wrote:

> Date: Wed, 22 Jan 2003 15:37:21 -0500
> From: Erik Price <ep...@ptc.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: using multiple filters
>
>
>
> Craig R. McClanahan wrote:
>
> >>Is testing the URL the most elegant way to achieve the former
> >>(determining when the SecurityFilter should be in effect and when it
> >>shouldn't)?  And to use the latter (a form validation filter) do I need
> >>to register it in the same FilterChain as the the SecurityFilter?  Or
> >>can there be two separate, disparate filters for a given resource?
> >>
> >
> >
> > You can have any number of filters mapped to the same resources -- the
> > container assembles the filter chain for you, so you don't need to worry
> > about that.
>
> I thought that the FilterChain is the last argument to my doFilter
> method call in my filter?

Yes, but it is the container's job to configure which filters are
included.

>  So then how do I specify which filter gets
> executed first?
>
>

The precise rules are listed in Section 6.2.4 of the Servlet Spec.
Basically, the container will:

* Find all the matching URL-mapped <filter-mapping> entries, and
  add the corresponding filter, in the order that these <filter-mapping>
  elements are in the web.xml file.

* Find all the filter-name-matched <filter-mapping> entries, and
  add the corresponding filter, in the order that these <filter-mapping>
  elements are in the web.xml file.

* The last filter in the constructed chain is rigged up so that
  calling chain.doFilter() from there will actually invoke the
  servlet.

So, you control the order filters are invoked in by managing the order of
your <filter-mapping> elements.

>
> Erik
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using multiple filters

Posted by Erik Price <ep...@ptc.com>.

Craig R. McClanahan wrote:

>>Is testing the URL the most elegant way to achieve the former
>>(determining when the SecurityFilter should be in effect and when it
>>shouldn't)?  And to use the latter (a form validation filter) do I need
>>to register it in the same FilterChain as the the SecurityFilter?  Or
>>can there be two separate, disparate filters for a given resource?
>>
> 
> 
> You can have any number of filters mapped to the same resources -- the
> container assembles the filter chain for you, so you don't need to worry
> about that.

I thought that the FilterChain is the last argument to my doFilter 
method call in my filter?  So then how do I specify which filter gets 
executed first?



Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using multiple filters

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 22 Jan 2003, Erik Price wrote:

> Date: Wed, 22 Jan 2003 14:38:05 -0500
> From: Erik Price <ep...@ptc.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: using multiple filters
>
> I would like to use a filter on every servlet and JSP in my webapp to
> verify that the user is logged in (by checking the user's session for a
> value), except for "index.jsp" and "error.jsp" (error.jsp is for things
> like invalid messages, etc).
>
> I would also like to use a filter on certain servlets to perform Form
> Validation using org.apache.commons.validator.
>
> Is testing the URL the most elegant way to achieve the former
> (determining when the SecurityFilter should be in effect and when it
> shouldn't)?  And to use the latter (a form validation filter) do I need
> to register it in the same FilterChain as the the SecurityFilter?  Or
> can there be two separate, disparate filters for a given resource?
>

You can have any number of filters mapped to the same resources -- the
container assembles the filter chain for you, so you don't need to worry
about that.

> Erik

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>