Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.acegisecurity.util
Class FilterToBeanProxy  view FilterToBeanProxy download FilterToBeanProxy.java

java.lang.Object
  extended byorg.acegisecurity.util.FilterToBeanProxy
All Implemented Interfaces:
javax.servlet.Filter

public class FilterToBeanProxy
extends java.lang.Object
implements javax.servlet.Filter

Delegates Filter requests to a Spring-managed bean.

This class acts as a proxy on behalf of a target Filter that is defined in the Spring bean context. It is necessary to specify which target Filter should be proxied as a filter initialization parameter.

On filter initialisation, the class will use Spring's WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)>WebApplicationContextUtils.getWebApplicationContext(ServletContext sc) 55 method to obtain an ApplicationContext instance. It will expect to find the target Filter in this ApplicationContext.

To use this filter, it is necessary to specify one of the following filter initialization parameters:

If both initialization parameters are specified, targetBean takes priority.

An additional initialization parameter, init, is also supported. If set to "lazy" the initialization will take place on the first HTTP request, rather than at filter creation time. This makes it possible to use FilterToBeanProxy with the Spring ContextLoaderServlet. Where possible you should not use this initialization parameter, instead using ContextLoaderListener.

A final optional initialization parameter, lifecycle, determines whether the servlet container or the IoC container manages the lifecycle of the proxied filter. When possible you should write your filters to be managed via the IoC container interfaces such as org.springframework.beans.factory.InitializingBean and org.springframework.beans.factory.DisposableBean. If you cannot control the filters you wish to proxy (eg you do not have their source code) you might need to allow the servlet container to manage lifecycle via the Filter.init(javax.servlet.FilterConfig)>Filter.init(javax.servlet.FilterConfig) 55 and Filter.destroy()>Filter.destroy() 55 methods. If this case, set the lifecycle initialization parameter to servlet-container-managed. If the parameter is any other value, servlet container lifecycle methods will not be delegated through to the proxy.

Version:
$Id: FilterToBeanProxy.java,v 1.9 2005/11/17 00:56:09 benalex Exp $

Field Summary
private  javax.servlet.Filter delegate
           
private  javax.servlet.FilterConfig filterConfig
           
private  boolean initialized
           
private  boolean servletContainerManaged
           
 
Constructor Summary
FilterToBeanProxy()
           
 
Method Summary
 void destroy()
          Called by the web container to indicate to a filter that it is being taken out of service.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          The doFilter method of the Filter is called by the container 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.
private  void doInit()
           
protected  org.springframework.context.ApplicationContext getContext(javax.servlet.FilterConfig filterConfig)
          Allows test cases to override where application context obtained from.
 void init(javax.servlet.FilterConfig filterConfig)
          Called by the web container to indicate to a filter that it is being placed into service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

private javax.servlet.Filter delegate

filterConfig

private javax.servlet.FilterConfig filterConfig

initialized

private boolean initialized

servletContainerManaged

private boolean servletContainerManaged
Constructor Detail

FilterToBeanProxy

public FilterToBeanProxy()
Method Detail

destroy

public void destroy()
Description copied from interface: javax.servlet.Filter
Called by the web container to indicate to a filter that it is being taken out of service. This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the filter's current state in memory.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Description copied from interface: javax.servlet.Filter
The doFilter method of the Filter is called by the container 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 passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:-
1. Examine the request
2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
4. a) Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
4. b) or not pass on the request/response pair to the next entity in the filter chain to block the request processing
5. Directly set headers on the response after invocation of the next entity in the filter chain.

Specified by:
doFilter in interface javax.servlet.Filter

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Description copied from interface: javax.servlet.Filter
Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

The web container cannot place the filter into service if the init method either
1.Throws a ServletException
2.Does not return within a time period defined by the web container

Specified by:
init in interface javax.servlet.Filter

getContext

protected org.springframework.context.ApplicationContext getContext(javax.servlet.FilterConfig filterConfig)
Allows test cases to override where application context obtained from.


doInit

private void doInit()
             throws javax.servlet.ServletException