Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-03-2009
Member
 
Join Date: Feb 2009
Posts: 69
How to invoke servlet filters

I am learning to integrate SSO feature in my web application. I am using Tomcat 6.0.18.

I have a map "CAS Filter" using "servlet-name" element "HelloWorldExample" in "filter-mapping" element redirection as mentioned above is working.
In case of using "/*" as the "url-pattern" element the redirection is working.

But in case of "url-pattern" element as "/servlet/*" the page gets redirected to actual JSP page which renders "Hello World".

The "/servlet/*" <url-pattern> should work because it should match the request path for Hello World Example.

Can anybody please help me in understanding the cause behind the problem?

Thanks,
Reply With Quote
  #2  
Old 30-03-2009
Member
 
Join Date: Jan 2009
Posts: 125
Re: How to invoke servlet filters

  1. A servlet filter implements the javax.servlet.Filter class. Implement three methods in the filter class:
    • init(javax.servlet.FilterConfig cfg). This method is called by the container once, when the servlet filter is placed into service. The FilterConfig passed to this method contains the init-parameters of the servlet filter. Specify the init-parameters for a servlet filter during configuration using the assembly tool.
    • destroy. This method is called by the container when the servlet filter is taken out of a service.
    • doFilter(ServletRequest req, ServletResponse res, FilterChain chain). This method is called by the container for every servlet request that maps to this filter before invoking the servlet. The FilterChain chain that is passed to this method can be used to invoke the next filter in the chain of filters. The original requested servlet runs when the last filter in the chain calls the chain.doFilter method. Therefore, all filters call the chain.doFilter method for the original servlet to run after filtering. If an additional authentication check is implemented in the filter code and results in failure, the original servlet does not run. The chain.doFilter method is not called and can be redirected to some other error page.
  2. If a servlet maps to many servlet filters, servlet filters are called in the order that is listed in the web.xml deployment descriptor of the application. Place the servlet filter class file in the WEB-INF/classes directory of the application.
Reply With Quote
  #3  
Old 30-03-2009
Member
 
Join Date: Jan 2009
Posts: 96
Re: How to invoke servlet filters

The Servlet Authentication Filter interface allows an Authentication provider to implement zero or more Servlet Authentication Filter classes. The filters are invoked as follows:
  1. The servlet container calls the Servlet Authentication Filters prior to authentication occurring.

    The servlet container gets the configured chain of Servlet Authentication Filters from the WebLogic Security Framework.

    The Security Framework returns the Servlet Authentication Filters in the order of the authentication providers. If one provider has multiple Servlet Authentication Filters, the Security Framework uses the ordered list of javax.servlet.Filters returned by the ServletAuthenticationFilter getAuthenticationFilters method.

    Duplicate filters are allowed because they might need to execute multiple times to correctly manipulate the request.

  2. For each filter, the servlet container calls the Filter init method to indicate to a filter that it is being placed into service.

  3. The servlet container calls the Filter doFilter method on the first filter each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

    The FilterChain object passed in to this method allows the Filter to pass on the request and response to the next entity in the chain. Filters use the FilterChain object to invoke the next filter in the chain, or if the calling filter is the last filter in the chain, to invoke the resource at the end of the chain.

  4. If all Servlet Authentication Filters call the Filter doFilter method then, when the final one calls the doFilter method, the servlet container then performs authentication as it would if the filters were not present.

    However, if any of the Servlet Authentication Filters do not call the doFilter method, the remaining filters, the servlet, and the servlet container’s authentication procedure are not called. This allows a filter to replace the servlet’s authentication process. This typically involves authentication failure or redirecting to another URL for authentication.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to invoke servlet filters"
Thread Thread Starter Forum Replies Last Post
SetPassword and ChangePassword Invoke manishdk Active Directory 2 12-04-2011 10:22 PM
How to invoke methods of C # in Silverlight using javascript Tynan Software Development 4 27-02-2011 08:58 AM
How do you invoke a procedure from a remote machine ? Fragman Software Development 4 30-01-2011 03:29 AM
How to invoke JavaScript Code from an Applet? Soumen Software Development 5 18-02-2010 01:02 AM
Invoke servlet from EJB components? Nurhan Software Development 3 01-04-2009 09:59 AM


All times are GMT +5.5. The time now is 02:04 AM.