Fields Summary |
---|
protected static org.apache.catalina.util.StringManager | sm |
private org.apache.catalina.Context | contextThe Context with which we are associated. |
private transient Filter | filterThe application Filter we are configured for. |
private org.apache.catalina.deploy.FilterDef | filterDefThe FilterDef that defines our associated Filter. |
protected static Properties | restrictedFiltersRestricted filters (which can only be loaded by a privileged webapp). |
Methods Summary |
---|
javax.servlet.Filter | getFilter()Return the application Filter we are configured for.
// Return the existing filter instance, if any
if (this.filter != null)
return (this.filter);
// Identify the class loader we will be using
String filterClass = filterDef.getFilterClass();
ClassLoader classLoader = null;
if (filterClass.startsWith("org.apache.catalina."))
classLoader = this.getClass().getClassLoader();
else
classLoader = context.getLoader().getClassLoader();
ClassLoader oldCtxClassLoader =
Thread.currentThread().getContextClassLoader();
// Instantiate a new instance of this filter and return it
Class clazz = classLoader.loadClass(filterClass);
if (!isFilterAllowed(clazz)) {
throw new SecurityException
(sm.getString("applicationFilterConfig.privilegedFilter",
filterClass));
}
this.filter = (Filter) clazz.newInstance();
if (!context.getIgnoreAnnotations()) {
if (context instanceof StandardContext) {
AnnotationProcessor processor = ((StandardContext)context).getAnnotationProcessor();
processor.processAnnotations(this.filter);
processor.postConstruct(this.filter);
}
}
if (context instanceof StandardContext &&
((StandardContext) context).getSwallowOutput()) {
try {
SystemLogHandler.startCapture();
filter.init(this);
} finally {
String log = SystemLogHandler.stopCapture();
if (log != null && log.length() > 0) {
getServletContext().log(log);
}
}
} else {
filter.init(this);
}
return (this.filter);
|
org.apache.catalina.deploy.FilterDef | getFilterDef()Return the filter definition we are configured for.
return (this.filterDef);
|
public java.lang.String | getFilterName()Return the name of the filter we are configuring.
// --------------------------------------------------- FilterConfig Methods
return (filterDef.getFilterName());
|
public java.lang.String | getInitParameter(java.lang.String name)Return a String containing the value of the named
initialization parameter, or null if the parameter
does not exist.
Map map = filterDef.getParameterMap();
if (map == null)
return (null);
else
return ((String) map.get(name));
|
public java.util.Enumeration | getInitParameterNames()Return an Enumeration of the names of the initialization
parameters for this Filter.
Map map = filterDef.getParameterMap();
if (map == null)
return (new Enumerator(new ArrayList()));
else
return (new Enumerator(map.keySet()));
|
public javax.servlet.ServletContext | getServletContext()Return the ServletContext of our associated web application.
return (this.context.getServletContext());
|
protected boolean | isFilterAllowed(java.lang.Class filterClass)Return true if loading this filter is allowed.
// Privileged webapps may load all servlets without restriction
if (context.getPrivileged()) {
return true;
}
Class clazz = filterClass;
while (clazz != null && !clazz.getName().equals("javax.servlet.Filter")) {
if ("restricted".equals(restrictedFilters.getProperty(clazz.getName()))) {
return (false);
}
clazz = clazz.getSuperclass();
}
return (true);
|
void | release()Release the Filter instance associated with this FilterConfig,
if there is one.
if (this.filter != null)
{
if (Globals.IS_SECURITY_ENABLED) {
try {
SecurityUtil.doAsPrivilege("destroy", filter);
} catch(java.lang.Exception ex){
context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
}
SecurityUtil.remove(filter);
} else {
filter.destroy();
}
if (!context.getIgnoreAnnotations()) {
try {
((StandardContext)context).getAnnotationProcessor().preDestroy(this.filter);
} catch (Exception e) {
context.getLogger().error("ApplicationFilterConfig.preDestroy", e);
}
}
}
this.filter = null;
|
void | setFilterDef(org.apache.catalina.deploy.FilterDef filterDef)Set the filter definition we are configured for. This has the side
effect of instantiating an instance of the corresponding filter class.
this.filterDef = filterDef;
if (filterDef == null) {
// Release any previously allocated filter instance
if (this.filter != null){
if( Globals.IS_SECURITY_ENABLED) {
try{
SecurityUtil.doAsPrivilege("destroy", filter);
} catch(java.lang.Exception ex){
context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
}
SecurityUtil.remove(filter);
} else {
filter.destroy();
}
if (!context.getIgnoreAnnotations()) {
try {
((StandardContext)context).getAnnotationProcessor().preDestroy(this.filter);
} catch (Exception e) {
context.getLogger().error("ApplicationFilterConfig.preDestroy", e);
}
}
}
this.filter = null;
} else {
// Allocate a new filter instance
Filter filter = getFilter();
}
|
public java.lang.String | toString()Return a String representation of this object.
StringBuffer sb = new StringBuffer("ApplicationFilterConfig[");
sb.append("name=");
sb.append(filterDef.getFilterName());
sb.append(", filterClass=");
sb.append(filterDef.getFilterClass());
sb.append("]");
return (sb.toString());
|