Search in sources :

Example 1 with SSLEngineConfigurator

use of org.glassfish.grizzly.ssl.SSLEngineConfigurator in project jersey by jersey.

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start() throws IOException {
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server keypair
    sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE);
    sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
    // contains client certificate
    sslContext.setTrustStoreFile(TRUSTORE_SERVER_FILE);
    sslContext.setTrustStorePass(TRUSTORE_SERVER_PWD);
    ResourceConfig rc = new ResourceConfig();
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 2 with SSLEngineConfigurator

use of org.glassfish.grizzly.ssl.SSLEngineConfigurator in project jersey by jersey.

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start(String keystore) throws IOException {
    final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
    final InputStream keyStore = Server.class.getResourceAsStream(keystore);
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server key pair
    sslContext.setKeyStoreBytes(ByteStreams.toByteArray(keyStore));
    sslContext.setKeyStorePass("asdfgh");
    // contains client certificate
    sslContext.setTrustStoreBytes(ByteStreams.toByteArray(trustStore));
    sslContext.setTrustStorePass("asdfgh");
    ResourceConfig rc = new ResourceConfig();
    rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InputStream(java.io.InputStream) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 3 with SSLEngineConfigurator

use of org.glassfish.grizzly.ssl.SSLEngineConfigurator in project graylog2-server by Graylog2.

the class JerseyService method startUpWeb.

private void startUpWeb() throws Exception {
    final String[] resources = new String[] { RESOURCE_PACKAGE_WEB };
    final SSLEngineConfigurator sslEngineConfigurator = configuration.isWebEnableTls() ? buildSslEngineConfigurator(configuration.getWebTlsCertFile(), configuration.getWebTlsKeyFile(), configuration.getWebTlsKeyPassword()) : null;
    final URI webListenUri = configuration.getWebListenUri();
    final URI listenUri = new URI(webListenUri.getScheme(), webListenUri.getUserInfo(), webListenUri.getHost(), webListenUri.getPort(), null, null, null);
    webHttpServer = setUp("web", listenUri, sslEngineConfigurator, configuration.getWebThreadPoolSize(), configuration.getWebSelectorRunnersCount(), configuration.getWebMaxInitialLineLength(), configuration.getWebMaxHeaderSize(), configuration.isWebEnableGzip(), configuration.isWebEnableCors(), Collections.emptySet(), resources);
    webHttpServer.start();
    LOG.info("Started Web Interface at <{}>", configuration.getWebListenUri());
}
Also used : SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) URI(java.net.URI)

Example 4 with SSLEngineConfigurator

use of org.glassfish.grizzly.ssl.SSLEngineConfigurator in project graylog2-server by Graylog2.

the class JerseyService method buildSslEngineConfigurator.

private SSLEngineConfigurator buildSslEngineConfigurator(Path certFile, Path keyFile, String keyPassword) throws GeneralSecurityException, IOException {
    if (keyFile == null || !Files.isRegularFile(keyFile) || !Files.isReadable(keyFile)) {
        throw new InvalidKeyException("Unreadable or missing private key: " + keyFile);
    }
    if (certFile == null || !Files.isRegularFile(certFile) || !Files.isReadable(certFile)) {
        throw new CertificateException("Unreadable or missing X.509 certificate: " + certFile);
    }
    final SSLContextConfigurator sslContext = new SSLContextConfigurator();
    final char[] password = firstNonNull(keyPassword, "").toCharArray();
    final KeyStore keyStore = PemKeyStore.buildKeyStore(certFile, keyFile, password);
    sslContext.setKeyStorePass(password);
    sslContext.setKeyStoreBytes(KeyStoreUtils.getBytes(keyStore, password));
    if (!sslContext.validateConfiguration(true)) {
        throw new IllegalStateException("Couldn't initialize SSL context for HTTP server");
    }
    return new SSLEngineConfigurator(sslContext.createSSLContext(false), false, false, false);
}
Also used : SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) CertificateException(java.security.cert.CertificateException) InvalidKeyException(java.security.InvalidKeyException) KeyStore(java.security.KeyStore) PemKeyStore(org.graylog2.shared.security.tls.PemKeyStore) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 5 with SSLEngineConfigurator

use of org.glassfish.grizzly.ssl.SSLEngineConfigurator in project ddf by codice.

the class SecureStubServer method run.

/**
     * Starts the server
     */
public SecureStubServer run() {
    simpleServer.getServerConfiguration().addHttpHandler(stubsToHandler(), "/");
    try {
        if (secured) {
            for (NetworkListener networkListener : simpleServer.getListeners()) {
                networkListener.setSecure(true);
                SSLEngineConfigurator sslEngineConfig = new SSLEngineConfigurator(getSslConfig(), false, false, false);
                networkListener.setSSLEngineConfig(sslEngineConfig);
            }
        }
        simpleServer.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return this;
}
Also used : SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener)

Aggregations

SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)6 SSLContextConfigurator (org.glassfish.grizzly.ssl.SSLContextConfigurator)3 URI (java.net.URI)2 HttpServer (org.glassfish.grizzly.http.server.HttpServer)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyStore (java.security.KeyStore)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1 Resource (org.glassfish.jersey.server.model.Resource)1 PluginRestResource (org.graylog2.plugin.rest.PluginRestResource)1 PemKeyStore (org.graylog2.shared.security.tls.PemKeyStore)1