Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpsServer


       
    }
   
    public HttpServer createHttpServerInstance(int port) throws IOException {
        try {
            HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
            server.setHttpsConfigurator (new HttpsConfigurator(sslContext) {
                @Override
                public void configure (HttpsParameters params) {

                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();
View Full Code Here


    }

    @Override
    public HttpServer createHttpServerInstance(int port) throws IOException {
        try {
            HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
            server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
                @Override
                public void configure(HttpsParameters params) {

                    // get the remote address if needed
                    InetSocketAddress remote = params.getClientAddress();
View Full Code Here

        httpExchange.getResponseBody().write(bytes);
        httpExchange.close();
    }

    public static HttpsServer createHttpsServer(int httpsProxyPort) throws Exception {
        HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(httpsProxyPort), 0);
        SSLContext sslContext = getSslContext();

        final SSLEngine m_engine = sslContext.createSSLEngine();

        httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
            public void configure(HttpsParameters params) {
                params.setCipherSuites(m_engine.getEnabledCipherSuites());
                params.setProtocols(m_engine.getEnabledProtocols());
            }
        });
        httpsServer.start();

        return httpsServer;
    }
View Full Code Here

    try {
      //*
      if (https)
        try {
          server = HttpsServer.create(new InetSocketAddress(port), 0);
          HttpsServer ss = (HttpsServer) server;

          // Получить экземпляр хранилища ключей.
          KeyStore keyStore = KeyStore.getInstance("JKS");
          FileInputStream fis = new FileInputStream(story_file);
          keyStore.load(fis, story_pwd);

          // Получить диспетчеры ключей базовой реализации для заданного хранилища ключей.
          KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
          keyManagerFactory.init(keyStore, key_pwd);
          KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();

          // Получить доверенные диспетчеры базовой реализации.
          TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
          trustManagerFactory.init(keyStore);
          TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
          // Получить защищенное случайное число.
          SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");

          // Создание SSL контекста
          SSLContext sslContext = SSLContext.getInstance("SSLv3");
          sslContext.init(keyManagers, trustManagers, secureRandom);

          sslp = sslContext.getSupportedSSLParameters();
          boolean needClientAuth = Strings.parseBoolean(cntx.getPrmNvl("needClientAuth", "false"));
          sslp.setNeedClientAuth(needClientAuth);
          boolean wantClientAuth = Strings.parseBoolean(cntx.getPrmNvl("wantClientAuth", "false"));
          sslp.setWantClientAuth(wantClientAuth);

          HttpsConfigurator conf = new HttpsConfigurator(sslContext) {
            public void configure(HttpsParameters params) {
              params.setSSLParameters(sslp);
            }
          };

          ss.setHttpsConfigurator(conf);
          System.setProperty("javax.net.ssl.trustStore", story_file);
          System.setProperty("javax.net.ssl.keyStore", story_file);
          String trustStore = System.getProperty("javax.net.ssl.trustStore");
          if (trustStore == null)
            System.out.println("javax.net.ssl.trustStore is not defined");
View Full Code Here

    try {
      // *
      if (https)
        try {
          server = HttpsServer.create(new InetSocketAddress(port), 0);
          HttpsServer ss = (HttpsServer) server;

          // Получить экземпляр хранилища ключей.
          KeyStore keyStore = KeyStore.getInstance("JKS");
          FileInputStream fis = new FileInputStream(story_file);
          keyStore.load(fis, story_pwd);

          // Получить диспетчеры ключей базовой реализации для
          // заданного хранилища ключей.
          KeyManagerFactory keyManagerFactory = KeyManagerFactory
              .getInstance("SunX509");
          keyManagerFactory.init(keyStore, key_pwd);
          KeyManager[] keyManagers = keyManagerFactory
              .getKeyManagers();

          // Получить доверенные диспетчеры базовой реализации.
          TrustManagerFactory trustManagerFactory = TrustManagerFactory
              .getInstance("SunX509");
          trustManagerFactory.init(keyStore);
          TrustManager[] trustManagers = trustManagerFactory
              .getTrustManagers();
          // Получить защищенное случайное число.
          SecureRandom secureRandom = SecureRandom.getInstance(
              "SHA1PRNG", "SUN");

          // Создание SSL контекста
          SSLContext sslContext = SSLContext.getInstance("SSLv3");
          sslContext.init(keyManagers, trustManagers, secureRandom);

          sslp = sslContext.getSupportedSSLParameters();
          boolean needClientAuth = Strings.parseBoolean(cntx
              .getPrmNvl("needClientAuth", "false"));
          sslp.setNeedClientAuth(needClientAuth);
          boolean wantClientAuth = Strings.parseBoolean(cntx
              .getPrmNvl("wantClientAuth", "false"));
          sslp.setWantClientAuth(wantClientAuth);

          HttpsConfigurator conf = new HttpsConfigurator(sslContext) {
            public void configure(HttpsParameters params) {
              params.setSSLParameters(sslp);
            }
          };

          ss.setHttpsConfigurator(conf);
          System.setProperty("javax.net.ssl.trustStore", story_file);
          System.setProperty("javax.net.ssl.keyStore", story_file);
          String trustStore = System
              .getProperty("javax.net.ssl.trustStore");
          if (trustStore == null)
View Full Code Here

        return wrapper;
    }

    private static HttpServer createHttpsServerWrapper(final HttpsServer delegate, final JdkHttpHandlerContainer handler) {
        return new HttpsServer() {

            @Override
            public void setHttpsConfigurator(final HttpsConfigurator httpsConfigurator) {
                delegate.setHttpsConfigurator(httpsConfigurator);
            }
View Full Code Here

      //Create the SSL context with keystore & truststore
      SSLContext ssl = SSLContext.getInstance("TLS");
      ssl.init(keyFactory.getKeyManagers(), trustFactory.getTrustManagers(), new SecureRandom());

      HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(HOSTNAME, 8443), 10);
      httpsServer.setHttpsConfigurator(new HttpsConfigurator(ssl) {

        public void configure(HttpsParameters params) {

          //require client authentication
          SSLParameters sslparams = getSSLContext().getDefaultSSLParameters();
          sslparams.setNeedClientAuth(true);
          params.setSSLParameters(sslparams);
        }
      });

      httpsServer.start();

      Endpoint endpoint = Endpoint.create(new BrownBagServiceImpl());

      endpoint.publish(httpsServer.createContext("/BrownBagService"));
    }
View Full Code Here

   
            
            InetSocketAddress address = new InetSocketAddress ( getProxyCallbackURLPrefix().getPort() );
   
            // initialise the HTTPS server
            HttpsServer httpsServer = HttpsServer.create ( address, 0 );
            SSLContext sslContext = SSLContext.getInstance ( "TLS" );
   
            // initialise the keystore
            char[] password = "changeit".toCharArray ();
            KeyStore ks = KeyStore.getInstance ( "JKS" );
            File base = new File(System.getProperty("user.home"), ".geoserver");
            File keystore = new File(base,"keystore.jks");
            FileInputStream fis = new FileInputStream ( keystore );
            ks.load ( fis, password );
   
            // setup the key manager factory
           
            KeyManagerFactory kmf = KeyManagerFactory.getInstance ( KeyManagerFactory.getDefaultAlgorithm() );
            kmf.init ( ks, password );
   
   
            // setup the trust manager factory
            //TrustManagerFactory tmf = TrustManagerFactory.getInstance ( TrustManagerFactory.getDefaultAlgorithm() );
            //tmf.init ( ks );
   
            // setup the HTTPS context and parameters
            sslContext.init ( kmf.getKeyManagers (), new TrustManager[]{trustManager}, null );
            httpsServer.setHttpsConfiguratornew HttpsConfigurator( sslContext )
            {
                public void configure ( HttpsParameters params )
                {
                    try
                    {
                        // initialise the SSL context
                        SSLContext c = SSLContext.getDefault ();
                        SSLEngine engine = c.createSSLEngine ();
                        params.setNeedClientAuth ( false );
                        params.setCipherSuites ( engine.getEnabledCipherSuites () );
                        params.setProtocols ( engine.getEnabledProtocols () );
   
                        // get the default parameters
                        SSLParameters defaultSSLParameters = c.getDefaultSSLParameters ();
                        params.setSSLParameters ( defaultSSLParameters );
                    }
                    catch ( Exception ex )
                    {
                        throw new RuntimeException(ex);
                    }
                }
            } );               
           
           
            httpsServer.createContext("/test", new HttpHandler() {           
                @Override
                public void handle(HttpExchange t) throws IOException {
                    LOGGER.info("https server working");
                    t.getRequestBody().close();                                                               
                    t.sendResponseHeaders(200, 0);
                    t.getResponseBody().close();
                }
            });
           
            httpsServer.setExecutor(null); // creates a default executor
            return httpsServer;
        }
View Full Code Here

            httpsServer = createAndStartHttpsServer();

    }

    protected HttpsServer createAndStartHttpsServer() throws Exception {
        HttpsServer httpsServer = ((LiveCasData) getTestData()).createSSLServer();
        URL callbackUrl = new URL(
                GeoServerCasConstants.createProxyCallBackURl(proxyCallbackUrlPrefix.toString()));
        httpsServer.createContext(callbackUrl.getPath(), new HttpsProxyCallBackHandler());

        httpsServer.createContext(createRequest("/j_spring_cas_security_check").getRequestURI(),
                new SingleSignOutHandler("/j_spring_cas_security_check"));
        httpsServer.createContext(createRequest("/wms").getRequestURI(), new SingleSignOutHandler(
                "/wms"));
        httpsServer.start();
        return httpsServer;
    }
View Full Code Here

            kmf.init(keyStore, password);
            TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
            tmf.init(keyStore);
            SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
            HttpsServer server = HttpsServer.create(new InetSocketAddress(portFlag.value(options)), 0);
            server.setHttpsConfigurator(new HttpsConfigurator(sslContext));
            return server;
        } else {
            return HttpServer.create(new InetSocketAddress(portFlag.value(options)), 0);
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpsServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.