import org.apache.catalina.Wrapper;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.deploy.ApplicationParameter;
+import org.apache.catalina.deploy.FilterDef;
+import org.apache.catalina.deploy.FilterMap;
import org.apache.catalina.util.Enumerator;
import org.apache.catalina.util.ResourceSet;
import org.apache.catalina.util.ServerInfo;
public void addFilter(String filterName, String description,
String className, Map<String, String> initParameters,
boolean isAsyncSupported) {
- // TODO SERVLET3
+
+ if (context.initialized) {
+ //TODO Spec breaking enhancement to ignore this restriction
+ throw new IllegalStateException(
+ sm.getString("applicationContext.addFilter.ise",
+ getContextPath()));
+ }
+ FilterDef filterDef = new FilterDef();
+ filterDef.setFilterName(filterName);
+ filterDef.setDescription(description);
+ filterDef.setFilterClass(className);
+ filterDef.getParameterMap().putAll(initParameters);
+ context.addFilterDef(filterDef);
+ // TODO SERVLET3 - ASync support
}
public void addFilterMappingForServletNames(String filterName,
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... servletNames) {
- // TODO SERVLET3
+ if (context.initialized) {
+ //TODO Spec breaking enhancement to ignore this restriction
+ throw new IllegalStateException(sm.getString(
+ "applicationContext.addFilterMapping", getContextPath()));
+ }
+ FilterMap filterMap = new FilterMap();
+ for (String servletName : servletNames) {
+ filterMap.addServletName(servletName);
+ }
+ filterMap.setFilterName(filterName);
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
+ if (isMatchAfter) {
+ context.addFilterMap(filterMap);
+ } else {
+ context.addFilterMapBefore(filterMap);
+ }
}
public void addFilterMappingForUrlPatterns(String filterName,
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... urlPatterns) {
- // TODO SERVLET3
+
+ if (context.initialized) {
+ //TODO Spec breaking enhancement to ignore this restriction
+ throw new IllegalStateException(sm.getString(
+ "applicationContext.addFilterMapping", getContextPath()));
+ }
+ FilterMap filterMap = new FilterMap();
+ for (String urlPattern : urlPatterns) {
+ filterMap.addURLPattern(urlPattern);
+ }
+ filterMap.setFilterName(filterName);
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
+ if (isMatchAfter) {
+ context.addFilterMap(filterMap);
+ } else {
+ context.addFilterMapBefore(filterMap);
+ }
}
public void addServletMapping(String servletName, String[] urlPatterns) {
- // TODO SERVLET3
+ if (context.initialized) {
+ //TODO Spec breaking enhancement to ignore this restriction
+ throw new IllegalStateException(sm.getString(
+ "applicationContext.addServletMapping", getContextPath()));
+ }
+ for (String urlPattern : urlPatterns) {
+ boolean jspWildCard = ("*.jsp".equals(urlPattern));
+ context.addServletMapping(servletName, urlPattern, jspWildCard);
+ }
}
// Context > Host > Engine > Service
Connector[] connectors = ((Engine) context.getParent().getParent())
.getService().findConnectors();
- // Need at least one SSL enabled connector to use the SSL session ID.
- // has to be SSL enabled so we can close the SSL session.
- // TODO extend this for SSL sessions managed by accelerators, web
- // servers etc
+ // Need at least one secure connector to use the SSL session ID.
for (Connector connector : connectors) {
if (Boolean.TRUE.equals(connector.getAttribute("secure"))) {
defaultSessionTrackingModes.add(SessionTrackingMode.SSL);
}
-}
\ No newline at end of file
+}
public void addFilter(String filterName, String description,
String className, Map<String, String> initParameters,
boolean isAsyncSupported) {
- // TODO SERVLET3
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("addFilter", new Object[]{filterName, description,
+ className, initParameters,
+ Boolean.valueOf(isAsyncSupported)});
+ } else {
+ context.addFilter(filterName, description, className,
+ initParameters, isAsyncSupported);
+ }
}
public void addFilterMappingForServletNames(String filterName,
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... servletNames) {
- // TODO SERVLET3
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("addFilterMappingForServletNames",
+ new Object[]{filterName, dispatcherTypes,
+ Boolean.valueOf(isMatchAfter), servletNames});
+ } else {
+ context.addFilterMappingForServletNames(filterName, dispatcherTypes,
+ isMatchAfter, servletNames);
+ }
}
public void addFilterMappingForUrlPatterns(String filterName,
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... urlPatterns) {
- // TODO SERVLET3
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("addFilterMappingForUrlPatterns",
+ new Object[]{filterName, dispatcherTypes,
+ Boolean.valueOf(isMatchAfter), urlPatterns});
+ } else {
+ context.addFilterMappingForUrlPatterns(filterName, dispatcherTypes,
+ isMatchAfter, urlPatterns);
+ }
}
public void addServletMapping(String servletName, String[] urlPatterns) {
- // TODO SERVLET3
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("addServletMapping",
+ new Object[]{servletName, urlPatterns});
+ } else {
+ context.addServletMapping(servletName, urlPatterns);
+ }
}
public SessionCookieConfig getSessionCookieConfig() {
- // TODO SERVLET3
- return null;
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ return (SessionCookieConfig)
+ doPrivileged("getSessionCookieConfig", null);
+ } else {
+ return context.getSessionCookieConfig();
+ }
}
public void setSessionCookieConfig(SessionCookieConfig sessionCookieConfig) {
- // TODO SERVLET3
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("setSessionCookieConfig",
+ new Object[]{sessionCookieConfig});
+ } else {
+ context.setSessionCookieConfig(sessionCookieConfig);
+ }
}
# See the License for the specific language governing permissions and
# limitations under the License.
+applicationContext.addFilter.ise=Filters can not be added to context {0} at this time. See SRV.4.4.
+applicationContext.addFilterMapping.ise=Filter mappings can not be added to context {0} at this time. See SRV.4.4.
+applicationContext.addServletMapping.ise=Servlet mappings can not be added to context {0} at this time. See SRV.4.4.
applicationContext.attributeEvent=Exception thrown by attributes event listener
applicationContext.mapping.error=Error during mapping
applicationContext.requestDispatcher.iae=Path {0} does not start with a "/" character
/**
* The set of filter mappings for this application, in the order
- * they were defined in the deployment descriptor.
+ * they were defined in the deployment descriptor with additional mappings
+ * added via the {@link ServletContext} possibly both before and after those
+ * defined in the deployment descriptor.
*/
private FilterMap filterMaps[] = new FilterMap[0];
+ /**
+ * Filter mappings added via {@link ServletContext} may have to be inserted
+ * before the mappings in the deploymenmt descriptor but must be inserted in
+ * the order the {@link ServletContext} methods are called. This isn't an
+ * issue for the mappings added after the deployment descriptor - they are
+ * just added to the end - but correctly the adding mappings before the
+ * deployment descriptor mappings requires knowing where the last 'before'
+ * mapping was added.
+ */
+ private int filterMapInsertPoint = 0;
/**
* Ignore annotations.
/**
- * Add a filter mapping to this Context.
+ * Add a filter mapping to this Context at the end of the current set
+ * of filter mappings.
*
* @param filterMap The filter mapping to be added
*
*/
public void addFilterMap(FilterMap filterMap) {
+ validateFilterMap(filterMap);
+ // Add this filter mapping to our registered set
+ synchronized (filterMaps) {
+ FilterMap results[] =new FilterMap[filterMaps.length + 1];
+ System.arraycopy(filterMaps, 0, results, 0, filterMaps.length);
+ results[filterMaps.length] = filterMap;
+ filterMaps = results;
+ }
+ fireContainerEvent("addFilterMap", filterMap);
+ }
+
+
+ /**
+ * Add a filter mapping to this Context before the mappings defined in the
+ * deployment descriptor but after any other mappings added via this method.
+ *
+ * @param filterMap The filter mapping to be added
+ *
+ * @exception IllegalArgumentException if the specified filter name
+ * does not match an existing filter definition, or the filter mapping
+ * is malformed
+ */
+ public void addFilterMapBefore(FilterMap filterMap) {
+
+ validateFilterMap(filterMap);
+
+ // Add this filter mapping to our registered set
+ synchronized (filterMaps) {
+ FilterMap results[] = new FilterMap[filterMaps.length + 1];
+ System.arraycopy(filterMaps, 0, results, 0, filterMapInsertPoint);
+ results[filterMapInsertPoint] = filterMap;
+ System.arraycopy(filterMaps, filterMapInsertPoint, results,
+ filterMaps.length - filterMapInsertPoint+1,
+ filterMapInsertPoint);
+
+ filterMapInsertPoint++;
+
+ results[filterMaps.length] = filterMap;
+ filterMaps = results;
+ }
+ fireContainerEvent("addFilterMap", filterMap);
+ }
+
+
+ /**
+ * Validate the supplied FilterMap.
+ */
+ private void validateFilterMap(FilterMap filterMap) {
// Validate the proposed filter mapping
String filterName = filterMap.getFilterName();
String[] servletNames = filterMap.getServletNames();
if (findFilterDef(filterName) == null)
throw new IllegalArgumentException
(sm.getString("standardContext.filterMap.name", filterName));
-// <= Servlet API 2.4
-// if ((servletNames.length == 0) && (urlPatterns.length == 0))
-// Servlet API 2.5 (FIX 43338)
-// SRV 6.2.5 says supporting for '*' as the servlet-name in filter-mapping.
+
if (!filterMap.getMatchAllServletNames() &&
!filterMap.getMatchAllUrlPatterns() &&
(servletNames.length == 0) && (urlPatterns.length == 0))
throw new IllegalArgumentException
(sm.getString("standardContext.filterMap.either"));
*/
- // Because filter-pattern is new in 2.3, no need to adjust
- // for 2.2 backwards compatibility
for (int i = 0; i < urlPatterns.length; i++) {
if (!validateURLPattern(urlPatterns[i])) {
throw new IllegalArgumentException
urlPatterns[i]));
}
}
-
- // Add this filter mapping to our registered set
- synchronized (filterMaps) {
- FilterMap results[] =new FilterMap[filterMaps.length + 1];
- System.arraycopy(filterMaps, 0, results, 0, filterMaps.length);
- results[filterMaps.length] = filterMap;
- filterMaps = results;
- }
- fireContainerEvent("addFilterMap", filterMap);
-
}
-
/**
* Add the classname of an InstanceListener to be added to each
* Wrapper appended to this Context.
System.arraycopy(filterMaps, 0, results, 0, n);
System.arraycopy(filterMaps, n + 1, results, n,
(filterMaps.length - 1) - n);
+ if (n < filterMapInsertPoint) {
+ filterMapInsertPoint--;
+ }
filterMaps = results;
}
import org.apache.catalina.util.RequestUtil;
import java.io.Serializable;
+import javax.servlet.DispatcherType;
+
/**
* Representation of a filter mapping for a web application, as represented
public void setDispatcher(String dispatcherString) {
String dispatcher = dispatcherString.toUpperCase();
- if (dispatcher.equals("FORWARD")) {
+ if (dispatcher.equals(DispatcherType.FORWARD.name())) {
// apply FORWARD to the global dispatcherMapping.
switch (dispatcherMapping) {
case REQUEST_ERROR_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
case REQUEST_INCLUDE : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
}
- } else if (dispatcher.equals("INCLUDE")) {
+ } else if (dispatcher.equals(DispatcherType.INCLUDE.name())) {
// apply INCLUDE to the global dispatcherMapping.
switch (dispatcherMapping) {
case NOT_SET : dispatcherMapping = INCLUDE; break;
case REQUEST_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
case REQUEST_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
}
- } else if (dispatcher.equals("REQUEST")) {
+ } else if (dispatcher.equals(DispatcherType.REQUEST.name())) {
// apply REQUEST to the global dispatcherMapping.
switch (dispatcherMapping) {
case NOT_SET : dispatcherMapping = REQUEST; break;
case INCLUDE_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break;
case INCLUDE_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break;
}
- } else if (dispatcher.equals("ERROR")) {
+ } else if (dispatcher.equals(DispatcherType.ERROR.name())) {
// apply ERROR to the global dispatcherMapping.
switch (dispatcherMapping) {
case NOT_SET : dispatcherMapping = ERROR; break;