Search in sources :

Example 11 with FilterMapping

use of org.eclipse.jetty.servlet.FilterMapping in project hadoop by apache.

the class HttpServer2 method addInternalServlet.

/**
   * Add an internal servlet in the server, specifying whether or not to
   * protect with Kerberos authentication.
   * Note: This method is to be used for adding servlets that facilitate
   * internal communication and not for user facing functionality. For
   * servlets added using this method, filters (except internal Kerberos
   * filters) are not enabled.
   *
   * @param name The name of the servlet (can be passed as null)
   * @param pathSpec The path spec for the servlet
   * @param clazz The servlet class
   * @param requireAuth Require Kerberos authenticate to access servlet
   */
public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) {
    ServletHolder holder = new ServletHolder(clazz);
    if (name != null) {
        holder.setName(name);
    }
    // Jetty doesn't like the same path spec mapping to different servlets, so
    // if there's already a mapping for this pathSpec, remove it and assume that
    // the newest one is the one we want
    final ServletMapping[] servletMappings = webAppContext.getServletHandler().getServletMappings();
    for (int i = 0; i < servletMappings.length; i++) {
        if (servletMappings[i].containsPathSpec(pathSpec)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found existing " + servletMappings[i].getServletName() + " servlet at path " + pathSpec + "; will replace mapping" + " with " + holder.getName() + " servlet");
            }
            ServletMapping[] newServletMappings = ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
            webAppContext.getServletHandler().setServletMappings(newServletMappings);
            break;
        }
    }
    webAppContext.addServlet(holder, pathSpec);
    if (requireAuth && UserGroupInformation.isSecurityEnabled()) {
        LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
        ServletHandler handler = webAppContext.getServletHandler();
        FilterMapping fmap = new FilterMapping();
        fmap.setPathSpec(pathSpec);
        fmap.setFilterName(SPNEGO_FILTER);
        fmap.setDispatches(FilterMapping.ALL);
        handler.addFilterMapping(fmap);
    }
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Example 12 with FilterMapping

use of org.eclipse.jetty.servlet.FilterMapping in project hadoop by apache.

the class HttpServer2 method addFilter.

@Override
public void addFilter(String name, String classname, Map<String, String> parameters) {
    FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
    final String[] USER_FACING_URLS = { "*.html", "*.jsp" };
    FilterMapping fmap = getFilterMapping(name, USER_FACING_URLS);
    defineFilter(webAppContext, filterHolder, fmap);
    LOG.info("Added filter " + name + " (class=" + classname + ") to context " + webAppContext.getDisplayName());
    final String[] ALL_URLS = { "/*" };
    fmap = getFilterMapping(name, ALL_URLS);
    for (Map.Entry<ServletContextHandler, Boolean> e : defaultContexts.entrySet()) {
        if (e.getValue()) {
            ServletContextHandler ctx = e.getKey();
            defineFilter(ctx, filterHolder, fmap);
            LOG.info("Added filter " + name + " (class=" + classname + ") to context " + ctx.getDisplayName());
        }
    }
    filterNames.add(name);
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 13 with FilterMapping

use of org.eclipse.jetty.servlet.FilterMapping in project hadoop by apache.

the class HttpServer2 method addGlobalFilter.

@Override
public void addGlobalFilter(String name, String classname, Map<String, String> parameters) {
    final String[] ALL_URLS = { "/*" };
    FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
    FilterMapping fmap = getFilterMapping(name, ALL_URLS);
    defineFilter(webAppContext, filterHolder, fmap);
    for (ServletContextHandler ctx : defaultContexts.keySet()) {
        defineFilter(ctx, filterHolder, fmap);
    }
    LOG.info("Added global filter '" + name + "' (class=" + classname + ")");
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 14 with FilterMapping

use of org.eclipse.jetty.servlet.FilterMapping in project hadoop by apache.

the class HttpServer2 method addFilterPathMapping.

/**
   * Add the path spec to the filter path mapping.
   * @param pathSpec The path spec
   * @param webAppCtx The WebApplicationContext to add to
   */
protected void addFilterPathMapping(String pathSpec, ServletContextHandler webAppCtx) {
    ServletHandler handler = webAppCtx.getServletHandler();
    for (String name : filterNames) {
        FilterMapping fmap = new FilterMapping();
        fmap.setPathSpec(pathSpec);
        fmap.setFilterName(name);
        fmap.setDispatches(FilterMapping.ALL);
        handler.addFilterMapping(fmap);
    }
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Aggregations

FilterMapping (org.eclipse.jetty.servlet.FilterMapping)14 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)7 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DispatcherType (javax.servlet.DispatcherType)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)2 MetaData (org.eclipse.jetty.webapp.MetaData)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 EventListener (java.util.EventListener)1 Filter (javax.servlet.Filter)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 SessionTrackingMode (javax.servlet.SessionTrackingMode)1 WebFilter (javax.servlet.annotation.WebFilter)1 WebInitParam (javax.servlet.annotation.WebInitParam)1 JspPropertyGroupDescriptor (javax.servlet.descriptor.JspPropertyGroupDescriptor)1 TaglibDescriptor (javax.servlet.descriptor.TaglibDescriptor)1