ApplicationFilterChainpublic final class ApplicationFilterChain extends Object implements FilterChainImplementation of javax.servlet.FilterChain used to manage
the execution of a set of filters for a particular request. When the
set of defined filters has all been executed, the next call to
doFilter() will execute the servlet's service()
method itself. |
Fields Summary |
---|
public static final int | INCREMENT | private ApplicationFilterConfig[] | filtersFilters. | private int | posThe int which is used to maintain the current position
in the filter chain. | private int | nThe int which gives the current number of filters in the chain. | private Servlet | servletThe servlet instance to be executed by this chain. | private static final org.apache.catalina.util.StringManager | smThe string manager for our package. | private org.apache.catalina.util.InstanceSupport | supportThe InstanceSupport instance associated with our Wrapper (used to
send "before filter" and "after filter" events. | private static Class[] | classTypeStatic class array used when the SecurityManager is turned on and
doFilter | private static Class[] | classTypeUsedInServiceStatic class array used when the SecurityManager is turned on and
service |
Constructors Summary |
---|
public ApplicationFilterChain()Construct a new chain instance with no defined filters.
// ----------------------------------------------------------- Constructors
super();
|
Methods Summary |
---|
void | addFilter(ApplicationFilterConfig filterConfig)Add a filter to the set of filters that will be executed in this chain.
if (n == filters.length) {
ApplicationFilterConfig[] newFilters =
new ApplicationFilterConfig[n + INCREMENT];
System.arraycopy(filters, 0, newFilters, 0, n);
filters = newFilters;
}
filters[n++] = filterConfig;
| public void | doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)Invoke the next filter in this chain, passing the specified request
and response. If there are no more filters in this chain, invoke
the service() method of the servlet itself.
// ---------------------------------------------------- FilterChain Methods
if (Globals.IS_SECURITY_ENABLED) {
final ServletRequest req = request;
final ServletResponse res = response;
try {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public Object run()
throws ServletException, IOException {
internalDoFilter(req,res);
return null;
}
}
);
} catch( PrivilegedActionException pe) {
Exception e = pe.getException();
if (e instanceof ServletException)
throw (ServletException) e;
else if (e instanceof IOException)
throw (IOException) e;
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new ServletException(e.getMessage(), e);
}
} else {
internalDoFilter(request,response);
}
| private void | internalDoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
// Call the next filter if there is one
if (pos < n) {
ApplicationFilterConfig filterConfig = filters[pos++];
Filter filter = null;
try {
filter = filterConfig.getFilter();
support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
filter, request, response);
if( SecurityUtil.isPackageProtectionEnabled() ) {
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] filterType = new Object[3];
filterType[0] = req;
filterType[1] = res;
filterType[2] = this;
SecurityUtil.doAsPrivilege
("doFilter", filter, classType, filterType);
filterType = null;
} else {
filter.doFilter(request, response, this);
}
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response);
} catch (IOException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (ServletException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (RuntimeException e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw e;
} catch (Throwable e) {
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, request, response, e);
throw new ServletException
(sm.getString("filterChain.filter"), e);
}
return;
}
// We fell off the end of the chain -- call the servlet instance
/* IASRI 4665318
try {
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
servlet, request, response);
if ((request instanceof HttpServletRequest) &&
(response instanceof HttpServletResponse)) {
// START SJS WS 7.0 6236329
//if( System.getSecurityManager() != null) {
if ( SecurityUtil.executeUnderSubjectDoAs() ){
// END OF SJS WS 7.0 6236329
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] serviceType = new Object[2];
serviceType[0] = req;
serviceType[1] = res;
SecurityUtil.doAsPrivilege("service",
servlet,
classTypeUsedInService,
serviceType,
principal);
serviceType = null;
} else {
servlet.service((HttpServletRequest) request,
(HttpServletResponse) response);
}
} else {
servlet.service(request, response);
}
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response);
} catch (IOException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (ServletException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (RuntimeException e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw e;
} catch (Throwable e) {
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
throw new ServletException
(sm.getString("filterChain.servlet"), e);
}
*/
// START IASRI 4665318
servletService(request, response, servlet, support);
// END IASRI 4665318
| void | release()Release references to the filters and wrapper executed by this chain.
n = 0;
pos = 0;
servlet = null;
support = null;
| static void | servletService(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.Servlet serv, org.apache.catalina.util.InstanceSupport supp)
try {
supp.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
serv, request, response);
if ((request instanceof HttpServletRequest) &&
(response instanceof HttpServletResponse)) {
if ( SecurityUtil.executeUnderSubjectDoAs() ){
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] serviceType = new Object[2];
serviceType[0] = req;
serviceType[1] = res;
SecurityUtil.doAsPrivilege("service",
serv,
classTypeUsedInService,
serviceType,
principal);
serviceType = null;
} else {
serv.service((HttpServletRequest) request,
(HttpServletResponse) response);
}
} else {
serv.service(request, response);
}
supp.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
serv, request, response);
} catch (IOException e) {
supp.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
serv, request, response, e);
throw e;
} catch (ServletException e) {
supp.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
serv, request, response, e);
throw e;
} catch (RuntimeException e) {
supp.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
serv, request, response, e);
throw e;
} catch (Throwable e) {
supp.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
serv, request, response, e);
throw new ServletException
(sm.getString("filterChain.servlet"), e);
}
| void | setServlet(javax.servlet.Servlet servlet)Set the servlet that will be executed at the end of this chain.
this.servlet = servlet;
| void | setSupport(org.apache.catalina.util.InstanceSupport support)Set the InstanceSupport object used for event notifications
for this filter chain.
this.support = support;
|
|