Search in sources :

Example 51 with SslConnectionFactory

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

the class SniSslConnectionFactoryTest method before.

@Before
public void before() throws Exception {
    String keystorePath = "src/test/resources/snikeystore";
    File keystoreFile = new File(keystorePath);
    if (!keystoreFile.exists())
        throw new FileNotFoundException(keystoreFile.getAbsolutePath());
    _server = new Server();
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    _https_config = new HttpConfiguration(http_config);
    _https_config.addCustomizer(new SecureRequestCustomizer());
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    ServerConnector https = _connector = new ServerConnector(_server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(_https_config));
    _server.addConnector(https);
    _server.setHandler(new AbstractHandler.ErrorDispatchHandler() {

        @Override
        protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) {
            baseRequest.setHandled(true);
            response.setStatus(200);
            response.setHeader("X-URL", request.getRequestURI());
            response.setHeader("X-HOST", request.getServerName());
        }
    });
    _server.start();
    _port = https.getLocalPort();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileNotFoundException(java.io.FileNotFoundException) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) File(java.io.File) Before(org.junit.Before)

Example 52 with SslConnectionFactory

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

the class SecuredRedirectHandlerTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    // Setup SSL
    File keystore = MavenTestingUtils.getTestResourceFile("keystore");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystore.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystore.getAbsolutePath());
    sslContextFactory.setTrustStorePassword("storepwd");
    server = new Server();
    int port = 32080;
    int securePort = 32443;
    // Setup HTTP Configuration
    HttpConfiguration httpConf = new HttpConfiguration();
    httpConf.setSecurePort(securePort);
    httpConf.setSecureScheme("https");
    ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConf));
    httpConnector.setName("unsecured");
    httpConnector.setPort(port);
    // Setup HTTPS Configuration
    HttpConfiguration httpsConf = new HttpConfiguration(httpConf);
    httpsConf.addCustomizer(new SecureRequestCustomizer());
    ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConf));
    httpsConnector.setName("secured");
    httpsConnector.setPort(securePort);
    // Add connectors
    server.setConnectors(new Connector[] { httpConnector, httpsConnector });
    // Wire up contexts
    String[] secureHosts = new String[] { "@secured" };
    ContextHandler test1Context = new ContextHandler();
    test1Context.setContextPath("/test1");
    test1Context.setHandler(new HelloHandler("Hello1"));
    test1Context.setVirtualHosts(secureHosts);
    ContextHandler test2Context = new ContextHandler();
    test2Context.setContextPath("/test2");
    test2Context.setHandler(new HelloHandler("Hello2"));
    test2Context.setVirtualHosts(secureHosts);
    ContextHandler rootContext = new ContextHandler();
    rootContext.setContextPath("/");
    rootContext.setHandler(new RootHandler("/test1", "/test2"));
    rootContext.setVirtualHosts(secureHosts);
    // Wire up context for unsecure handling to only
    // the named 'unsecured' connector
    ContextHandler redirectHandler = new ContextHandler();
    redirectHandler.setContextPath("/");
    redirectHandler.setHandler(new SecuredRedirectHandler());
    redirectHandler.setVirtualHosts(new String[] { "@unsecured" });
    // Establish all handlers that have a context
    ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
    contextHandlers.setHandlers(new Handler[] { redirectHandler, rootContext, test1Context, test2Context });
    // Create server level handler tree
    HandlerList handlers = new HandlerList();
    handlers.addHandler(contextHandlers);
    // round things out
    handlers.addHandler(new DefaultHandler());
    server.setHandler(handlers);
    server.start();
    // calculate serverUri
    String host = httpConnector.getHost();
    if (host == null) {
        host = "localhost";
    }
    serverHttpUri = new URI(String.format("http://%s:%d/", host, httpConnector.getLocalPort()));
    serverHttpsUri = new URI(String.format("https://%s:%d/", host, httpsConnector.getLocalPort()));
    origVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    origSsf = HttpsURLConnection.getDefaultSSLSocketFactory();
    HttpsURLConnection.setDefaultHostnameVerifier(new AllowAllVerifier());
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContextFactory.getSslContext().getSocketFactory());
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Matchers.containsString(org.hamcrest.Matchers.containsString) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) URI(java.net.URI) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 53 with SslConnectionFactory

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

the class SslContextFactoryReloadTest method start.

private void start(Handler handler) throws Exception {
    server = new Server();
    sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(KEYSTORE_1);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStoreProvider(null);
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 54 with SslConnectionFactory

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

the class TestTransparentProxyServer method main.

public static void main(String[] args) throws Exception {
    ((StdErrLog) Log.getLog()).setSource(false);
    String jetty_root = "../../..";
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(100);
    // Setup server
    Server server = new Server(threadPool);
    server.manage(threadPool);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
    // Common HTTP configuration
    HttpConfiguration config = new HttpConfiguration();
    config.setSecurePort(8443);
    config.addCustomizer(new ForwardedRequestCustomizer());
    config.setSendDateHeader(true);
    config.setSendServerVersion(true);
    // Http Connector
    HttpConnectionFactory http = new HttpConnectionFactory(config);
    ServerConnector httpConnector = new ServerConnector(server, http);
    httpConnector.setPort(8080);
    httpConnector.setIdleTimeout(30000);
    server.addConnector(httpConnector);
    // SSL configurations
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    // Handlers
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
    server.setHandler(handlers);
    // Setup proxy webapp
    WebAppContext webapp = new WebAppContext();
    webapp.setResourceBase("src/main/webapp");
    contexts.addHandler(webapp);
    // start server
    server.setStopAtShutdown(true);
    server.start();
    server.join();
}
Also used : StdErrLog(org.eclipse.jetty.util.log.StdErrLog) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) 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) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 55 with SslConnectionFactory

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

the class WordPressHTTP2FastCGIProxyServer method main.

public static void main(String[] args) throws Exception {
    int tlsPort = 8443;
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setEndpointIdentificationAlgorithm("");
    sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
    sslContextFactory.setTrustStorePassword("storepwd");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    Server server = new Server();
    // HTTP(S) Configuration
    HttpConfiguration config = new HttpConfiguration();
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(tlsPort);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    String root = "/home/simon/programs/wordpress-3.7.1";
    ServletContextHandler context = new ServletContextHandler(server, "/wp");
    context.setResourceBase(root);
    context.setWelcomeFiles(new String[] { "index.php" });
    // Serve static resources
    ServletHolder defaultServlet = new ServletHolder("default", DefaultServlet.class);
    context.addServlet(defaultServlet, "/");
    FilterHolder tryFilesFilter = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    //        tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path $path/index.php"); // Permalink /?p=123
    // Permalink /%year%/%monthnum%/%postname%
    tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path /index.php?p=$path");
    // FastCGI
    ServletHolder fcgiServlet = context.addServlet(FastCGIProxyServlet.class, "*.php");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
    fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
    fcgiServlet.setInitParameter("prefix", "/");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
    server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

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