Java Code Examples for org.eclipse.jetty.util.ssl.SslContextFactory#setKeyStoreResource()
The following examples show how to use
org.eclipse.jetty.util.ssl.SslContextFactory#setKeyStoreResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebServer.java From hop with Apache License 2.0 | 6 votes |
private ServerConnector getConnector() { if ( sslConfig != null ) { log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.SslModeUsing" ) ); SslConnectionFactory connector = new SslConnectionFactory(); SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStoreResource( new PathResource( new File( sslConfig.getKeyStore() ) ) ); contextFactory.setKeyStorePassword( sslConfig.getKeyStorePassword() ); contextFactory.setKeyManagerPassword( sslConfig.getKeyPassword() ); contextFactory.setKeyStoreType( sslConfig.getKeyStoreType() ); return new ServerConnector( server, connector ); } else { return new ServerConnector( server ); } }
Example 2
Source File: EventServer.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private SslConnectionFactory getSSLConnectionFactory() { Resource keyStoreResource = null; try { keyStoreResource = Resource.newClassPathResource("localhost"); System.out.println(keyStoreResource); } catch (Exception ex) { Logger.getLogger(EventServer.class.getName()).log(Level.SEVERE, null, ex); } SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(keyStoreResource); String secret = readresource(); sslContextFactory.setKeyStorePassword(Encrypt.getInstance().decrypt(secret)); sslContextFactory.setKeyManagerPassword(Encrypt.getInstance().decrypt(secret)); return new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()); }
Example 3
Source File: FakeGoServer.java From gocd with Apache License 2.0 | 5 votes |
private void start() throws Exception { server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias("cruise"); sslContextFactory.setKeyStoreResource(Resource.newClassPathResource("testdata/fake-server-keystore")); sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd"); ServerConnector secureConnnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(new HttpConfiguration()) ); server.addConnector(secureConnnector); WebAppContext wac = new WebAppContext(".", "/go"); ServletHolder holder = new ServletHolder(); holder.setServlet(new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.getOutputStream().println("Hello"); } }); wac.addServlet(holder, "/hello"); addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this); addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this); addFakeAgentBinaryServlet(wac, "/admin/agent-plugins.zip", TEST_AGENT_PLUGINS, this); addFakeAgentBinaryServlet(wac, "/admin/tfs-impl.jar", TEST_TFS_IMPL, this); addlatestAgentStatusCall(wac); addDefaultServlet(wac); server.setHandler(wac); server.setStopAtShutdown(true); server.start(); port = connector.getLocalPort(); securePort = secureConnnector.getLocalPort(); }
Example 4
Source File: Http2Server.java From http2-examples with Apache License 2.0 | 4 votes |
public static void main(String... args) throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.addServlet(new ServletHolder(new Servlet()), "/"); server.setHandler(context); // HTTP Configuration HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); // SSL Context Factory for HTTPS and HTTP/2 SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(newClassPathResource("keystore")); sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); // HTTPS Configuration HttpConfiguration https_config = new HttpConfiguration(http_config); https_config.addCustomizer(new SecureRequestCustomizer()); // HTTP/2 Connection Factory HTTP2ServerConnectionFactory h2 = new MyConnectionFactory(https_config); NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable(); 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(8443); server.addConnector(http2Connector); ALPN.debug=false; server.start(); server.join(); }
Example 5
Source File: Http2EchoServer.java From http2-examples with Apache License 2.0 | 4 votes |
public static void main(String... args) throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.addServlet(new ServletHolder(new PushEchoServlet()), "/"); server.setHandler(context); // HTTP Configuration HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); // SSL Context Factory for HTTPS and HTTP/2 SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(newClassPathResource("keystore")); sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); // HTTPS Configuration HttpConfiguration https_config = new HttpConfiguration(http_config); https_config.addCustomizer(new SecureRequestCustomizer()); // HTTP/2 Connection Factory HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config); NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable(); 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(8443); server.addConnector(http2Connector); ALPN.debug=false; server.start(); server.join(); }
Example 6
Source File: Http2Server.java From http2-examples with Apache License 2.0 | 4 votes |
public static void main(String... args) throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.addServlet(new ServletHolder(new Servlet()), "/"); server.setHandler(context); // HTTP Configuration HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); // SSL Context Factory for HTTPS and HTTP/2 SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(newClassPathResource("keystore")); sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); // HTTPS Configuration HttpConfiguration https_config = new HttpConfiguration(http_config); https_config.addCustomizer(new SecureRequestCustomizer()); // HTTP/2 Connection Factory HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config); NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable(); 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(8443); server.addConnector(http2Connector); ALPN.debug=false; server.start(); server.join(); }
Example 7
Source File: Start.java From etcd-viewer with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { int timeout = (int) Duration.ONE_HOUR.getMilliseconds(); System.setProperty(WICKET_CFG, CfgType.development.toString()); Server server = new Server(); ServerConnector connector = new ServerConnector(server); // Set some timeout options to make debugging easier. connector.setIdleTimeout(timeout); connector.setSoLingerTime(-1); connector.setPort(8080); server.addConnector(connector); Resource keystore = Resource.newClassPathResource("/keystore"); if (keystore != null && keystore.exists()) { // if a keystore for a SSL certificate is available, start a SSL // connector on port 8443. // By default, the quickstart comes with a Apache Wicket Quickstart // Certificate that expires about half way september 2021. Do not // use this certificate anywhere important as the passwords are // available in the source. SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(keystore); sslContextFactory.setKeyStorePassword("wicket"); sslContextFactory.setTrustStoreResource(keystore); sslContextFactory.setKeyManagerPassword("wicket"); // HTTP Configuration HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(8443); httpConfig.setOutputBufferSize(32768); httpConfig.setRequestHeaderSize(8192); httpConfig.setResponseHeaderSize(8192); httpConfig.setSendServerVersion(true); httpConfig.setSendDateHeader(false); // SSL HTTP Configuration HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); // SSL Connector ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig)); sslConnector.setPort(8443); server.addConnector(sslConnector); System.out.println("SSL access to the quickstart has been enabled on port 8443"); System.out.println("You can access the application using SSL on https://localhost:8443"); System.out.println(); } WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); // START JMX SERVER // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); // server.getContainer().addEventListener(mBeanContainer); // mBeanContainer.start(); server.setHandler(bb); try { System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP"); server.start(); System.in.read(); System.out.println(">>> STOPPING EMBEDDED JETTY SERVER"); server.stop(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
Example 8
Source File: Start.java From wicket-orientdb with Apache License 2.0 | 4 votes |
/** * Main function, starts the jetty server. * * @param args */ public static void main(String[] args) { System.setProperty("wicket.configuration", "development"); Server server = new Server(); HttpConfiguration http_config = new HttpConfiguration(); http_config.setSecureScheme("https"); http_config.setSecurePort(8443); http_config.setOutputBufferSize(32768); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(8080); http.setIdleTimeout(1000 * 60 * 60); server.addConnector(http); Resource keystore = Resource.newClassPathResource("/keystore"); if (keystore != null && keystore.exists()) { // if a keystore for a SSL certificate is available, start a SSL // connector on port 8443. // By default, the quickstart comes with a Apache Wicket Quickstart // Certificate that expires about half way september 2021. Do not // use this certificate anywhere important as the passwords are // available in the source. SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStoreResource(keystore); sslContextFactory.setKeyStorePassword("wicket"); sslContextFactory.setKeyManagerPassword("wicket"); HttpConfiguration https_config = new HttpConfiguration(http_config); https_config.addCustomizer(new SecureRequestCustomizer()); ServerConnector https = new ServerConnector(server, new SslConnectionFactory( sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config)); https.setPort(8443); https.setIdleTimeout(500000); server.addConnector(https); System.out.println("SSL access to the examples has been enabled on port 8443"); System.out .println("You can access the application using SSL on https://localhost:8443"); System.out.println(); } WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); // uncomment next line if you want to test with JSESSIONID encoded in the urls // ((AbstractSessionManager) // bb.getSessionHandler().getSessionManager()).setUsingCookies(false); server.setHandler(bb); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); server.addEventListener(mBeanContainer); server.addBean(mBeanContainer); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(100); } }