use of io.crnk.servlet.internal.ServletModule 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.servlet.internal.ServletModule in project crnk-framework by crnk-project.
the class CrnkConfigV3 method crnkBoot.
@Bean
@ConditionalOnMissingBean(CrnkBoot.class)
public CrnkBoot crnkBoot(ServiceDiscovery serviceDiscovery) {
CrnkBoot boot = new CrnkBoot();
boot.setObjectMapper(objectMapper);
if (properties.getDomainName() != null && properties.getPathPrefix() != null) {
String baseUrl = properties.getDomainName() + properties.getPathPrefix();
boot.setServiceUrlProvider(new ConstantServiceUrlProvider(baseUrl));
}
boot.setServiceDiscovery(serviceDiscovery);
boot.setDefaultPageLimit(properties.getDefaultPageLimit());
boot.setMaxPageLimit(properties.getMaxPageLimit());
boot.setPropertiesProvider(new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (CrnkProperties.RESOURCE_SEARCH_PACKAGE.equals(key)) {
return properties.getResourcePackage();
}
if (CrnkProperties.RESOURCE_DEFAULT_DOMAIN.equals(key)) {
return properties.getDomainName();
}
if (CrnkProperties.WEB_PATH_PREFIX.equals(key)) {
return properties.getPathPrefix();
}
if (CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES.equals(key)) {
return String.valueOf(properties.getAllowUnknownAttributes());
}
if (CrnkProperties.ALLOW_UNKNOWN_PARAMETERS.equals(key)) {
return String.valueOf(properties.getAllowUnknownParameters());
}
if (CrnkProperties.RETURN_404_ON_NULL.equals(key)) {
return String.valueOf(properties.getReturn404OnNull());
}
return applicationContext.getEnvironment().getProperty(key);
}
});
boot.setAllowUnknownAttributes();
boot.addModule(new ServletModule(boot.getModuleRegistry().getHttpRequestContextProvider()));
boot.boot();
return boot;
}
use of io.crnk.servlet.internal.ServletModule 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.servlet.internal.ServletModule 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.servlet.internal.ServletModule 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