Пример #1
0
  private static void initSSL(
      Server server,
      int sslport,
      String keystore,
      String password,
      String keyPassword,
      boolean needClientAuth) {

    if (keystore == null) {
      throw new IllegalStateException(
          "you need to provide argument -Drjrkeystore with -Drjrsslport");
    }
    if (password == null) {
      throw new IllegalStateException(
          "you need to provide argument -Drjrpassword with -Drjrsslport");
    }
    if (keyPassword == null) {
      throw new IllegalStateException(
          "you need to provide argument -Drjrkeypassword with -Drjrsslport");
    }

    SslSocketConnector sslConnector = new SslSocketConnector();
    sslConnector.setKeystore(keystore);
    sslConnector.setPassword(password);
    sslConnector.setKeyPassword(keyPassword);

    if (needClientAuth) {
      System.err.println("Enable NeedClientAuth.");
      sslConnector.setNeedClientAuth(needClientAuth);
    }
    sslConnector.setMaxIdleTime(30000);
    sslConnector.setPort(sslport);

    server.addConnector(sslConnector);
  }
 private static SslSocketConnector getSslConnector(int port) {
   SslSocketConnector sslConnector = new SslSocketConnector();
   sslConnector.setKeystore(resourceBase + "/keystore");
   sslConnector.setKeyPassword("pulkkisenjorma");
   sslConnector.setPort(port);
   sslConnector.setMaxIdleTime(30000);
   return sslConnector;
 }
Пример #3
0
  public static void main(String[] args) throws Exception {
    ApplicationProperties properties = new ApplicationProperties();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);

    int port = Integer.getInteger("jetty.port", properties.getHttpPort());
    connector.setPort(port);

    SslSocketConnector sslConnector = new SslSocketConnector();
    sslConnector.setMaxIdleTime(1000 * 60 * 60);
    sslConnector.setSoLingerTime(-1);
    sslConnector.setKeyPassword("password");
    sslConnector.setPassword("password");
    sslConnector.setKeystore("src/main/webapp/WEB-INF/keystore");

    port = Integer.getInteger("jetty.sslport", properties.getHttpsPort());
    sslConnector.setPort(port);

    server.setConnectors(new Connector[] {connector, sslConnector});

    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.addHandler(bb);

    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      while (System.in.available() == 0) {
        Thread.sleep(5000);
      }
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
Пример #4
0
  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());
    }
  }
Пример #5
0
  private void deployWebApp() {
    try {
      Server server = new Server();
      SelectChannelConnector connector = new SelectChannelConnector();
      connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
      connector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
      connector.setHost(getHost());
      connector.setPort(getPort());
      if (isHttpsEnabled()) {
        connector.setConfidentialPort(getHttpsPort());
      }
      server.addConnector(connector);

      if (isHttpsEnabled()) {
        SslSocketConnector sslConnector = new SslSocketConnector();
        sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
        sslConnector.setHost(getHost());
        sslConnector.setPort(getHttpsPort());
        sslConnector.setKeystore(
            System.getProperty(
                "subsonic.ssl.keystore",
                getClass().getResource("/subsonic.keystore").toExternalForm()));
        sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
        server.addConnector(sslConnector);
      }

      WebAppContext context = new WebAppContext();
      context.setTempDirectory(getJettyDirectory());
      context.setContextPath(getContextPath());
      context.setWar(getWar());
      context.setOverrideDescriptor("/web-jetty.xml");

      if (isHttpsEnabled()) {

        // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
        context
            .getSecurityHandler()
            .setConstraintMappings(
                new ConstraintMapping[] {
                  createConstraintMapping("/stream", Constraint.DC_NONE),
                  createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
                  createConstraintMapping("/ws/*", Constraint.DC_NONE),
                  createConstraintMapping("/sonos/*", Constraint.DC_NONE),
                  createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
                });
      }

      server.addHandler(context);
      server.start();

      System.err.println("Subsonic running on: " + getUrl());
      if (isHttpsEnabled()) {
        System.err.println("                and: " + getHttpsUrl());
      }

    } catch (Throwable x) {
      x.printStackTrace();
      exception = x;
    }
  }