jp.terasoluna.fw.web.thin
Class AbstractControlFilter<E>

java.lang.Object
  extended by jp.terasoluna.fw.web.thin.AbstractControlFilter<E>
Type Parameters:
E - Specifies controller class.
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
AuthenticationControlFilter, AuthorizationControlFilter, BlockageControlFilter, ServerBlockageControlFilter

public abstract class AbstractControlFilter<E>
extends java.lang.Object
implements javax.servlet.Filter

Abstract class that performs access control by using the controller which is implemented as bean.

This class is the upper class of the class that performs access control by using the bean which is fetched from DI container.

How to use

To use the implementation class of this class, perform the following settings in deployment descriptor(web.xml) and Bean definition file. The id attribute which is defined in Bean definition file should be set as sampleXxxController. In the "class" attribute of <bean> element, set the class that implements the interface which represents each of the filters (here it is referred as SampleXxxController).
*Xxx differs depending on the Filter that provides each function.

Deployment descriptor(web.xml)

 <filter>
   <filter-name>
     xxxControlFilter
   </filter-name>
   <filter-class>
     jp.terasoluna.sample.XxxControlFilter
   </filter-class>
   <init-param>
     <param-name>controller</param-name>
     <param-value>
       "sampleXxxController"
     </param-value>
   </init-param>
 </filter>

 <filter-mapping>
   <filter-name>xxxControlFilter</filter-name>
   <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <error-page>
   <exception-type>
     jp.terasoluna.sample.XxxException
   </exception-type>
   <location>/XxxError.jsp</location>
 </error-page>
 
Bean definition file

 <bean id="sampleXxxController"
       class="jp.terasoluna...SampleXxxController" />
 

Filter provides the default value in the "id" attribute of <bean> element defined in Bean definition file. In this case, <init-param> elements can be omitted from the <filter> element in deployment descriptor(web.xml).


Field Summary
protected  javax.servlet.FilterConfig config
          Filter configuration information.
private static org.apache.commons.logging.Log log
          Log class.
 
Constructor Summary
AbstractControlFilter()
           
 
Method Summary
 void destroy()
          It is called when filter process is performed.
Processing is not performed in this class.
abstract  void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
          Performs access control.
protected  E getController()
          Fetches controller instance from DI container.
protected abstract  java.lang.Class getControllerClass()
          Returns the interface that should be implemented by the class which performs access control.
abstract  java.lang.String getDefaultControllerBeanId()
          Returns default id at the time of fetching controller from DI container.
protected abstract  java.lang.String getErrorCode()
          Returns error code which indicates the failure in generating the controller.
 void init(javax.servlet.FilterConfig config)
          When the filter changes to "Service start state", it is called by the container. After creating an instance of the filter, container calls init method only once.
In order to request the filter to execute the filter process, init method should finish normally. Container cannot change the Filter to service state when the init method is any of the following.
ServletException is thrown. It is not restored within the time defined by container. Either the implementation class of the controller does not exist or the settings are abnormal.
protected  void setConfig(javax.servlet.FilterConfig config)
          Sets filter configuration information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log class.


config

protected javax.servlet.FilterConfig config
Filter configuration information.

Constructor Detail

AbstractControlFilter

public AbstractControlFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
When the filter is changed to "Service start state", it is called by the container. After creating an instance of the filter, container calls init method only once.
In order to request the filter to execute the filter process, init method should finish normally. Container cannot change the Filter to service state when the init method is any of the following.

Specified by:
init in interface javax.servlet.Filter
Parameters:
config - FilterConfig instance.
Throws:
javax.servlet.ServletException - Exception which is thrown at the time of abnormal initialization.
See Also:
Filter.init(javax.servlet.FilterConfig)

setConfig

protected void setConfig(javax.servlet.FilterConfig config)
Sets filter configuration information.

Parameters:
config - Filter configuration information

getController

protected E getController()
Fetches controller instance from DI container.

Returns:
E Contoller instance which is fetched

getControllerClass

protected abstract java.lang.Class getControllerClass()
Returns the interface that should be implemented by the access controller class.

Returns:
Class of controller which is used in this filter.

getErrorCode

protected abstract java.lang.String getErrorCode()
Returns error code that indicates the failure in generating the controller.

Returns:
Error code

getDefaultControllerBeanId

public abstract java.lang.String getDefaultControllerBeanId()
Returns default id at the time of fetching the controller from DI container.

Returns:
Default id attribute value

doFilter

public abstract void doFilter(javax.servlet.ServletRequest req,
                              javax.servlet.ServletResponse res,
                              javax.servlet.FilterChain chain)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Performs access control.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
req - HTTP request
res - HTTP response
chain - Filter chain
Throws:
java.io.IOException - I/O error
javax.servlet.ServletException - Servlet exception
See Also:
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)

destroy

public void destroy()
It is called at the time of filter processing.
Processing is not performed in this class.

Specified by:
destroy in interface javax.servlet.Filter
See Also:
Filter.destroy()