Package org.apache.shiro.web.servlet
Class AbstractFilter
- java.lang.Object
-
- org.apache.shiro.web.servlet.ServletContextSupport
-
- org.apache.shiro.web.servlet.AbstractFilter
-
- All Implemented Interfaces:
Filter
- Direct Known Subclasses:
NameableFilter
public abstract class AbstractFilter extends ServletContextSupport implements Filter
Base abstract Filter simplifying Filter initialization andaccess
to init parameters. Subclass initialization logic should be performed by overriding theonFilterConfigSet()
template method. FilterChain execution logic (theFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
method is left to subclasses.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected FilterConfig
filterConfig
FilterConfig provided by the Servlet container at start-up.
-
Constructor Summary
Constructors Constructor Description AbstractFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Default no-op implementation that can be overridden by subclasses for custom cleanup behavior.FilterConfig
getFilterConfig()
Returns the servlet container specifiedFilterConfig
instance provided atstartup
.protected String
getInitParam(String paramName)
Returns the value for the namedinit-param
, ornull
if there was noinit-param
specified by that name.void
init(FilterConfig filterConfig)
Sets the filter'sfilterConfig
and then immediately callsonFilterConfigSet()
to trigger any processing a subclass might wish to perform.protected void
onFilterConfigSet()
Template method to be overridden by subclasses to perform initialization logic at start-up.void
setFilterConfig(FilterConfig filterConfig)
Sets the FilterConfig and theServletContext
as attributes of this class for use by subclasses.-
Methods inherited from class org.apache.shiro.web.servlet.ServletContextSupport
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString, toStringBuilder
-
-
-
-
Field Detail
-
filterConfig
protected FilterConfig filterConfig
FilterConfig provided by the Servlet container at start-up.
-
-
Constructor Detail
-
AbstractFilter
public AbstractFilter()
-
-
Method Detail
-
getFilterConfig
public FilterConfig getFilterConfig()
Returns the servlet container specifiedFilterConfig
instance provided atstartup
.- Returns:
- the servlet container specified
FilterConfig
instance provided at start-up.
-
setFilterConfig
public void setFilterConfig(FilterConfig filterConfig)
Sets the FilterConfig and theServletContext
as attributes of this class for use by subclasses. That is:this.filterConfig = filterConfig; setServletContext(filterConfig.getServletContext());
- Parameters:
filterConfig
- the FilterConfig instance provided by the Servlet container at start-up.
-
getInitParam
protected String getInitParam(String paramName)
Returns the value for the namedinit-param
, ornull
if there was noinit-param
specified by that name.- Parameters:
paramName
- the name of theinit-param
- Returns:
- the value for the named
init-param
, ornull
if there was noinit-param
specified by that name.
-
init
public final void init(FilterConfig filterConfig) throws ServletException
Sets the filter'sfilterConfig
and then immediately callsonFilterConfigSet()
to trigger any processing a subclass might wish to perform.- Specified by:
init
in interfaceFilter
- Parameters:
filterConfig
- the servlet container supplied FilterConfig instance.- Throws:
ServletException
- ifonFilterConfigSet()
throws an Exception.
-
onFilterConfigSet
protected void onFilterConfigSet() throws Exception
Template method to be overridden by subclasses to perform initialization logic at start-up. TheServletContext
andFilterConfig
will be accessible (and non-null
) at the time this method is invoked via thegetServletContext()
andgetFilterConfig()
methods respectively.init-param
values may be conveniently obtained via thegetInitParam(String)
method.- Throws:
Exception
- if the subclass has an error upon initialization.
-
-