- private static SslConnectionFactory createConnectionFactory(GigiConfig conf) throws GeneralSecurityException, IOException {
- final SslContextFactory sslContextFactory = generateSSLContextFactory(conf, "www");
- final SslContextFactory secureContextFactory = generateSSLContextFactory(conf, "secure");
- secureContextFactory.setWantClientAuth(true);
- secureContextFactory.setNeedClientAuth(false);
- final SslContextFactory staticContextFactory = generateSSLContextFactory(conf, "static");
- final SslContextFactory apiContextFactory = generateSSLContextFactory(conf, "api");
- try {
- secureContextFactory.start();
- staticContextFactory.start();
- apiContextFactory.start();
- } catch (Exception e) {
- e.printStackTrace();
+ private HttpConfiguration createHttpConfiguration() {
+ // SSL HTTP Configuration
+ HttpConfiguration httpsConfig = new HttpConfiguration();
+ httpsConfig.setSendServerVersion(false);
+ httpsConfig.setSendXPoweredBy(false);
+ return httpsConfig;
+ }
+
+ private void initConnectors() throws GeneralSecurityException, IOException {
+ HttpConfiguration httpConfig = createHttpConfiguration();
+ if (conf.getMainProps().getProperty("proxy", "false").equals("true")) {
+ httpConfig.addCustomizer(new ExtendedForwarded());
+ s.setConnectors(new Connector[] {
+ ConnectorsLauncher.createConnector(conf, s, httpConfig, false)
+ });
+ } else {
+ HttpConfiguration httpsConfig = createHttpConfiguration();
+ // for client-cert auth
+ httpsConfig.addCustomizer(new SecureRequestCustomizer());
+ s.setConnectors(new Connector[] {
+ ConnectorsLauncher.createConnector(conf, s, httpsConfig, true), ConnectorsLauncher.createConnector(conf, s, httpConfig, false)
+ });
+ }
+ }
+
+ private void initEmails(GigiConfig conf) throws GeneralSecurityException, IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
+ KeyStore privateStore = conf.getPrivateStore();
+ Certificate mail = null;
+ Key k = null;
+ if (privateStore != null && privateStore.containsAlias("mail")) {
+ mail = privateStore.getCertificate("mail");
+ k = privateStore.getKey("mail", conf.getPrivateStorePw().toCharArray());
+ }
+ EmailProvider.initSystem(conf.getMainProps(), mail, k);
+ }
+
+ private static class ConnectorsLauncher {
+
+ private ConnectorsLauncher() {}
+
+ protected static ServerConnector createConnector(GigiConfig conf, Server s, HttpConfiguration httpConfig, boolean doHttps) throws GeneralSecurityException, IOException {
+ ServerConnector connector;
+ if (doHttps) {
+ connector = new ServerConnector(s, createConnectionFactory(conf), new HttpConnectionFactory(httpConfig));
+ } else {
+ connector = new ServerConnector(s, new HttpConnectionFactory(httpConfig));
+ }
+ connector.setHost(conf.getMainProps().getProperty("host"));
+ if (doHttps) {
+ connector.setPort(ServerConstants.getSecurePort());
+ } else {
+ connector.setPort(ServerConstants.getPort());
+ }
+ connector.setAcceptQueueSize(100);
+ return connector;