Results 1 to 3 of 3

Thread: How to invoke servlet filters

  1. #1
    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,

  2. #2
    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.

  3. #3
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,927,006.26651 seconds with 16 queries