org.apache.hadoop.http.FilterInitializer Java Examples

The following examples show how to use org.apache.hadoop.http.FilterInitializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Get an array of FilterConfiguration specified in the conf.
 */
private static FilterInitializer[] getFilterInitializers(
    ConfigurationSource conf) {
  if (conf == null) {
    return null;
  }

  Class<?>[] classes =
      conf.getClasses(FILTER_INITIALIZER_PROPERTY, StaticUserWebFilter.class);
  if (classes == null) {
    return null;
  }

  FilterInitializer[] initializers = new FilterInitializer[classes.length];
  for (int i = 0; i < classes.length; i++) {
    try {
      initializers[i] = (FilterInitializer) classes[i].newInstance();
    } catch (Exception e) {
      LOG.error("Can't initialize the filter initializer {}",
          classes[i].getCanonicalName(), e);
    }
  }
  return initializers;
}
 
Example #2
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private void initializeWebServer(String name, String hostName,
    ConfigurationSource conf, String[] pathSpecs,
    String authFilterConfigPrefix,
    boolean securityEnabled) throws IOException {

  Preconditions.checkNotNull(webAppContext);

  int maxThreads = conf.getInt(HTTP_MAX_THREADS_KEY, -1);
  // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the
  // default value (currently 250).

  QueuedThreadPool threadPool = (QueuedThreadPool) webServer.getThreadPool();
  threadPool.setDaemon(true);
  if (maxThreads != -1) {
    threadPool.setMaxThreads(maxThreads);
  }

  SessionHandler handler = webAppContext.getSessionHandler();
  handler.setHttpOnly(true);
  handler.getSessionCookieConfig().setSecure(true);

  ContextHandlerCollection contexts = new ContextHandlerCollection();
  RequestLog requestLog = HttpRequestLog.getRequestLog(name);

  handlers.addHandler(contexts);
  if (requestLog != null) {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(requestLog);
    handlers.addHandler(requestLogHandler);
  }
  handlers.addHandler(webAppContext);
  final String appDir = getWebAppsPath(name);
  addDefaultApps(contexts, appDir, conf);
  webServer.setHandler(handlers);

  Map<String, String> xFrameParams = setHeaders(conf);
  addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
  final FilterInitializer[] initializers = getFilterInitializers(conf);
  if (initializers != null) {
    conf.set(BIND_ADDRESS, hostName);
    org.apache.hadoop.conf.Configuration hadoopConf =
        LegacyHadoopConfigurationSource.asHadoopConfiguration(conf);
    Map<String, String> filterConfig = getFilterConfigMap(hadoopConf,
        authFilterConfigPrefix);
    for (FilterInitializer c : initializers) {
      if ((c instanceof AuthenticationFilterInitializer) && securityEnabled) {
        addFilter("authentication",
            AuthenticationFilter.class.getName(), filterConfig);
      } else {
        c.initFilter(this, hadoopConf);
      }
    }
  }

  addDefaultServlets();

  if (pathSpecs != null) {
    for (String path : pathSpecs) {
      LOG.info("adding path spec: {}", path);
      addFilterPathMapping(path, webAppContext);
    }
  }
}