Example usage for javax.servlet FilterChain FilterChain

List of usage examples for javax.servlet FilterChain FilterChain

Introduction

In this page you can find the example usage for javax.servlet FilterChain FilterChain.

Prototype

FilterChain

Source Link

Usage

From source file:se.trillian.goodies.web.DisableSessionIdInUrlFilterTest.java

public void testSessionIdInEncodeUrlIsRemoved() throws Exception {
    final boolean[] called = new boolean[] { false };

    filter.doFilter(request, response, new FilterChain() {
        public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {

            HttpServletResponse response = (HttpServletResponse) res;
            assertEquals("/home_en.html", response.encodeRedirectURL("/home_en.html"));
            assertEquals("/home_en.html", response.encodeURL("/home_en.html"));
            called[0] = true;//w  ww.  j a va2s. c o m
        }
    });

    assertTrue(called[0]);
}

From source file:com.thoughtworks.go.server.security.BasicAuthenticationFilterTest.java

@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
    BasicAuthenticationFilter filter = new BasicAuthenticationFilter();
    final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[] { false };

    filter.setAuthenticationManager(new AuthenticationManager() {
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
            return new UsernamePasswordAuthenticationToken("school-principal",
                    "u can be principal if you know this!");
        }/* w  ww .jav a  2s  .c o  m*/
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.addHeader("Authorization", "Basic " + Base64.encodeBase64String("loser:boozer".getBytes()));
    filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
                throws IOException, ServletException {

        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));

    assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testRedirectWithQueryString() throws Exception {
    final MockHttpSession session = new MockHttpSession();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.setQueryString("test=12456");
    request.setRequestURI("/test");
    request.setSecure(true);//from   w w w.j  a  va 2s . com
    final FilterChain filterChain = new FilterChain() {

        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            // nothing to do
        }
    };

    request.setSession(session);
    this.filter = new AuthenticationFilter();

    final MockFilterConfig config = new MockFilterConfig();
    config.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
    config.addInitParameter("serverName", "localhost:8443");
    this.filter.init(config);

    this.filter.doFilter(request, response, filterChain);

    assertEquals(CAS_LOGIN_URL + "?service=" + URLEncoder.encode(
            "https://localhost:8443" + request.getRequestURI() + "?" + request.getQueryString(), "UTF-8"),
            response.getRedirectedUrl());
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testAssertion() throws Exception {
    final MockHttpSession session = new MockHttpSession();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final FilterChain filterChain = new FilterChain() {

        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            // nothing to do
        }//www.java  2s .c o  m
    };

    request.setSession(session);
    session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, new AssertionImpl("test"));
    this.filter.doFilter(request, response, filterChain);

    assertNull(response.getRedirectedUrl());
}

From source file:org.jasig.cas.client.util.HttpServletRequestWrapperFilterTests.java

private FilterChain createFilterChain() {
    return new FilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            HttpServletRequestWrapperFilterTests.this.mockRequest = (HttpServletRequest) request;
        }/*from www  .  j  a v a2 s  . co m*/

    };
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testRenew() throws Exception {
    final MockHttpSession session = new MockHttpSession();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final FilterChain filterChain = new FilterChain() {

        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            // nothing to do
        }/*from   w  w  w . ja  v  a  2s  . co m*/
    };

    this.filter.setRenew(true);
    request.setSession(session);
    this.filter.doFilter(request, response, filterChain);

    assertNotNull(response.getRedirectedUrl());
    assertTrue(response.getRedirectedUrl().indexOf("renew=true") != -1);
}

From source file:com.boundlessgeo.geoserver.AppAuthFilter.java

boolean runSecurityFilters(HttpServletRequest req, HttpServletResponse res, String... chainNames)
        throws IOException, ServletException {
    final GeoServerSecurityManager secMgr = GeoServerExtensions.bean(GeoServerSecurityManager.class);
    GeoServerSecurityFilterChain secFilterChain = new GeoServerSecurityFilterChain(
            secMgr.getSecurityConfig().getFilterChain());

    List<Filter> filters = new ArrayList<Filter>();
    for (String chainName : chainNames) {
        RequestFilterChain reqFilterChain = secFilterChain.getRequestChainByName(chainName);
        filters.addAll(Lists.transform(reqFilterChain.getCompiledFilterNames(), new Function<String, Filter>() {
            @Override/*from  w  w  w . j  ava  2s.  com*/
            public Filter apply(@Nullable String s) {
                try {
                    return secMgr.loadFilter(s);
                } catch (IOException e) {
                    //TODO: something better here
                    throw new RuntimeException("Unable to load security filter:" + s);
                }
            }
        }));
    }

    GeoServerCompositeFilter compFilter = new GeoServerCompositeFilter();
    compFilter.setNestedFilters(filters);
    compFilter.doFilter(req, res, new FilterChain() {
        @Override
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
        }
    });

    return isAuthenticated();
}

From source file:org.opennms.netmgt.ncs.rest.AbstractSpringJerseyRestTestCase.java

protected void dispatch(final MockHttpServletRequest request, final MockHttpServletResponse response)
        throws Exception {
    final FilterChain filterChain = new FilterChain() {
        public void doFilter(final ServletRequest filterRequest, final ServletResponse filterResponse)
                throws IOException, ServletException {
            getDispatcher().service(filterRequest, filterResponse);
        }/*from ww w . ja  v a 2 s  . c  om*/
    };
    if (getFilter() != null) {
        getFilter().doFilter(request, response, filterChain);
    } else {
        filterChain.doFilter(request, response);
    }
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testGateway() throws Exception {
    final MockHttpSession session = new MockHttpSession();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final FilterChain filterChain = new FilterChain() {

        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            // nothing to do
        }/*  w w w.ja v  a 2 s  .  com*/
    };

    request.setSession(session);
    this.filter.setRenew(true);
    this.filter.setGateway(true);
    this.filter.doFilter(request, response, filterChain);
    assertNotNull(session.getAttribute(DefaultGatewayResolverImpl.CONST_CAS_GATEWAY));
    assertNotNull(response.getRedirectedUrl());

    final MockHttpServletResponse response2 = new MockHttpServletResponse();
    this.filter.doFilter(request, response2, filterChain);
    assertNull(session.getAttribute(DefaultGatewayResolverImpl.CONST_CAS_GATEWAY));
    assertNull(response2.getRedirectedUrl());
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testIgnorePatterns() throws Exception {
    final AuthenticationFilter f = new AuthenticationFilter();
    final MockServletContext context = new MockServletContext();
    context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);

    context.addInitParameter("ignorePattern", "=valueTo(\\w+)");
    context.addInitParameter("service", CAS_SERVICE_URL);
    f.init(new MockFilterConfig(context));

    final MockHttpServletRequest request = new MockHttpServletRequest();
    final String URL = CAS_SERVICE_URL + "?param=valueToIgnore";
    request.setRequestURI(URL);/*from w  w  w . jav  a  2  s  . co m*/

    final MockHttpSession session = new MockHttpSession();
    request.setSession(session);

    final MockHttpServletResponse response = new MockHttpServletResponse();

    final FilterChain filterChain = new FilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
        }
    };

    f.doFilter(request, response, filterChain);
    assertNull(response.getRedirectedUrl());
}