001 package com.sptci.auth;
002
003 import java.io.IOException;
004
005 import java.util.logging.Logger;
006
007 import javax.servlet.FilterChain;
008 import javax.servlet.FilterConfig;
009 import javax.servlet.ServletException;
010 import javax.servlet.ServletRequest;
011 import javax.servlet.ServletResponse;
012
013 /**
014 * A raw servlet filter adapter implementation.
015 *
016 * @author Rakesh Vidyadharan 2006-11-14
017 * @version $Id: Filter.java 3251 2007-05-12 19:09:12Z rakesh $
018 */
019 public abstract class Filter implements javax.servlet.Filter
020 {
021 /**
022 * The logger that is used to log errors or other messages.
023 */
024 protected static final Logger logger =
025 Logger.getLogger( Filter.class.getName() );
026
027 /**
028 * The HTTP request attribute that will be set with the {@link
029 * User} object.
030 */
031 public static final String USER = "applicationUser";
032
033 /**
034 * A reference to the Servlet container's Filter configuration.
035 */
036 protected FilterConfig filterConfig = null;
037
038 /**
039 * Called by the web container to indicate to a filter that it is
040 * being placed into service. The servlet container calls the init
041 * method exactly once after instantiating the filter. The init
042 * method must complete successfully before the filter is asked to
043 * do any filtering work.
044 *
045 * @param filterConfig - A reference to the configuration object
046 * used by the servlet container to pass information to the filter.
047 * @throws ServletException - If an exception is encountered while
048 * fetching the initialisation parameters from the specified
049 * <code>filterConfig</code> object reference.
050 */
051 public void init( FilterConfig filterConfig ) throws ServletException
052 {
053 setFilterConfig( filterConfig );
054 }
055
056 /**
057 * Called by the web container to indicate to a filter that it is
058 * being taken out of service. This method is only called once all
059 * threads within the filter's doFilter method have exited or after
060 * a timeout period has passed. After the web container calls this
061 * method, it will not call the doFilter method again on this
062 * instance of the filter. Just sets the {@link #filterConfig}
063 * reference to <code>null</code>.
064 */
065 public void destroy()
066 {
067 setFilterConfig( null );
068 }
069
070 /**
071 * Filter action. Passes through to next filter or destination.
072 */
073 public void doFilter( ServletRequest request,
074 ServletResponse response, FilterChain chain )
075 throws IOException, ServletException
076 {
077 chain.doFilter( request, response );
078 }
079
080 /**
081 * Set {@link #filterConfig}.
082 *
083 * @param filterConfig The value to set.
084 */
085 protected void setFilterConfig( FilterConfig filterConfig )
086 {
087 this.filterConfig = filterConfig;
088 }
089 }