Search in sources :

Example 1 with ResourceConfig

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();
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) AbstractSecuredWebServer(com.emc.storageos.security.AbstractSecuredWebServer) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DelegatingFilterProxy(org.springframework.web.filter.DelegatingFilterProxy) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 2 with ResourceConfig

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)), "/*");
    }
}
Also used : Server(org.eclipse.jetty.server.Server) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Example 3 with ResourceConfig

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);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) URI(java.net.URI) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter)

Example 4 with ResourceConfig

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());
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 5 with ResourceConfig

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();
        }
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DelegatingFilterProxy(org.springframework.web.filter.DelegatingFilterProxy) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) MediaType(javax.ws.rs.core.MediaType) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

Aggregations

ResourceConfig (com.sun.jersey.api.core.ResourceConfig)8 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)6 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 Server (org.eclipse.jetty.server.Server)5 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 DefaultResourceConfig (com.sun.jersey.api.core.DefaultResourceConfig)4 MediaType (javax.ws.rs.core.MediaType)3 ApplicationAdapter (com.sun.jersey.api.core.ApplicationAdapter)2 IoCComponentProviderFactory (com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory)2 IOException (java.io.IOException)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 DispatcherType (javax.servlet.DispatcherType)2 AbstractSessionManager (org.eclipse.jetty.server.session.AbstractSessionManager)2 AnnisRunnerException (annis.AnnisRunnerException)1 MultipleIniWebEnvironment (annis.security.MultipleIniWebEnvironment)1 StorageApplication (com.emc.storageos.api.service.impl.resource.StorageApplication)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 AbstractSecuredWebServer (com.emc.storageos.security.AbstractSecuredWebServer)1 ServiceCodeExceptionMapper (com.emc.storageos.svcs.errorhandling.mappers.ServiceCodeExceptionMapper)1