Search in sources :

Example 46 with RequestContext

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;
}
Also used : HashMap(java.util.HashMap) RequestContext(org.craftercms.commons.http.RequestContext)

Example 47 with RequestContext

use of org.craftercms.commons.http.RequestContext in project engine by craftercms.

the class ConfigAwareTestBase method setCurrentRequestContext.

private void setCurrentRequestContext() {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
    request.setPathInfo("/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response, null);
    RequestContext.setCurrent(context);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(org.craftercms.commons.http.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

RequestContext (org.craftercms.commons.http.RequestContext)47 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)40 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)40 Test (org.junit.Test)37 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)17 Authentication (org.craftercms.security.authentication.Authentication)12 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)11 Cookie (javax.servlet.http.Cookie)9 Profile (org.craftercms.profile.api.Profile)9 ObjectId (org.bson.types.ObjectId)7 AuthenticationRequiredException (org.craftercms.security.exception.AuthenticationRequiredException)5 AccessDeniedException (org.craftercms.security.exception.AccessDeniedException)4 Date (java.util.Date)3 BadCredentialsException (org.craftercms.security.exception.BadCredentialsException)3 RequestSecurityProcessor (org.craftercms.security.processors.RequestSecurityProcessor)3 HashMap (java.util.HashMap)2 HttpSession (javax.servlet.http.HttpSession)2 AuthenticationException (org.craftercms.security.exception.AuthenticationException)2 ExecutionInput (graphql.ExecutionInput)1 ExecutionInput.newExecutionInput (graphql.ExecutionInput.newExecutionInput)1