Search in sources :

Example 81 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project vespa by vespa-engine.

the class ConnectorFactory method newSslConnectionFactory.

private SslConnectionFactory newSslConnectionFactory() {
    Ssl sslConfig = connectorConfig.ssl();
    SslContextFactory factory = new JDiscSslContextFactory();
    sslKeyStoreConfigurator.configure(new DefaultSslKeyStoreContext(factory));
    sslTrustStoreConfigurator.configure(new DefaultSslTrustStoreContext(factory));
    switch(sslConfig.clientAuth()) {
        case NEED_AUTH:
            factory.setNeedClientAuth(true);
            break;
        case WANT_AUTH:
            factory.setWantClientAuth(true);
            break;
    }
    if (!sslConfig.prng().isEmpty()) {
        factory.setSecureRandomAlgorithm(sslConfig.prng());
    }
    setStringArrayParameter(factory, sslConfig.excludeProtocol(), ExcludeProtocol::name, SslContextFactory::setExcludeProtocols);
    setStringArrayParameter(factory, sslConfig.includeProtocol(), IncludeProtocol::name, SslContextFactory::setIncludeProtocols);
    setStringArrayParameter(factory, sslConfig.excludeCipherSuite(), ExcludeCipherSuite::name, SslContextFactory::setExcludeCipherSuites);
    setStringArrayParameter(factory, sslConfig.includeCipherSuite(), IncludeCipherSuite::name, SslContextFactory::setIncludeCipherSuites);
    factory.setKeyManagerFactoryAlgorithm(sslConfig.sslKeyManagerFactoryAlgorithm());
    factory.setProtocol(sslConfig.protocol());
    return new SslConnectionFactory(factory, HttpVersion.HTTP_1_1.asString());
}
Also used : ExcludeProtocol(com.yahoo.jdisc.http.ConnectorConfig.Ssl.ExcludeProtocol) DefaultSslTrustStoreContext(com.yahoo.jdisc.http.ssl.DefaultSslTrustStoreContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) DefaultSslKeyStoreContext(com.yahoo.jdisc.http.ssl.DefaultSslKeyStoreContext) IncludeProtocol(com.yahoo.jdisc.http.ConnectorConfig.Ssl.IncludeProtocol) IncludeCipherSuite(com.yahoo.jdisc.http.ConnectorConfig.Ssl.IncludeCipherSuite) ExcludeCipherSuite(com.yahoo.jdisc.http.ConnectorConfig.Ssl.ExcludeCipherSuite) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) Ssl(com.yahoo.jdisc.http.ConnectorConfig.Ssl)

Example 82 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project jackrabbit by apache.

the class WebDAVTestBase method setUp.

protected void setUp() throws Exception {
    super.setUp();
    File home = new File("target/jackrabbit-repository");
    if (!home.exists()) {
        home.mkdirs();
    }
    File config = new File(home, "repository.xml");
    if (!config.exists()) {
        createDefaultConfiguration(config);
    }
    File keystore = new File(home, KEYSTORE);
    if (!keystore.exists()) {
        createKeystore(keystore);
    }
    if (repoContext == null) {
        repoContext = RepositoryContext.create(RepositoryConfig.create(config.toURI(), home.getPath()));
    }
    if (server == null) {
        server = new Server();
        ServletHolder simple = new ServletHolder(new SimpleWebdavServlet() {

            private static final long serialVersionUID = 8638589328461138178L;

            public Repository getRepository() {
                return repoContext.getRepository();
            }
        });
        simple.setInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/config.xml");
        ServletHolder remoting = new ServletHolder(new JcrRemotingServlet() {

            private static final long serialVersionUID = -2969534124090379387L;

            public Repository getRepository() {
                return repoContext.getRepository();
            }
        });
        remoting.setInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/remoting");
        ServletContextHandler schandler = new ServletContextHandler(server, "/");
        schandler.addServlet(simple, SIMPLE_WEBDAV_SERVLET_PATH_MAPPING);
        schandler.addServlet(remoting, REMOTING_WEBDAV_SERVLET_PATH_MAPPING);
        schandler.setBaseResource(Resource.newClassPathResource("/"));
        server.setHandler(schandler);
    }
    if (httpConnector == null) {
        httpConnector = new ServerConnector(server);
        httpConnector.setHost("localhost");
        httpConnector.setPort(0);
        server.addConnector(httpConnector);
    }
    if (httpsConnector == null) {
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(keystore.getPath());
        sslContextFactory.setKeyStorePassword(KEYSTOREPW);
        sslContextFactory.setKeyManagerPassword(KEYSTOREPW);
        sslContextFactory.setTrustStorePath(keystore.getPath());
        sslContextFactory.setTrustStorePassword(KEYSTOREPW);
        SslConnectionFactory cfac = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
        httpsConnector = new ServerConnector(server, cfac, new HttpConnectionFactory(new HttpConfiguration()));
        httpsConnector.setHost("localhost");
        httpsConnector.setPort(0);
        server.addConnector(httpsConnector);
    }
    if (!server.isStarted()) {
        try {
            server.start();
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    this.uri = new URI("http", null, "localhost", httpConnector.getLocalPort(), "/default/", null, null);
    this.remotingUri = new URI("http", null, "localhost", httpConnector.getLocalPort(), REMOTING_PREFIX + "/", null, null);
    this.httpsUri = new URI("https", null, "localhost", httpsConnector.getLocalPort(), "/default/", null, null);
    this.root = this.uri.toASCIIString();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    // cm.setMaxTotal(100);
    HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("admin", "admin"));
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);
    // Add AuthCache to the execution context
    this.context = HttpClientContext.create();
    this.context.setCredentialsProvider(credsProvider);
    this.context.setAuthCache(authCache);
    this.client = HttpClients.custom().setConnectionManager(cm).build();
    super.setUp();
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SimpleWebdavServlet(org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet) HttpHost(org.apache.http.HttpHost) BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Repository(javax.jcr.Repository) AuthScope(org.apache.http.auth.AuthScope) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Example 83 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project cia by Hack23.

the class CitizenIntelligenceAgencyServer method init.

/**
 * Inits the.
 *
 * @throws Exception
 *             the exception
 */
public final void init() throws Exception {
    initialised = true;
    server = new Server();
    Security.addProvider(new BouncyCastleProvider());
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    final HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(28443);
    final HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStorePath("target/keystore.jks");
    sslContextFactory.setTrustStorePath("target/keystore.jks");
    sslContextFactory.setKeyStorePassword("changeit");
    sslContextFactory.setTrustStorePassword("changeit");
    sslContextFactory.setKeyManagerPassword("changeit");
    sslContextFactory.setCertAlias("jetty");
    sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
    sslContextFactory.setIncludeProtocols("TLSv1.2");
    final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
    sslConnector.setPort(PORT);
    server.setConnectors(new ServerConnector[] { sslConnector });
    final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
    handler.setExtraClasspath("target/classes");
    handler.setParentLoaderPriority(true);
    handler.setConfigurationDiscovered(true);
    handler.setClassLoader(Thread.currentThread().getContextClassLoader());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 84 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project winstone by jenkinsci.

the class Http2ConnectorFactory method start.

@Override
public boolean start(Map args, Server server) throws IOException {
    int listenPort = Option.HTTP2_PORT.get(args);
    String listenAddress = Option.HTTP2_LISTEN_ADDRESS.get(args);
    if (listenPort < 0) {
        // not running HTTP2 listener
        return false;
    }
    try {
        configureSsl(args, server);
        SslContextFactory sslContextFactory = getSSLContext(args);
        sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
        // HTTPS Configuration
        HttpConfiguration https_config = new HttpConfiguration();
        https_config.setSecureScheme("https");
        https_config.setSecurePort(listenPort);
        https_config.addCustomizer(new SecureRequestCustomizer());
        // HTTP/2 Connection Factory
        HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
        ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
        alpn.setDefaultProtocol("h2");
        // SSL Connection Factory
        SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
        // HTTP/2 Connector
        ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
        http2Connector.setPort(listenPort);
        http2Connector.setHost(listenAddress);
        server.addConnector(http2Connector);
        server.setDumpAfterStart(Boolean.getBoolean("dumpAfterStart"));
        ALPN.debug = Boolean.getBoolean("alpnDebug");
        return true;
    } catch (IllegalStateException e) {
        Logger.log(Logger.WARNING, Launcher.RESOURCES, "Http2ConnectorFactory.FailedStart.ALPN", e);
    }
    return false;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 85 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project nifi-minifi by apache.

the class JettyServer method main.

public static void main(String[] args) throws Exception {
    C2Properties properties = C2Properties.getInstance();
    final HandlerCollection handlers = new HandlerCollection();
    for (Path path : Files.list(Paths.get(C2_SERVER_HOME, "webapps")).collect(Collectors.toList())) {
        handlers.addHandler(loadWar(path.toFile(), "/c2", JettyServer.class.getClassLoader()));
    }
    Server server;
    int port = Integer.parseInt(properties.getProperty("minifi.c2.server.port", "10080"));
    if (properties.isSecure()) {
        SslContextFactory sslContextFactory = properties.getSslContextFactory();
        HttpConfiguration config = new HttpConfiguration();
        config.setSecureScheme("https");
        config.setSecurePort(port);
        config.addCustomizer(new SecureRequestCustomizer());
        server = new Server();
        ServerConnector serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
        serverConnector.setPort(port);
        server.addConnector(serverConnector);
    } else {
        server = new Server(port);
    }
    server.setHandler(handlers);
    server.start();
    // ensure everything started successfully
    for (Handler handler : server.getChildHandlers()) {
        // see if the handler is a web app
        if (handler instanceof WebAppContext) {
            WebAppContext context = (WebAppContext) handler;
            // cause it to be unavailable
            if (context.getUnavailableException() != null) {
                System.err.println("Failed to start web server: " + context.getUnavailableException().getMessage());
                System.err.println("Shutting down...");
                logger.warn("Failed to start web server... shutting down.", context.getUnavailableException());
                server.stop();
                System.exit(1);
            }
        }
    }
    server.dumpStdErr();
    server.join();
}
Also used : Path(java.nio.file.Path) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Handler(org.eclipse.jetty.server.Handler) C2Properties(org.apache.nifi.minifi.c2.api.properties.C2Properties) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Aggregations

SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)106 ServerConnector (org.eclipse.jetty.server.ServerConnector)101 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)96 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)90 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)87 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)82 Server (org.eclipse.jetty.server.Server)56 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)19 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)17 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)16 IOException (java.io.IOException)15 File (java.io.File)14 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)11 ServletException (javax.servlet.ServletException)10 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)10 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)9 Connector (org.eclipse.jetty.server.Connector)9 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)9 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)9 ArrayList (java.util.ArrayList)8