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