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);
}
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));
}
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);
}
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);
}
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
}
}
}
}
Aggregations