Search in sources :

Example 56 with FilterChain

use of javax.servlet.FilterChain in project gocd by gocd.

the class WebBasedAuthenticationFilterTest method setUp.

@Before
public void setUp() throws Exception {
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    filterChain = mock(FilterChain.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    goConfigService = mock(GoConfigService.class);
    siteUrlProvider = mock(SiteUrlProvider.class);
    securityConfig = new SecurityConfig();
    securityAuthConfig = new SecurityAuthConfig("github", "github.oauth", new ConfigurationProperty());
    securityConfig.securityAuthConfigs().add(securityAuthConfig);
    stub(goConfigService.security()).toReturn(securityConfig);
    filter = new WebBasedAuthenticationFilter(authorizationExtension, goConfigService, siteUrlProvider);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) FilterChain(javax.servlet.FilterChain) SiteUrlProvider(com.thoughtworks.go.server.web.SiteUrlProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 57 with FilterChain

use of javax.servlet.FilterChain in project gocd by gocd.

the class BasicAuthenticationFilterTest method shouldConvey_itsBasicProcessingFilter.

@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
    BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
    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!");
        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("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));
}
Also used : ServletRequest(javax.servlet.ServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ServletResponse(javax.servlet.ServletResponse) AuthenticationException(org.springframework.security.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) IOException(java.io.IOException) AuthenticationManager(org.springframework.security.AuthenticationManager) ServletException(javax.servlet.ServletException) Authentication(org.springframework.security.Authentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 58 with FilterChain

use of javax.servlet.FilterChain in project gocd by gocd.

the class GoExceptionTranslationFilterTest method setUp.

@Before
public void setUp() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
    authenticationException = mock(AuthenticationException.class);
    basicAuth = mock(BasicProcessingFilterEntryPoint.class);
    cruiseLoginFormAuth = mock(AuthenticationEntryPoint.class);
    securityService = mock(SecurityService.class);
    filter = new GoExceptionTranslationFilter();
    filter.setUrlPatternsThatShouldNotBeRedirectedToAfterLogin("(\\.json)|(/images/)");
    filter.setAuthenticationEntryPoint(cruiseLoginFormAuth);
    filter.setBasicAuthenticationEntryPoint(basicAuth);
    filter.setSecurityService(securityService);
}
Also used : AuthenticationException(org.springframework.security.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SecurityService(com.thoughtworks.go.server.service.SecurityService) FilterChain(javax.servlet.FilterChain) AuthenticationEntryPoint(org.springframework.security.ui.AuthenticationEntryPoint) BasicProcessingFilterEntryPoint(org.springframework.security.ui.basicauth.BasicProcessingFilterEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 59 with FilterChain

use of javax.servlet.FilterChain in project felix by apache.

the class RequestDispatcherImpl method include.

@Override
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request, this.resolution.handler.getContext(), this.requestInfo, DispatcherType.INCLUDE, this.resolution.handler.getServletInfo().isAsyncSupported(), this.resolution.handler.getMultipartConfig(), this.resolution.handler.getMultipartSecurityContext());
    final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
    final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
    final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
    filterChain.doFilter(req, response);
}
Also used : FilterChain(javax.servlet.FilterChain) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler)

Example 60 with FilterChain

use of javax.servlet.FilterChain in project felix by apache.

the class RequestDispatcherImpl method forward.

@Override
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    if (response.isCommitted()) {
        throw new ServletException("Response has been committed");
    } else {
        // See section 9.4 of Servlet 3.0 spec
        response.resetBuffer();
    }
    try {
        final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request, this.resolution.handler.getContext(), this.requestInfo, DispatcherType.FORWARD, this.resolution.handler.getServletInfo().isAsyncSupported(), this.resolution.handler.getMultipartConfig(), this.resolution.handler.getMultipartSecurityContext());
        final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
        final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
        final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
        filterChain.doFilter(req, response);
    } finally {
        // see section 9.4 of Servlet 3.0 spec...
        if (!request.isAsyncStarted()) {
            response.flushBuffer();
            try {
                try {
                    response.getWriter().close();
                } catch (final IllegalStateException ise) {
                    // output stream has been used
                    response.getOutputStream().close();
                }
            } catch (final Exception ignore) {
            // ignore everything, see FELIX-5053
            }
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) FilterChain(javax.servlet.FilterChain) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

FilterChain (javax.servlet.FilterChain)418 HttpServletRequest (javax.servlet.http.HttpServletRequest)317 HttpServletResponse (javax.servlet.http.HttpServletResponse)269 Test (org.junit.Test)246 ServletResponse (javax.servlet.ServletResponse)135 ServletRequest (javax.servlet.ServletRequest)118 FilterConfig (javax.servlet.FilterConfig)80 Filter (javax.servlet.Filter)68 ServletException (javax.servlet.ServletException)54 IOException (java.io.IOException)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)46 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Injector (com.google.inject.Injector)32 ServletTestUtils.newFakeHttpServletRequest (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletRequest)25 ServletContext (javax.servlet.ServletContext)25 Test (org.testng.annotations.Test)25 HttpSession (javax.servlet.http.HttpSession)24 MockFilterChain (org.springframework.mock.web.MockFilterChain)24 InvocationOnMock (org.mockito.invocation.InvocationOnMock)22 Properties (java.util.Properties)19