AuthFilter extends AuthenticationFilter { @Override protected Properties getConfiguration(String prefix, FilterConfig config) throws ServletException { final Properties p = super.getConfiguration(CONF_PREFIX, config); p.setProperty(AUTH_TYPE, UserGroupInformation.isSecurityEnabled() ? KerberosAuthenticationHandler.TYPE : PseudoAuthenticationHandler.TYPE); if (p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED) == null) { p.setProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, "true"); } p.setProperty(COOKIE_PATH, "/"); return p; }  @Override void doFilter(ServletRequest request, ServletResponse response,
      FilterChain filterChain);  }
@Test public void testGetConfiguration() throws ServletException { AuthFilter filter = new AuthFilter(); Map<String, String> m = new HashMap<>(); m.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY, "xyz/thehost@REALM"); m.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY, "thekeytab"); FilterConfig config = new DummyFilterConfig(m); Properties p = filter.getConfiguration("random", config); Assert .assertEquals("xyz/thehost@REALM", p.getProperty("kerberos.principal")); Assert.assertEquals("thekeytab", p.getProperty("kerberos.keytab")); Assert.assertEquals("true", p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED)); }
@Test public void testGetSimpleAuthDisabledConfiguration() throws ServletException { AuthFilter filter = new AuthFilter(); Map<String, String> m = new HashMap<String,String>(); m.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_SIMPLE_ANONYMOUS_ALLOWED, "false"); FilterConfig config = new DummyFilterConfig(m); Properties p = filter.getConfiguration("random", config); Assert.assertEquals("false", p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED)); }
@Test public void testGetSimpleAuthDefaultConfiguration() throws ServletException { AuthFilter filter = new AuthFilter(); Map<String, String> m = new HashMap<String,String>(); FilterConfig config = new DummyFilterConfig(m); Properties p = filter.getConfiguration("random", config); Assert.assertEquals("true", p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED)); }