Java 类org.eclipse.jetty.server.ssl.SslSelectChannelConnector 实例源码

项目:Wilma    文件:JettyServer.java   
/**
 * Configures and starts a new Jetty server instance.
 * This server is configured to answer incoming request in a dummy way.
 * @param server the server that should be started
 * @param httpPort the http server port
 * @param httpsPort the https server port
 * @param isPerfTest determines whether server is started in performance test mode or not
 * @throws Exception
 */
public void configureAndStart(final Server server, final Integer httpPort, final Integer httpsPort, final Boolean isPerfTest) {
    try {
        SelectChannelConnector httpConnector = createHttpConnector(httpPort);
        SslSelectChannelConnector sslConnector = createSslConnector(httpsPort);
        server.setConnectors(new Connector[]{httpConnector, sslConnector});
        if (isPerfTest) {
            server.setHandler(new PerformanceTestHandler());
        } else {
            server.setHandler(new CompositeHandler(new ExampleHandler(new InputStreamConverter()), new SequenceTestHandler(new InputStreamConverter()), new PerformanceTestHandler()));
        }
        startServer(server);
        server.join();
    } catch (Exception e) {
        throw new SystemException("server cannot be started", e);
    }
}
项目:Wilma    文件:JettyServer.java   
private SslSelectChannelConnector createSslConnector(final Integer port) {
    SslSelectChannelConnector sslConnector = createSslSelectChannelConnector();
    sslConnector.setPort(port);
    SslContextFactory cf = sslConnector.getSslContextFactory();
    cf.setKeyStorePath("certificate/wilmaKeystore.jks");
    cf.setKeyStorePassword("secret123");
    cf.setKeyManagerPassword("secret123");
    return sslConnector;
}
项目:activemq-apollo-java-port    文件:WsTransportServer.java   
private Connector resolveConnector(String scheme, Map<String, String> options) {
    if (isWebSocket(scheme)) {
        return new SelectChannelConnector();
    }else if (isSecureWebSocket(scheme)) {
        SSLContext context = resolveSslContext();
        SslSelectChannelConnector channelConnector = new SslSelectChannelConnector();
        SslContextFactory sslSettings = channelConnector.getSslContextFactory();
        sslSettings.setSslContext(context);
        if (options.containsKey("client_auth")) {
            String clientAuth = options.get("client_auth");
            if (clientAuth != null) {
                sslSettings.setWantClientAuth(true);
            }else if("want".equals(clientAuth)) {
                sslSettings.setWantClientAuth(true);
            }else if("need".equals(clientAuth)) {
                sslSettings.setNeedClientAuth(true);
            }else if("none".equals(clientAuth)) {
                // don't do anything? default to whatever jetty uses
            } else {
                LOG.warn("Invalid setting for the wss protocol 'client_auth' query option. Please set to one of: none, want, need");
            }

        }
        return channelConnector;

    }  else {
        throw new RuntimeException("Invalid bind protocol: " + scheme);
    }
}
项目:kc-rice    文件:TestClient1.java   
/**
   * Creates a Server that exposes the TestClient1 services via http and https
   *
   * @return the Server instance
   */
  @Override
  protected Server createServer() {

      // Need this CredentialsSourceFactory in our config to enable our test of basic auth
      // with our httpInvoker-echoServiceSecure

      registerTestCredentialsSourceFactory();

      ConfigConstants configConstants = new ConfigConstants();

      Server server = new Server();

      SelectChannelConnector connector0 = new SelectChannelConnector();
      connector0.setPort(configConstants.SERVER_HTTP_PORT);
      connector0.setMaxIdleTime(30000);
      connector0.setRequestHeaderSize(8192);

      SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();

      ssl_connector.setPort(configConstants.SERVER_HTTPS_PORT);
      SslContextFactory cf = ssl_connector.getSslContextFactory();
      cf.setKeyStore(configConstants.KEYSTORE_PATH);
      cf.setKeyStorePassword(configConstants.KEYSTORE_PASS);
      cf.setKeyManagerPassword(configConstants.KEYSTORE_PASS);

      server.setConnectors(new Connector[]{connector0, ssl_connector});

      URL webRoot = getClass().getClassLoader().getResource(configConstants.WEB_ROOT);
      String location = webRoot.getPath();

      LOG.debug("#####################################");
LOG.debug("#");
LOG.debug("#  Starting Client1 using following web root " + location);
LOG.debug("#");
LOG.debug("#####################################");

      WebAppContext context = new WebAppContext();
      context.setResourceBase(location);
      context.setContextPath(configConstants.CONTEXT);

      HandlerCollection handlers = new HandlerCollection();
      handlers.addHandler(context);
      server.setHandler(handlers);

      server.setDumpAfterStart(true);
      //server.setDumpBeforeStop(true);

      return server;
  }
项目:Wilma    文件:JettyServer.java   
SslSelectChannelConnector createSslSelectChannelConnector() {
    return new SslSelectChannelConnector();
}
项目:rice    文件:TestClient1.java   
/**
   * Creates a Server that exposes the TestClient1 services via http and https
   *
   * @return the Server instance
   */
  @Override
  protected Server createServer() {

      // Need this CredentialsSourceFactory in our config to enable our test of basic auth
      // with our httpInvoker-echoServiceSecure

      registerTestCredentialsSourceFactory();

      ConfigConstants configConstants = new ConfigConstants();

      Server server = new Server();

      SelectChannelConnector connector0 = new SelectChannelConnector();
      connector0.setPort(configConstants.SERVER_HTTP_PORT);
      connector0.setMaxIdleTime(30000);
      connector0.setRequestHeaderSize(8192);

      SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();

      ssl_connector.setPort(configConstants.SERVER_HTTPS_PORT);
      SslContextFactory cf = ssl_connector.getSslContextFactory();
      cf.setKeyStore(configConstants.KEYSTORE_PATH);
      cf.setKeyStorePassword(configConstants.KEYSTORE_PASS);
      cf.setKeyManagerPassword(configConstants.KEYSTORE_PASS);

      server.setConnectors(new Connector[]{connector0, ssl_connector});

      URL webRoot = getClass().getClassLoader().getResource(configConstants.WEB_ROOT);
      String location = webRoot.getPath();

      LOG.debug("#####################################");
LOG.debug("#");
LOG.debug("#  Starting Client1 using following web root " + location);
LOG.debug("#");
LOG.debug("#####################################");

      WebAppContext context = new WebAppContext();
      context.setResourceBase(location);
      context.setContextPath(configConstants.CONTEXT);

      HandlerCollection handlers = new HandlerCollection();
      handlers.addHandler(context);
      server.setHandler(handlers);

      server.setDumpAfterStart(true);
      //server.setDumpBeforeStop(true);

      return server;
  }
项目:incubator-blur    文件:JettyServer.java   
private void createServer() throws MalformedURLException {
    server = new Server(port);

    if (Boolean.parseBoolean(Config.getBlurConfig().get("blur.console.ssl.enable", "false"))) {
        SslContextFactory factory = new SslContextFactory(Boolean.parseBoolean(Config.getBlurConfig().get("blur.console.ssl.hostname.match", "true")));
        factory.setKeyStorePath(Config.getBlurConfig().get("blur.console.ssl.keystore.path"));
        factory.setKeyStorePassword(Config.getBlurConfig().get("blur.console.ssl.keystore.password"));
        factory.setTrustStore(Config.getBlurConfig().get("blur.console.ssl.truststore.path"));
        factory.setTrustStorePassword(Config.getBlurConfig().get("blur.console.ssl.truststore.password"));

        SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(factory);
        sslConnector.setPort(port);

        server.addConnector(sslConnector);
    }

    // for localhost:port/console/index.html and whatever else is in the webapp directory
    URL warUrl = null;
      if (devMode) {
          warUrl = new URL("file://" + new File(DEV_WEBAPPDIR).getAbsolutePath());
      } else {
          warUrl = this.getClass().getClassLoader().getResource(PROD_WEBAPPDIR);
      }
    String warUrlString = warUrl.toExternalForm();
    WebAppContext staticContext = new WebAppContext(warUrlString, CONTEXTPATH);
    staticContext.setSessionHandler(new SessionHandler());

    // service calls
//    ContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
//    servletContext.setContextPath("/console/service");
    ServletHandler serviceHandler = new ServletHandler();
    serviceHandler.addServletWithMapping(AuthServlet.class, "/service/auth/*");
    serviceHandler.addServletWithMapping(NodesServlet.class, "/service/nodes/*");
    serviceHandler.addServletWithMapping(TablesServlet.class, "/service/tables/*");
    serviceHandler.addServletWithMapping(QueriesServlet.class, "/service/queries/*");
    serviceHandler.addServletWithMapping(SearchServlet.class, "/service/search/*");
    serviceHandler.addServletWithMapping(JavascriptServlet.class, "/service/config.js");
    serviceHandler.addFilterWithMapping(LoggedInFilter.class, "/service/*", FilterMapping.REQUEST);
//    servletContext.setHandler(serviceHandler);
    staticContext.setServletHandler(serviceHandler);


//    ContextHandlerCollection handlers = new ContextHandlerCollection();
//    handlers.setHandlers(new Handler[] { /*servletContext,*/ staticContext  });

    server.setHandler(staticContext);
    System.out.println("started server on http://localhost:" + port + CONTEXTPATH);
    try {
      server.start();
      System.out.println(server.getHandlers()[0]);
    } catch (Exception e) {
      log.error("Error starting Blur Console Jetty Server.  Exiting", e);
      System.exit(1);
    }
  }
项目:openfire    文件:HttpBindManager.java   
private void createSSLConnector(int securePort) {
    httpsConnector = null;
    try {
        if (securePort > 0 && CertificateManager.isRSACertificate(SSLConfig.getKeyStore(), "*")) {
            if (!CertificateManager.isRSACertificate(SSLConfig.getKeyStore(),
                    XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
                Log.warn("HTTP binding: Using RSA certificates but they are not valid for " +
                        "the hosted domain");
            }

            final SslContextFactory sslContextFactory = new SslContextFactory(SSLConfig.getKeystoreLocation());
            sslContextFactory.setTrustStorePassword(SSLConfig.getc2sTrustPassword());
            sslContextFactory.setTrustStoreType(SSLConfig.getStoreType());
            sslContextFactory.setTrustStore(SSLConfig.getc2sTruststoreLocation());
            sslContextFactory.setKeyStorePassword(SSLConfig.getKeyPassword());
            sslContextFactory.setKeyStoreType(SSLConfig.getStoreType());

            // Set policy for checking client certificates
            String certPol = JiveGlobals.getProperty("xmpp.client.cert.policy", "disabled");
            if(certPol.equals("needed")) {                    
                sslContextFactory.setNeedClientAuth(true);
                sslContextFactory.setWantClientAuth(true);
            } else if(certPol.equals("wanted")) {
                sslContextFactory.setNeedClientAuth(false);
                sslContextFactory.setWantClientAuth(true);
            } else {
                sslContextFactory.setNeedClientAuth(false);
                sslContextFactory.setWantClientAuth(false);
            }

            final SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
            sslConnector.setHost(getBindInterface());
            sslConnector.setPort(securePort);
            configureProxiedConnector(sslConnector);
            httpsConnector = sslConnector;
        }
    }
    catch (Exception e) {
        Log.error("Error creating SSL connector for Http bind", e);
    }
}
项目:openfire-bespoke    文件:HttpBindManager.java   
private void createSSLConnector(int securePort) {
    httpsConnector = null;
    try {
        if (securePort > 0 && CertificateManager.isRSACertificate(SSLConfig.getKeyStore(), "*")) {
            if (!CertificateManager.isRSACertificate(SSLConfig.getKeyStore(),
                    XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
                Log.warn("HTTP binding: Using RSA certificates but they are not valid for " +
                        "the hosted domain");
            }

            final SslContextFactory sslContextFactory = new SslContextFactory(SSLConfig.getKeystoreLocation());
            sslContextFactory.setTrustStorePassword(SSLConfig.getc2sTrustPassword());
            sslContextFactory.setTrustStoreType(SSLConfig.getStoreType());
            sslContextFactory.setTrustStore(SSLConfig.getc2sTruststoreLocation());
            sslContextFactory.setKeyStorePassword(SSLConfig.getKeyPassword());
            sslContextFactory.setKeyStoreType(SSLConfig.getStoreType());

            // Set policy for checking client certificates
            String certPol = JiveGlobals.getProperty("xmpp.client.cert.policy", "disabled");
            if(certPol.equals("needed")) {                    
                sslContextFactory.setNeedClientAuth(true);
                sslContextFactory.setWantClientAuth(true);
            } else if(certPol.equals("wanted")) {
                sslContextFactory.setNeedClientAuth(false);
                sslContextFactory.setWantClientAuth(true);
            } else {
                sslContextFactory.setNeedClientAuth(false);
                sslContextFactory.setWantClientAuth(false);
            }

            final SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
            sslConnector.setHost(getBindInterface());
            sslConnector.setPort(securePort);

            httpsConnector = sslConnector;
        }
    }
    catch (Exception e) {
        Log.error("Error creating SSL connector for Http bind", e);
    }
}