@Override
  public void initFilter(FilterContainer container, Configuration conf) {
    setAuthFilterConfig(conf);

    String authType = filterConfig.get(AuthenticationFilter.AUTH_TYPE);
    if (authType.equals(PseudoAuthenticationHandler.TYPE)) {
      filterConfig.put(AuthenticationFilter.AUTH_TYPE,
          PseudoDelegationTokenAuthenticationHandler.class.getName());
    } else if (authType.equals(KerberosAuthenticationHandler.TYPE)) {
      filterConfig.put(AuthenticationFilter.AUTH_TYPE,
          KerberosDelegationTokenAuthenticationHandler.class.getName());
    }
    filterConfig.put(DelegationTokenAuthenticationHandler.TOKEN_KIND,
        TimelineDelegationTokenIdentifier.KIND_NAME.toString());

    container.addGlobalFilter("Timeline Authentication Filter",
        TimelineAuthenticationFilter.class.getName(),
        filterConfig);
  }
@Test
  public void testProxyUserConfiguration() {
    FilterContainer container = Mockito.mock(FilterContainer.class);
    for (int i = 0; i < 3; ++i) {
      Configuration conf = new YarnConfiguration();
      switch (i) {
      case 0:
        // hadoop.proxyuser prefix
        conf.set("hadoop.proxyuser.foo.hosts", "*");
        conf.set("hadoop.proxyuser.foo.users", "*");
        conf.set("hadoop.proxyuser.foo.groups", "*");
        break;
      case 1:
        // yarn.timeline-service.http-authentication.proxyuser prefix
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.hosts", "*");
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.users", "*");
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.groups", "*");
        break;
      case 2:
        // hadoop.proxyuser prefix has been overwritten by
        // yarn.timeline-service.http-authentication.proxyuser prefix
        conf.set("hadoop.proxyuser.foo.hosts", "bar");
        conf.set("hadoop.proxyuser.foo.users", "bar");
        conf.set("hadoop.proxyuser.foo.groups", "bar");
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.hosts", "*");
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.users", "*");
        conf.set(TIMELINE_HTTP_AUTH_PREFIX + "proxyuser.foo.groups", "*");
        break;
      default:
        break;
      }

      TimelineAuthenticationFilterInitializer initializer =
          new TimelineAuthenticationFilterInitializer();
      initializer.initFilter(container, conf);
      Assert.assertEquals(
          "*", initializer.filterConfig.get("proxyuser.foo.hosts"));
      Assert.assertEquals(
          "*", initializer.filterConfig.get("proxyuser.foo.users"));
      Assert.assertEquals(
          "*", initializer.filterConfig.get("proxyuser.foo.groups"));
    }
  }