Search in sources :

Example 56 with FilterConfig

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

the class TestStaticUserWebFilter method mockConfig.

private FilterConfig mockConfig(String username) {
    FilterConfig mock = Mockito.mock(FilterConfig.class);
    Mockito.doReturn(username).when(mock).getInitParameter(ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
    return mock;
}
Also used : FilterConfig(javax.servlet.FilterConfig)

Example 57 with FilterConfig

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

the class TestCorsFilter method testInitDefaultFilterConfig.

@Test
public void testInitDefaultFilterConfig() throws IOException, ServletException {
    TesterHttpServletRequest request = new TesterHttpServletRequest();
    request.setHeader(CorsFilter.REQUEST_HEADER_ORIGIN, TesterFilterConfigs.HTTPS_WWW_APACHE_ORG);
    request.setMethod("GET");
    TesterHttpServletResponse response = new TesterHttpServletResponse();
    CorsFilter corsFilter = new CorsFilter();
    corsFilter.init(new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public String getFilterName() {
            return null;
        }
    });
    corsFilter.doFilter(request, response, filterChain);
    Assert.assertTrue(response.getHeader(CorsFilter.RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN).equals("https://www.apache.org"));
    Assert.assertTrue(((Boolean) request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_IS_CORS_REQUEST)).booleanValue());
    Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_ORIGIN).equals(TesterFilterConfigs.HTTPS_WWW_APACHE_ORG));
    Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_REQUEST_TYPE).equals(CorsFilter.CORSRequestType.SIMPLE.name().toLowerCase(Locale.ENGLISH)));
}
Also used : Enumeration(java.util.Enumeration) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) Test(org.junit.Test)

Example 58 with FilterConfig

use of javax.servlet.FilterConfig in project grails-core by grails.

the class SitemeshLayoutViewResolver method loadSitemeshConfig.

protected Factory loadSitemeshConfig() {
    FilterConfig filterConfig = new FilterConfig() {

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return new Enumeration<String>() {

                @Override
                public boolean hasMoreElements() {
                    return false;
                }

                @Override
                public String nextElement() {
                    throw new NoSuchElementException();
                }
            };
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public String getFilterName() {
            return null;
        }
    };
    Config config = new Config(filterConfig);
    Grails5535Factory sitemeshFactory = new Grails5535Factory(config);
    if (servletContext != null) {
        servletContext.setAttribute(FACTORY_SERVLET_CONTEXT_ATTRIBUTE, sitemeshFactory);
    }
    sitemeshFactory.refresh();
    FactoryHolder.setFactory(sitemeshFactory);
    sitemeshConfigLoaded = true;
    return sitemeshFactory;
}
Also used : Enumeration(java.util.Enumeration) Config(com.opensymphony.module.sitemesh.Config) FilterConfig(javax.servlet.FilterConfig) FilterConfig(javax.servlet.FilterConfig) NoSuchElementException(java.util.NoSuchElementException) Grails5535Factory(org.grails.web.sitemesh.Grails5535Factory)

Example 59 with FilterConfig

use of javax.servlet.FilterConfig in project guice by google.

the class FilterPipelineTest method testDispatchThruGuiceFilter.

public final void testDispatchThruGuiceFilter() throws ServletException, IOException {
    //create mocks
    FilterConfig filterConfig = createMock(FilterConfig.class);
    ServletContext servletContext = createMock(ServletContext.class);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    FilterChain proceedingFilterChain = createMock(FilterChain.class);
    //begin mock script ***
    expect(filterConfig.getServletContext()).andReturn(servletContext).once();
    expect(request.getRequestURI()).andReturn("/public/login.jsp").anyTimes();
    expect(request.getContextPath()).andReturn("").anyTimes();
    //at the end, proceed down webapp's normal filter chain
    proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
    expectLastCall().once();
    //run mock script ***
    replay(filterConfig, servletContext, request, proceedingFilterChain);
    final GuiceFilter webFilter = new GuiceFilter();
    webFilter.init(filterConfig);
    webFilter.doFilter(request, null, proceedingFilterChain);
    webFilter.destroy();
    //assert expectations
    verify(filterConfig, servletContext, request, proceedingFilterChain);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Example 60 with FilterConfig

use of javax.servlet.FilterConfig in project guice by google.

the class ContinuingRequestIntegrationTest method testRequestContinuesInOtherThread.

public final void testRequestContinuesInOtherThread() throws ServletException, IOException, InterruptedException {
    executor = Executors.newSingleThreadExecutor();
    injector = Guice.createInjector(new ServletModule() {

        @Override
        protected void configureServlets() {
            serve("/*").with(ContinuingServlet.class);
            bind(ExecutorService.class).toInstance(executor);
        }
    });
    FilterConfig filterConfig = createMock(FilterConfig.class);
    expect(filterConfig.getServletContext()).andReturn(createMock(ServletContext.class));
    GuiceFilter guiceFilter = injector.getInstance(GuiceFilter.class);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    expect(request.getRequestURI()).andReturn("/");
    expect(request.getContextPath()).andReturn("").anyTimes();
    expect(request.getMethod()).andReturn("GET");
    expect(request.getCookies()).andReturn(new Cookie[0]);
    FilterChain filterChain = createMock(FilterChain.class);
    expect(request.getParameter(PARAM_NAME)).andReturn(PARAM_VALUE);
    replay(request, filterConfig, filterChain);
    guiceFilter.init(filterConfig);
    guiceFilter.doFilter(request, null, filterChain);
    // join.
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    assertEquals(PARAM_VALUE, injector.getInstance(OffRequestCallable.class).value);
    verify(request, filterConfig, filterChain);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) AbstractExecutorService(java.util.concurrent.AbstractExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

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