use of com.sun.jersey.api.core.ResourceConfig in project coprhd-controller by CoprHD.
the class AuthenticationServerImpl method initServer.
@Override
protected void initServer() throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String authDocumentRoot = loader.getResource(AUTH_DOCUMENT_ROOT).toString();
_server = new Server();
initConnectors();
// Static Pages
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setWelcomeFiles(new String[] { "*" });
resourceHandler.setResourceBase(authDocumentRoot);
// AuthN servlet filters
ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
rootHandler.setContextPath("/");
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { resourceHandler, rootHandler });
_server.setHandler(handlerCollection);
((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
rootHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
}
// load trust store from file to zk. must do it before authmgr started, who holds the connection with ad.
loadTrustStoreFromLocalFiles();
_dbClient.start();
_tokenManager.init();
_authManager.init();
}
use of com.sun.jersey.api.core.ResourceConfig in project coprhd-controller by CoprHD.
the class TestWebServer method initServer.
/**
* Initialize server handlers, rest resources.
*
* @throws Exception
*/
private void initServer() throws Exception {
_server = new Server();
initConnectors();
// AuthN servlet filters
ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
rootHandler.setContextPath("/");
_server.setHandler(rootHandler);
((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put(MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN_TYPE);
rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
}
}
use of com.sun.jersey.api.core.ResourceConfig in project camunda-bpm-platform by camunda.
the class JerseyServerBootstrap method setupServer.
private void setupServer(Application application) {
ResourceConfig rc = new ApplicationAdapter(application);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(ResourceConfig.FEATURE_TRACE, "true");
rc.setPropertiesAndFeatures(properties);
Properties serverProperties = readProperties();
int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
URI serverUri = UriBuilder.fromPath(ROOT_RESOURCE_PATH).scheme("http").host("localhost").port(port).build();
try {
server = GrizzlyServerFactory.createHttpServer(serverUri, rc);
} catch (IllegalArgumentException e) {
throw new ServerBootstrapException(e);
} catch (NullPointerException e) {
throw new ServerBootstrapException(e);
} catch (IOException e) {
throw new ServerBootstrapException(e);
}
}
use of com.sun.jersey.api.core.ResourceConfig in project SSM by Intel-bigdata.
the class SmartZeppelinServer method setupRestApiContextHandler.
private void setupRestApiContextHandler(WebAppContext webApp) throws Exception {
webApp.setSessionHandler(new SessionHandler());
// There are two sets of rest api: Zeppelin's and SSM's. They have different path.
ResourceConfig smartConfig = new ApplicationAdapter(new SmartRestApp());
ServletHolder smartServletHolder = new ServletHolder(new ServletContainer(smartConfig));
webApp.addServlet(smartServletHolder, SMART_PATH_SPEC);
ResourceConfig zeppelinConfig = new ApplicationAdapter(new ZeppelinRestApp());
ServletHolder zeppelinServletHolder = new ServletHolder(new ServletContainer(zeppelinConfig));
webApp.addServlet(zeppelinServletHolder, ZEPPELIN_PATH_SPEC);
String shiroIniPath = zconf.getShiroPath();
if (!StringUtils.isBlank(shiroIniPath)) {
webApp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
SecurityUtils.initSecurityManager(shiroIniPath);
webApp.addFilter(ShiroFilter.class, ZEPPELIN_PATH_SPEC, EnumSet.allOf(DispatcherType.class));
// To make shiro configuration (authentication, etc.) take effect for smart rest api as well.
webApp.addFilter(ShiroFilter.class, SMART_PATH_SPEC, EnumSet.allOf(DispatcherType.class));
webApp.addEventListener(new EnvironmentLoaderListener());
}
}
use of com.sun.jersey.api.core.ResourceConfig in project coprhd-controller by CoprHD.
the class AbstractSecuredWebServer method initServer.
/**
* Initialize server handlers, rest resources.
*
* @throws Exception
*/
protected void initServer() throws Exception {
_server = new Server();
initThreadPool();
initConnectors();
// AuthN servlet filters
servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/");
_server.setHandler(servletHandler);
((AbstractSessionManager) servletHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
if (_disabler != null) {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_disablingFilter));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
_log.warn("security checks are disabled... skipped adding security filters");
} else {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
}
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
type.put("octet-stream", MediaType.APPLICATION_OCTET_STREAM_TYPE);
type.put("form-data", MediaType.MULTIPART_FORM_DATA_TYPE);
servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
// AuthZ resource filters
Map<String, Object> props = new HashMap<String, Object>();
props.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, _resourceFilterFactory);
// Adding the ContainerResponseFilter
props.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, _responseFilter);
config.setPropertiesAndFeatures(props);
}
if (_dbClient != null) {
// Otherwise there could be a dependency loop between services.
if (startDbClientInBackground) {
_log.info("starting dbclient in background");
new Thread() {
public void run() {
_dbClient.start();
}
}.start();
} else {
_log.info("starting dbclient");
_dbClient.start();
}
}
}
Aggregations