org.apache.shiro.web.servlet
Class OncePerRequestFilter
java.lang.Object
org.apache.shiro.web.servlet.ServletContextSupport
org.apache.shiro.web.servlet.AbstractFilter
org.apache.shiro.web.servlet.NameableFilter
org.apache.shiro.web.servlet.OncePerRequestFilter
- All Implemented Interfaces:
- Filter, Nameable
- Direct Known Subclasses:
- AbstractShiroFilter, AdviceFilter
public abstract class OncePerRequestFilter
- extends NameableFilter
Filter base class that guarantees to be just executed once per request,
on any servlet container. It provides a doFilterInternal(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
method with HttpServletRequest and HttpServletResponse arguments.
The getAlreadyFilteredAttributeName() method determines how
to identify that a request is already filtered. The default implementation
is based on the configured name of the concrete filter instance.
NOTE This class was borrowed from the Spring framework, and as such,
all copyright notices and author names have remained in tact.
- Since:
- 0.1
ALREADY_FILTERED_SUFFIX
public static final String ALREADY_FILTERED_SUFFIX
- Suffix that gets appended to the filter name for the "already filtered" request attribute.
- See Also:
getAlreadyFilteredAttributeName(),
Constant Field Values
OncePerRequestFilter
public OncePerRequestFilter()
doFilter
public final void doFilter(ServletRequest request,
ServletResponse response,
FilterChain filterChain)
throws ServletException,
IOException
- This
doFilter implementation stores a request attribute for
"already filtered", proceeding without filtering again if the
attribute is already there.
- Throws:
ServletException
IOException- See Also:
getAlreadyFilteredAttributeName(),
shouldNotFilter(javax.servlet.ServletRequest),
doFilterInternal(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
getAlreadyFilteredAttributeName
protected String getAlreadyFilteredAttributeName()
- Return name of the request attribute that identifies that a request has already been filtered.
The default implementation takes the configured
name and appends ".FILTERED".
If the filter is not fully initialized, it falls back to the implementation's class name.
- Returns:
- the name of the request attribute that identifies that a request has already been filtered.
- See Also:
NameableFilter.getName(),
ALREADY_FILTERED_SUFFIX
shouldNotFilter
protected boolean shouldNotFilter(ServletRequest request)
throws ServletException
- Can be overridden in subclasses for custom filtering control,
returning
true to avoid filtering of the given request.
The default implementation always returns false.
- Parameters:
request - current HTTP request
- Returns:
- whether the given request should not be filtered
- Throws:
ServletException - in case of errors
doFilterInternal
protected abstract void doFilterInternal(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException,
IOException
- Same contract as for
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain),
but guaranteed to be invoked only once per request.
- Parameters:
request - incoming ServletRequestresponse - outgoing ServletResponsechain - the FilterChain to execute
- Throws:
ServletException - if there is a problem processing the request
IOException - if there is an I/O problem processing the request
Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.