use of org.glassfish.grizzly.ssl.SSLContextConfigurator 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.SSLContextConfigurator 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.SSLContextConfigurator 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.SSLContextConfigurator in project ddf by codice.
the class SecureStubServer method getSslConfig.
private SSLContextConfigurator getSslConfig() throws IOException {
SSLContextConfigurator defaultConfig = SSLContextConfigurator.DEFAULT_CONFIG;
if (!defaultConfig.validateConfiguration(true)) {
String keystoreServer = createCertificateStore("keystore_server");
String truststoreServer = createCertificateStore("truststore_server");
defaultConfig.setKeyStoreFile(keystoreServer);
defaultConfig.setKeyStorePass("secret");
defaultConfig.setTrustStoreFile(truststoreServer);
defaultConfig.setTrustStorePass("secret");
}
return defaultConfig;
}
Aggregations