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);
}
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);
}
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());
}
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);
}
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;
}
Aggregations