Search in sources :

Example 1 with HttpRequestContextProvider

use of io.crnk.core.engine.http.HttpRequestContextProvider in project crnk-framework by crnk-project.

the class ServletModuleTest method testName.

@Test
public void testName() {
    HttpRequestContextProvider provider = new HttpRequestContextProvider();
    ServletModule module = new ServletModule(provider);
    Assert.assertEquals("servlet", module.getModuleName());
}
Also used : ServletModule(io.crnk.servlet.internal.ServletModule) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider) Test(org.junit.Test)

Example 2 with HttpRequestContextProvider

use of io.crnk.core.engine.http.HttpRequestContextProvider in project crnk-framework by crnk-project.

the class CrnkFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    boot = new CrnkBoot();
    boot.setPropertiesProvider(new FilterPropertiesProvider(filterConfig));
    HttpRequestContextProvider provider = boot.getModuleRegistry().getHttpRequestContextProvider();
    boot.addModule(new ServletModule(provider));
    initCrnk(boot);
    boot.boot();
}
Also used : FilterPropertiesProvider(io.crnk.servlet.internal.FilterPropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ServletModule(io.crnk.servlet.internal.ServletModule) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider)

Example 3 with HttpRequestContextProvider

use of io.crnk.core.engine.http.HttpRequestContextProvider in project crnk-framework by crnk-project.

the class HttpRequestProcessorImpl method process.

@Override
public void process(HttpRequestContextBase requestContextBase) throws IOException {
    HttpRequestContextBaseAdapter requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
    HttpRequestContextProvider httpRequestContextProvider = moduleRegistry.getHttpRequestContextProvider();
    try {
        httpRequestContextProvider.onRequestStarted(requestContext);
        List<HttpRequestProcessor> processors = moduleRegistry.getHttpRequestProcessors();
        PreconditionUtil.assertFalse("no processors available", processors.isEmpty());
        for (HttpRequestProcessor processor : processors) {
            processor.process(requestContext);
            if (requestContext.hasResponse()) {
                break;
            }
        }
    } finally {
        httpRequestContextProvider.onRequestFinished();
    }
}
Also used : HttpRequestProcessor(io.crnk.core.engine.http.HttpRequestProcessor) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider)

Example 4 with HttpRequestContextProvider

use of io.crnk.core.engine.http.HttpRequestContextProvider in project crnk-framework by crnk-project.

the class CrnkServlet method init.

@Override
public void init() throws ServletException {
    boot.setPropertiesProvider(new ServletPropertiesProvider(getServletConfig()));
    acceptPlainJson = !Boolean.parseBoolean(boot.getPropertiesProvider().getProperty(CrnkProperties.REJECT_PLAIN_JSON));
    HttpRequestContextProvider provider = boot.getModuleRegistry().getHttpRequestContextProvider();
    boot.addModule(new ServletModule(provider));
    initCrnk(boot);
    boot.boot();
}
Also used : ServletPropertiesProvider(io.crnk.servlet.internal.ServletPropertiesProvider) ServletModule(io.crnk.servlet.internal.ServletModule) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider)

Example 5 with HttpRequestContextProvider

use of io.crnk.core.engine.http.HttpRequestContextProvider in project crnk-framework by crnk-project.

the class ServletModuleTest method testSecurityProviderInstalled.

@Test
public void testSecurityProviderInstalled() {
    HttpRequestContextProvider provider = new HttpRequestContextProvider();
    ServletModule module = new ServletModule(provider);
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(module);
    boot.boot();
    SecurityProvider securityProvider = boot.getModuleRegistry().getSecurityProvider();
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.addUserRole("guest");
    request.addUserRole("admin");
    provider.onRequestStarted(new HttpRequestContextBaseAdapter(new ServletRequestContext(servletContext, request, response, "api", HttpHeaders.DEFAULT_CHARSET)));
    Assert.assertFalse(securityProvider.isUserInRole("doesNotExist"));
    Assert.assertTrue(securityProvider.isUserInRole("guest"));
    Assert.assertTrue(securityProvider.isUserInRole("admin"));
}
Also used : HttpRequestContextBaseAdapter(io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter) CrnkBoot(io.crnk.core.boot.CrnkBoot) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) ServletContext(javax.servlet.ServletContext) ServletRequestContext(io.crnk.servlet.internal.ServletRequestContext) ServletModule(io.crnk.servlet.internal.ServletModule) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

HttpRequestContextProvider (io.crnk.core.engine.http.HttpRequestContextProvider)8 ServletModule (io.crnk.servlet.internal.ServletModule)4 CrnkBoot (io.crnk.core.boot.CrnkBoot)3 Test (org.junit.Test)3 Document (io.crnk.core.engine.document.Document)2 HttpRequestContext (io.crnk.core.engine.http.HttpRequestContext)2 HttpRequestContextBaseAdapter (io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter)2 Response (io.crnk.core.engine.dispatcher.Response)1 Relationship (io.crnk.core.engine.document.Relationship)1 Resource (io.crnk.core.engine.document.Resource)1 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)1 ResourceFilter (io.crnk.core.engine.filter.ResourceFilter)1 HttpRequestProcessor (io.crnk.core.engine.http.HttpRequestProcessor)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 DocumentMapper (io.crnk.core.engine.internal.document.mapper.DocumentMapper)1 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 SecurityProvider (io.crnk.core.engine.security.SecurityProvider)1 Task (io.crnk.core.mock.models.Task)1