use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class SecurityExceptionProcessorTest method testAuthenticationRequired.
@Test
public void testAuthenticationRequired() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
doThrow(AuthenticationRequiredException.class).when(chain).processRequest(context);
processor.processRequest(context, chain);
verify(chain).processRequest(context);
verify(authenticationRequiredHandler).handle(eq(context), any(AuthenticationRequiredException.class));
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class ProfileControllerTest method setCurrentRequestContext.
private void setCurrentRequestContext() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestContext.setCurrent(context);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class TenantControllerTest method setCurrentRequestContext.
private void setCurrentRequestContext() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestContext.setCurrent(context);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RequestSecurityFilter method doFilterInternal.
/**
* Passes the request through the chain of {@link RequestSecurityProcessor}s.
*
* @param request
* @param response
* @param chain
* @throws IOException
* @throws ServletException
*/
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
RequestContext context = RequestContext.getCurrent();
if (context == null) {
context = createRequestContext(request, response);
}
List<RequestSecurityProcessor> finalSecurityProcessors = new ArrayList<>(securityProcessors);
finalSecurityProcessors.add(getLastProcessorInChain(chain));
Iterator<RequestSecurityProcessor> processorIter = finalSecurityProcessors.iterator();
RequestSecurityProcessorChain processorChain = new RequestSecurityProcessorChainImpl(processorIter);
try {
processorChain.processRequest(context);
} catch (IOException | ServletException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e.getMessage(), e);
}
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class AuthenticationRequiredHandlerImplTest method testSendError.
@Test
public void testSendError() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
handler.handle(context, new AuthenticationRequiredException(""));
verify(requestCache).saveRequest(request, response);
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertTrue(response.isCommitted());
}
Aggregations