Search in sources :

Example 61 with FilterConfig

use of javax.servlet.FilterConfig in project spring-framework by spring-projects.

the class ConditionalDelegatingFilterProxyTests method init.

@Test
public void init() throws Exception {
    FilterConfig config = new MockFilterConfig();
    filter = new PatternMappingFilterProxy(delegate, "/");
    filter.init(config);
    assertThat(delegate.filterConfig, is(config));
}
Also used : FilterConfig(javax.servlet.FilterConfig) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 62 with FilterConfig

use of javax.servlet.FilterConfig in project hadoop by apache.

the class TestAuthFilter method testGetCustomAuthConfiguration.

@Test
public void testGetCustomAuthConfiguration() throws ServletException {
    AuthFilter filter = new AuthFilter();
    Map<String, String> m = new HashMap<String, String>();
    m.put(AuthFilter.CONF_PREFIX + AuthFilter.AUTH_TYPE, "com.yourclass");
    m.put(AuthFilter.CONF_PREFIX + "alt-kerberos.param", "value");
    FilterConfig config = new DummyFilterConfig(m);
    Properties p = filter.getConfiguration(AuthFilter.CONF_PREFIX, config);
    Assert.assertEquals("com.yourclass", p.getProperty(AuthFilter.AUTH_TYPE));
    Assert.assertEquals("value", p.getProperty("alt-kerberos.param"));
}
Also used : HashMap(java.util.HashMap) FilterConfig(javax.servlet.FilterConfig) Properties(java.util.Properties) Test(org.junit.Test)

Example 63 with FilterConfig

use of javax.servlet.FilterConfig in project hadoop by apache.

the class TestAuthFilter method testGetConfiguration.

@Test
public void testGetConfiguration() throws ServletException {
    AuthFilter filter = new AuthFilter();
    Map<String, String> m = new HashMap<String, String>();
    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));
}
Also used : HashMap(java.util.HashMap) FilterConfig(javax.servlet.FilterConfig) Properties(java.util.Properties) Test(org.junit.Test)

Example 64 with FilterConfig

use of javax.servlet.FilterConfig in project newts by OpenNMS.

the class NewtsService method configureUIRedirect.

private void configureUIRedirect(Environment environment) {
    environment.servlets().addFilter("TrailingSlashRedirect", new Filter() {

        @Override
        public void init(FilterConfig cfg) throws ServletException {
            LOG.info("Initializing redirect filter");
        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            StringBuffer url = ((HttpServletRequest) request).getRequestURL();
            String path = new URL(url.toString()).getPath();
            if (path.endsWith(UI_URL_PATH)) {
                LOG.debug("Caught request to malformed URL {}, redirecting...", UI_URL_PATH);
                ((HttpServletResponse) response).sendRedirect(String.format("%s/", url.toString()));
            } else {
                chain.doFilter(request, response);
            }
        }

        @Override
        public void destroy() {
        }
    }).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Filter(javax.servlet.Filter) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterConfig(javax.servlet.FilterConfig) URL(java.net.URL)

Example 65 with FilterConfig

use of javax.servlet.FilterConfig in project hadoop by apache.

the class TestCrossOriginFilter method testPatternMatchingOrigins.

@Test
public void testPatternMatchingOrigins() throws ServletException, IOException {
    // Setup the configuration settings of the server
    Map<String, String> conf = new HashMap<String, String>();
    conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "*.example.com");
    FilterConfig filterConfig = new FilterConfigTest(conf);
    // Object under test
    CrossOriginFilter filter = new CrossOriginFilter();
    filter.init(filterConfig);
    // match multiple sub-domains
    Assert.assertFalse(filter.areOriginsAllowed("example.com"));
    Assert.assertFalse(filter.areOriginsAllowed("foo:example.com"));
    Assert.assertTrue(filter.areOriginsAllowed("foo.example.com"));
    Assert.assertTrue(filter.areOriginsAllowed("foo.bar.example.com"));
    // First origin is allowed
    Assert.assertTrue(filter.areOriginsAllowed("foo.example.com foo.nomatch.com"));
    // Second origin is allowed
    Assert.assertTrue(filter.areOriginsAllowed("foo.nomatch.com foo.example.com"));
    // No origin in list is allowed
    Assert.assertFalse(filter.areOriginsAllowed("foo.nomatch1.com foo.nomatch2.com"));
}
Also used : HashMap(java.util.HashMap) FilterConfig(javax.servlet.FilterConfig) CrossOriginFilter(org.apache.hadoop.security.http.CrossOriginFilter) Test(org.junit.Test)

Aggregations

FilterConfig (javax.servlet.FilterConfig)118 Test (org.junit.Test)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)64 FilterChain (javax.servlet.FilterChain)63 HttpServletResponse (javax.servlet.http.HttpServletResponse)50 ServletContext (javax.servlet.ServletContext)28 HashMap (java.util.HashMap)21 ServletException (javax.servlet.ServletException)21 Vector (java.util.Vector)17 Properties (java.util.Properties)15 Filter (javax.servlet.Filter)14 ServletResponse (javax.servlet.ServletResponse)14 ServletRequest (javax.servlet.ServletRequest)12 IOException (java.io.IOException)10 SignerSecretProvider (org.apache.hadoop.security.authentication.util.SignerSecretProvider)10 HttpCookie (java.net.HttpCookie)9 Cookie (javax.servlet.http.Cookie)9 Signer (org.apache.hadoop.security.authentication.util.Signer)9 Enumeration (java.util.Enumeration)8 CrossOriginFilter (org.apache.hadoop.security.http.CrossOriginFilter)8