Search in sources :

Example 6 with SslSelectChannelConnector

use of org.eclipse.jetty.server.ssl.SslSelectChannelConnector in project coprhd-controller by CoprHD.

the class StorageApiWebServer method initServer.

private void initServer() {
    server = new Server();
    // Warn if there are any Ciphers that are not supported
    try {
        List<String> supportedCipherSuites = Lists.newArrayList(SSLContext.getDefault().getSocketFactory().getSupportedCipherSuites());
        for (String chosenCipher : ciphers) {
            if (!supportedCipherSuites.contains(chosenCipher)) {
                LOG.warn("Cipher Suite Not Supported:" + chosenCipher);
            }
        }
    } catch (NoSuchAlgorithmException e) {
        LOG.error("Error checking Cipher Suites", e);
    }
    SslContextFactory sslFac = new SslContextFactory();
    sslFac.setIncludeCipherSuites(ciphers);
    sslFac.setKeyStorePath(SystemProperties.resolve(KEYSTORE_PATH));
    sslFac.setKeyStorePassword(keystoreKey);
    SslSelectChannelConnector connector = new SslSelectChannelConnector(sslFac);
    connector.setPort(serviceInfo.getEndpoint().getPort());
    server.addConnector(connector);
    server.setSendServerVersion(false);
    WebAppContext context = new WebAppContext();
    context.setContextPath("/api");
    context.setWar(SystemProperties.resolve(WAR_PATH));
    server.setHandler(context);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector)

Example 7 with SslSelectChannelConnector

use of org.eclipse.jetty.server.ssl.SslSelectChannelConnector in project platformlayer by platformlayer.

the class StandaloneXaasWebserver method start.

public boolean start() throws Exception {
    LogbackHook.attachToRootLogger();
    this.server = new Server();
    {
        SslContextFactory sslContextFactory = new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
        {
            CertificateAndKey certificateAndKey = encryptionStore.getCertificateAndKey("https");
            String secret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
            KeyStore keystore = KeyStoreUtils.createEmpty(secret);
            String alias = "https";
            KeyStoreUtils.put(keystore, alias, certificateAndKey, secret);
            sslContextFactory.setKeyStore(keystore);
            sslContextFactory.setKeyStorePassword(secret);
            sslContextFactory.setCertAlias(alias);
        }
        // TODO: Preconfigure a better SSLContext??
        SSLContext sslContext = SSLContext.getDefault();
        sslContextFactory.setIncludeCipherSuites(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledCipherSuites());
        sslContextFactory.setIncludeProtocols(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledProtocols());
        SslSelectChannelConnector connector = new SslSelectChannelConnector(sslContextFactory);
        connector.setPort(PORT);
        String host = configuration.lookup("http.host", null);
        if (host != null) {
            connector.setHost(host);
        }
        server.setConnectors(new Connector[] { connector });
    }
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    {
        ServletContextHandler context = new ServletContextHandler(contexts, "/api");
        // context.setContextPath("/");
        context.addEventListener(guiceServletConfig);
        // Must add DefaultServlet for embedded Jetty
        // Failing to do this will cause 404 errors.
        context.addServlet(DefaultServlet.class, "/");
        FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
        context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
    }
    for (Entry<String, File> entry : wars.entrySet()) {
        String contextPath = entry.getKey();
        File war = entry.getValue();
        WebAppContext context = new WebAppContext();
        context.setWar(war.getAbsolutePath());
        context.setContextPath(contextPath);
        context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
        contexts.addHandler(context);
    }
    server.setHandler(contexts);
    server.addLifeCycleListener(new CloseOnFailLifecycleListener());
    server.start();
    if (!server.isStarted()) {
        return false;
    }
    if (configuration.lookup("jobrunner.enabled", true)) {
        scheduler.start();
        jobPoller.start();
    }
    return true;
}
Also used : SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) GuiceFilter(com.google.inject.servlet.GuiceFilter) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) CertificateAndKey(com.fathomdb.crypto.CertificateAndKey) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Aggregations

SslSelectChannelConnector (org.eclipse.jetty.server.ssl.SslSelectChannelConnector)7 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)7 Server (org.eclipse.jetty.server.Server)4 KeyStore (java.security.KeyStore)3 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)3 Connector (org.eclipse.jetty.server.Connector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 ServiceBindException (co.cask.cdap.common.ServiceBindException)1 ResolvingDiscoverable (co.cask.cdap.common.discovery.ResolvingDiscoverable)1 CertificateAndKey (com.fathomdb.crypto.CertificateAndKey)1 GuiceFilter (com.google.inject.servlet.GuiceFilter)1 File (java.io.File)1 BindException (java.net.BindException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 Discoverable (org.apache.twill.discovery.Discoverable)1 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)1