use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class SecurityExceptionProcessorTest method testAccessDeniedWithAuthentication.
@Test
public void testAccessDeniedWithAuthentication() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
doThrow(AccessDeniedException.class).when(chain).processRequest(context);
SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), new Profile()));
processor.processRequest(context, chain);
verify(chain).processRequest(context);
verify(accessDeniedHandler).handle(eq(context), any(AccessDeniedException.class));
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class SecurityExceptionProcessorTest method testNonSecurityException.
@Test(expected = Exception.class)
public void testNonSecurityException() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);
doThrow(Exception.class).when(chain).processRequest(context);
processor.processRequest(context, chain);
}
use of org.craftercms.commons.http.RequestContext in project profile by craftercms.
the class RequestSecurityFilterTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
RequestContext context = (RequestContext) invocation.getArguments()[0];
RequestSecurityProcessorChain chain = (RequestSecurityProcessorChain) invocation.getArguments()[1];
chain.processRequest(context);
return null;
}
}).when(processor).processRequest(any(RequestContext.class), any(RequestSecurityProcessorChain.class));
filter = new RequestSecurityFilter();
filter.setSecurityEnabled(true);
filter.setSecurityProcessors(Arrays.asList(processor));
filter.setUrlsToInclude("/static-assets/paywall/**");
filter.setUrlsToExclude("/static-assets/**");
}
use of org.craftercms.commons.http.RequestContext in project engine by craftercms.
the class ExecuteControllerDirective method createScriptVariables.
protected Map<String, Object> createScriptVariables(Environment env) throws TemplateException {
Map<String, Object> variables = new HashMap<String, Object>();
RequestContext context = RequestContext.getCurrent();
SiteItem contentModel = getContentModel(env);
Object templateModel = getTemplateModel(env);
if (context != null) {
GroovyScriptUtils.addSiteItemScriptVariables(variables, context.getRequest(), context.getResponse(), servletContext, contentModel, templateModel);
} else {
throw new IllegalStateException("No current request context found");
}
return variables;
}
use of org.craftercms.commons.http.RequestContext in project engine by craftercms.
the class RenderComponentDirective method createScriptVariables.
protected Map<String, Object> createScriptVariables(SiteItem component, Map<String, Object> templateModel, Map<String, Object> additionalModel) {
Map<String, Object> variables = new HashMap<>();
RequestContext context = RequestContext.getCurrent();
if (context != null) {
GroovyScriptUtils.addSiteItemScriptVariables(variables, context.getRequest(), context.getResponse(), servletContext, component, templateModel);
if (MapUtils.isNotEmpty(additionalModel)) {
variables.putAll(additionalModel);
}
} else {
throw new IllegalStateException("No current request context found");
}
return variables;
}
Aggregations