protected void configureConnectors() { if (server != null) { if (_useNIO) { SelectChannelConnector nioConnector = new SelectChannelConnector(); nioConnector.setUseDirectBuffers(false); nioConnector.setPort(_port); server.addConnector(nioConnector); } else { SocketConnector bioConnector = new SocketConnector(); bioConnector.setPort(_port); bioConnector.setMaxIdleTime(3000); server.addConnector(bioConnector); } if (_useSSL) { SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setPort(_sslPort); // sslConnector.setKeystore("/sdcard/jetty/etc/keystore"); sslConnector.setKeystore(_keystoreFile); sslConnector.setKeystoreType("bks"); // sslConnector.setTruststore("/sdcard/jetty/etc/keystore"); sslConnector.setTruststore(_truststoreFile); // sslConnector.setPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslConnector.setPassword(_keystorePassword); // sslConnector.setKeyPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); sslConnector.setKeyPassword(_keymgrPassword); // sslConnector.setTrustPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslConnector.setTrustPassword(_truststorePassword); sslConnector.setTruststoreType("bks"); server.addConnector(sslConnector); } } }
public EmbeddedWebServer(String host, int port) { server = new Server(); handler = new ContextHandlerCollection(); root = new Context(handler, "/", new SessionHandler(), null, null, null); if (EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE)) || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS)) || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE)) || EMPTY.equals( Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS))) { sock = new SocketConnector(); usingSsl = false; } else { sock = new SslSocketConnector(); ((SslSocketConnector) sock) .setKeystore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE)); ((SslSocketConnector) sock) .setKeyPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS)); ((SslSocketConnector) sock) .setTruststore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE)); ((SslSocketConnector) sock) .setTrustPassword( Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS)); usingSsl = true; } sock.setHost(host); sock.setPort(port); }
private static SslSocketConnector createSslConnector() { SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setPort(sslPort); sslConnector.setKeyPassword("secret"); sslConnector.setKeystore("src/test/resources/keystore"); sslConnector.setTrustPassword("secret"); sslConnector.setTruststore("src/main/resources/truststore"); sslConnector.setPassword("secret"); sslConnector.setWantClientAuth(true); // sslConnector.setNeedClientAuth(true); return sslConnector; }
public void start(SoapMonitor soapMonitor, int localPort) { Settings settings = soapMonitor.getProject().getSettings(); server.setThreadPool(new SoapUIJettyThreadPool()); Context context = new Context(server, ROOT, 0); if (sslEndpoint != null) { if (sslEndpoint.startsWith(HTTPS)) { sslConnector = new SslSocketConnector(); sslConnector.setKeystore( settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_KEYSTORE, "JKS")); sslConnector.setPassword( settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_PASSWORD, "")); sslConnector.setKeyPassword( settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_KEYPASSWORD, "")); sslConnector.setTruststore( settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_TRUSTSTORE, "JKS")); sslConnector.setTrustPassword( settings.getString( SoapMonitorAction.SecurityTabForm.SSLTUNNEL_TRUSTSTORE_PASSWORD, "")); sslConnector.setNeedClientAuth(false); sslConnector.setMaxIdleTime(30000); sslConnector.setPort(localPort); server.addConnector(sslConnector); context.addServlet(new ServletHolder(new TunnelServlet(soapMonitor, sslEndpoint)), ROOT); } else { if (sslEndpoint.startsWith(HTTP)) { connector.setPort(localPort); server.addConnector(connector); context.addServlet(new ServletHolder(new TunnelServlet(soapMonitor, sslEndpoint)), ROOT); } else { UISupport.showErrorMessage("Unsupported/unknown protocol tunnel will not start"); return; } } proxyOrTunnel = false; } else { proxyOrTunnel = true; connector.setPort(localPort); server.addConnector(connector); context.addServlet(new ServletHolder(new ProxyServlet(soapMonitor)), ROOT); } try { server.start(); } catch (Exception e) { UISupport.showErrorMessage("Error starting monitor: " + e.getMessage()); } }
/** * Method to start the Jetty server * * @param jobDataMap */ private void startServer(JobDataMap jobDataMap) { if (LOG.isDebugEnabled()) { LOG.debug("Initialising HTTP server"); } int port = Integer.parseInt(jobDataMap.getString("port")); String bindAddress = jobDataMap.getString("bindAddress"); String authConfigFile = jobDataMap.getString("authConfigFile"); String keystore = jobDataMap.getString("keystore"); Server server = new Server(); if (keystore == null || keystore.equals("")) { LOG.info("Starting with HTTP (non-encrypted) protocol"); SelectChannelConnector connector = new SelectChannelConnector(); connector.setHost(bindAddress); connector.setPort(port); server.addConnector(connector); } else { LOG.info("Starting with HTTPS (encrypted) protocol"); SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setHost(bindAddress); sslConnector.setPort(port); sslConnector.setKeystore(jobDataMap.getString("keystore")); sslConnector.setKeyPassword(jobDataMap.getString("keyPassword")); sslConnector.setTruststore(jobDataMap.getString("trustStore")); sslConnector.setTrustPassword(jobDataMap.getString("trustPassword")); sslConnector.setPassword(jobDataMap.getString("password")); server.addConnector(sslConnector); } if (authConfigFile != null && !(authConfigFile.equals(""))) { if (LOG.isDebugEnabled()) { LOG.debug("Requiring basic auth"); } Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); ; constraint.setRoles(new String[] {"user", "grouper"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); SecurityHandler sh = new SecurityHandler(); try { sh.setUserRealm(new HashUserRealm("Grouper", authConfigFile)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } sh.setConstraintMappings(new ConstraintMapping[] {cm}); Handler[] handlers = new Handler[] {sh, new EsbHttpHandler()}; server.setHandlers(handlers); } else { if (LOG.isDebugEnabled()) { LOG.debug("Not requiring basic auth"); } server.setHandler(new EsbHttpHandler()); } try { server.start(); LOG.info("HTTP server started on address " + bindAddress + " port " + port); server.join(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { SocketConnector socketConnector = new SocketConnector(); socketConnector.setPort(6080); SslSocketConnector sslSocketConnector = new SslSocketConnector(); sslSocketConnector.setPort(6443); // sslSocketConnector.setNeedClientAuth(true); //why not use mutual authentication when // we can String serverKeystore = MockHttpListenerWithAuthentication.class .getClassLoader() .getResource("cert/serverkeystore.jks") .getPath(); sslSocketConnector.setKeystore(serverKeystore); sslSocketConnector.setKeyPassword("serverpass"); String serverTruststore = MockHttpListenerWithAuthentication.class .getClassLoader() .getResource("cert/servertruststore.jks") .getPath(); sslSocketConnector.setTruststore(serverTruststore); sslSocketConnector.setTrustPassword("serverpass"); server.addConnector(socketConnector); server.addConnector(sslSocketConnector); SecurityHandler securityHandler = createBasicAuthenticationSecurityHandler(); HandlerList handlerList = new HandlerList(); handlerList.addHandler(securityHandler); handlerList.addHandler( new AbstractHandler() { @Override public void handle( String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, int i) throws IOException, ServletException { System.out.println("uri: " + httpServletRequest.getRequestURI()); System.out.println("queryString: " + httpServletRequest.getQueryString()); System.out.println("method: " + httpServletRequest.getMethod()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(httpServletRequest.getInputStream(), baos); System.out.println("body: " + baos.toString()); PrintWriter writer = httpServletResponse.getWriter(); writer.append("testsvar"); Random r = new Random(); for (int j = 0; j < 10; j++) { int value = r.nextInt(Integer.MAX_VALUE); writer.append(value + ""); } System.out.println(); writer.close(); httpServletResponse.setStatus(HttpServletResponse.SC_OK); } }); server.addHandler(handlerList); server.start(); }