use of org.eclipse.jetty.server.SslConnectionFactory in project vespa by vespa-engine.
the class ConnectorFactory method newSslConnectionFactory.
private SslConnectionFactory newSslConnectionFactory() {
Ssl sslConfig = connectorConfig.ssl();
SslContextFactory factory = new JDiscSslContextFactory();
sslKeyStoreConfigurator.configure(new DefaultSslKeyStoreContext(factory));
sslTrustStoreConfigurator.configure(new DefaultSslTrustStoreContext(factory));
switch(sslConfig.clientAuth()) {
case NEED_AUTH:
factory.setNeedClientAuth(true);
break;
case WANT_AUTH:
factory.setWantClientAuth(true);
break;
}
if (!sslConfig.prng().isEmpty()) {
factory.setSecureRandomAlgorithm(sslConfig.prng());
}
setStringArrayParameter(factory, sslConfig.excludeProtocol(), ExcludeProtocol::name, SslContextFactory::setExcludeProtocols);
setStringArrayParameter(factory, sslConfig.includeProtocol(), IncludeProtocol::name, SslContextFactory::setIncludeProtocols);
setStringArrayParameter(factory, sslConfig.excludeCipherSuite(), ExcludeCipherSuite::name, SslContextFactory::setExcludeCipherSuites);
setStringArrayParameter(factory, sslConfig.includeCipherSuite(), IncludeCipherSuite::name, SslContextFactory::setIncludeCipherSuites);
factory.setKeyManagerFactoryAlgorithm(sslConfig.sslKeyManagerFactoryAlgorithm());
factory.setProtocol(sslConfig.protocol());
return new SslConnectionFactory(factory, HttpVersion.HTTP_1_1.asString());
}
use of org.eclipse.jetty.server.SslConnectionFactory in project jackrabbit by apache.
the class WebDAVTestBase method setUp.
protected void setUp() throws Exception {
super.setUp();
File home = new File("target/jackrabbit-repository");
if (!home.exists()) {
home.mkdirs();
}
File config = new File(home, "repository.xml");
if (!config.exists()) {
createDefaultConfiguration(config);
}
File keystore = new File(home, KEYSTORE);
if (!keystore.exists()) {
createKeystore(keystore);
}
if (repoContext == null) {
repoContext = RepositoryContext.create(RepositoryConfig.create(config.toURI(), home.getPath()));
}
if (server == null) {
server = new Server();
ServletHolder simple = new ServletHolder(new SimpleWebdavServlet() {
private static final long serialVersionUID = 8638589328461138178L;
public Repository getRepository() {
return repoContext.getRepository();
}
});
simple.setInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/config.xml");
ServletHolder remoting = new ServletHolder(new JcrRemotingServlet() {
private static final long serialVersionUID = -2969534124090379387L;
public Repository getRepository() {
return repoContext.getRepository();
}
});
remoting.setInitParameter(JcrRemotingServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/remoting");
ServletContextHandler schandler = new ServletContextHandler(server, "/");
schandler.addServlet(simple, SIMPLE_WEBDAV_SERVLET_PATH_MAPPING);
schandler.addServlet(remoting, REMOTING_WEBDAV_SERVLET_PATH_MAPPING);
schandler.setBaseResource(Resource.newClassPathResource("/"));
server.setHandler(schandler);
}
if (httpConnector == null) {
httpConnector = new ServerConnector(server);
httpConnector.setHost("localhost");
httpConnector.setPort(0);
server.addConnector(httpConnector);
}
if (httpsConnector == null) {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystore.getPath());
sslContextFactory.setKeyStorePassword(KEYSTOREPW);
sslContextFactory.setKeyManagerPassword(KEYSTOREPW);
sslContextFactory.setTrustStorePath(keystore.getPath());
sslContextFactory.setTrustStorePassword(KEYSTOREPW);
SslConnectionFactory cfac = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
httpsConnector = new ServerConnector(server, cfac, new HttpConnectionFactory(new HttpConfiguration()));
httpsConnector.setHost("localhost");
httpsConnector.setPort(0);
server.addConnector(httpsConnector);
}
if (!server.isStarted()) {
try {
server.start();
} catch (Exception e) {
throw new RepositoryStubException(e);
}
}
this.uri = new URI("http", null, "localhost", httpConnector.getLocalPort(), "/default/", null, null);
this.remotingUri = new URI("http", null, "localhost", httpConnector.getLocalPort(), REMOTING_PREFIX + "/", null, null);
this.httpsUri = new URI("https", null, "localhost", httpsConnector.getLocalPort(), "/default/", null, null);
this.root = this.uri.toASCIIString();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// cm.setMaxTotal(100);
HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("admin", "admin"));
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
this.context = HttpClientContext.create();
this.context.setCredentialsProvider(credsProvider);
this.context.setAuthCache(authCache);
this.client = HttpClients.custom().setConnectionManager(cm).build();
super.setUp();
}
use of org.eclipse.jetty.server.SslConnectionFactory in project cia by Hack23.
the class CitizenIntelligenceAgencyServer method init.
/**
* Inits the.
*
* @throws Exception
* the exception
*/
public final void init() throws Exception {
initialised = true;
server = new Server();
Security.addProvider(new BouncyCastleProvider());
// Setup JMX
final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
final HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(28443);
final HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStoreType("JKS");
sslContextFactory.setKeyStorePath("target/keystore.jks");
sslContextFactory.setTrustStorePath("target/keystore.jks");
sslContextFactory.setKeyStorePassword("changeit");
sslContextFactory.setTrustStorePassword("changeit");
sslContextFactory.setKeyManagerPassword("changeit");
sslContextFactory.setCertAlias("jetty");
sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
sslContextFactory.setIncludeProtocols("TLSv1.2");
final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
sslConnector.setPort(PORT);
server.setConnectors(new ServerConnector[] { sslConnector });
final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
handler.setExtraClasspath("target/classes");
handler.setParentLoaderPriority(true);
handler.setConfigurationDiscovered(true);
handler.setClassLoader(Thread.currentThread().getContextClassLoader());
final HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
server.setHandler(handlers);
}
use of org.eclipse.jetty.server.SslConnectionFactory in project winstone by jenkinsci.
the class Http2ConnectorFactory method start.
@Override
public boolean start(Map args, Server server) throws IOException {
int listenPort = Option.HTTP2_PORT.get(args);
String listenAddress = Option.HTTP2_LISTEN_ADDRESS.get(args);
if (listenPort < 0) {
// not running HTTP2 listener
return false;
}
try {
configureSsl(args, server);
SslContextFactory sslContextFactory = getSSLContext(args);
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration();
https_config.setSecureScheme("https");
https_config.setSecurePort(listenPort);
https_config.addCustomizer(new SecureRequestCustomizer());
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol("h2");
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
// HTTP/2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
http2Connector.setPort(listenPort);
http2Connector.setHost(listenAddress);
server.addConnector(http2Connector);
server.setDumpAfterStart(Boolean.getBoolean("dumpAfterStart"));
ALPN.debug = Boolean.getBoolean("alpnDebug");
return true;
} catch (IllegalStateException e) {
Logger.log(Logger.WARNING, Launcher.RESOURCES, "Http2ConnectorFactory.FailedStart.ALPN", e);
}
return false;
}
use of org.eclipse.jetty.server.SslConnectionFactory in project nifi-minifi by apache.
the class JettyServer method main.
public static void main(String[] args) throws Exception {
C2Properties properties = C2Properties.getInstance();
final HandlerCollection handlers = new HandlerCollection();
for (Path path : Files.list(Paths.get(C2_SERVER_HOME, "webapps")).collect(Collectors.toList())) {
handlers.addHandler(loadWar(path.toFile(), "/c2", JettyServer.class.getClassLoader()));
}
Server server;
int port = Integer.parseInt(properties.getProperty("minifi.c2.server.port", "10080"));
if (properties.isSecure()) {
SslContextFactory sslContextFactory = properties.getSslContextFactory();
HttpConfiguration config = new HttpConfiguration();
config.setSecureScheme("https");
config.setSecurePort(port);
config.addCustomizer(new SecureRequestCustomizer());
server = new Server();
ServerConnector serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
serverConnector.setPort(port);
server.addConnector(serverConnector);
} else {
server = new Server(port);
}
server.setHandler(handlers);
server.start();
// ensure everything started successfully
for (Handler handler : server.getChildHandlers()) {
// see if the handler is a web app
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
// cause it to be unavailable
if (context.getUnavailableException() != null) {
System.err.println("Failed to start web server: " + context.getUnavailableException().getMessage());
System.err.println("Shutting down...");
logger.warn("Failed to start web server... shutting down.", context.getUnavailableException());
server.stop();
System.exit(1);
}
}
}
server.dumpStdErr();
server.join();
}
Aggregations