rsanchez
2014-10-23 c4d513ca26fe80946a5d90264de5d8e13e4ea974
securis/src/main/java/net/curisit/securis/SeCurisServer.java
....@@ -52,7 +52,7 @@
5252 private static final Logger CONSOLE = LogManager.getLogger("console");
5353
5454 private static final String PID_FILE = System.getProperty("user.home") + "/.SeCuris/securis-server.pid";
55
-
55
+
5656 private static Server server;
5757 private static Injector injector = null;
5858
....@@ -64,19 +64,15 @@
6464 CONSOLE.info("Execute SeCuris server using:");
6565 CONSOLE.info(" $ ./securis-server.sh {start|stop}");
6666 }
67
-
68
- private void testMail() {
69
-
70
- }
71
-
67
+
7268 public static void main(String[] args) throws Exception {
73
- String command;
69
+ String command;
7470 if (args.length > 0) {
7571 command = args[0].toLowerCase();
7672 } else {
7773 command = "start";
7874 }
79
-
75
+
8076 switch (command) {
8177 case "start":
8278 startServer();
....@@ -90,7 +86,7 @@
9086 System.exit(-1);
9187 }
9288 }
93
-
89
+
9490 private static void stopServer() {
9591 if (!new File(PID_FILE).exists()) {
9692 CONSOLE.error("SeCuris server is NOT running or PID file is missing");
....@@ -105,7 +101,7 @@
105101 LOG.error("Error getting SeCuris server process PID from file: {}", PID_FILE);
106102 }
107103 }
108
-
104
+
109105 private static void startServer() {
110106
111107 if (new File(PID_FILE).exists()) {
....@@ -116,20 +112,22 @@
116112 }
117113 System.exit(-2);
118114 }
119
-
115
+
120116 SecurisModule securisModule = new SecurisModule();
121117 JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
122118 Properties props = new Properties();
123119 props.put("javax.persistence.jdbc.password", securisModule.getPassword());
124120 props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
125
- //LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
121
+ // LOG.info("BD Url: {} {}",
122
+ // securisModule.getUrl(securisModule.getAppDir()),
123
+ // securisModule.getPassword());
126124 jpaPersistModule.properties(props);
127125
128126 injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
129127
130128 try {
131129 startServer(injector.getInstance(Key.get(URI.class, Names.named("base-uri"))));
132
-
130
+
133131 } catch (SeCurisException e) {
134132 CONSOLE.error("Error launching the SeCuris server, {}", e);
135133 }
....@@ -153,14 +151,14 @@
153151
154152 QueuedThreadPool threadPool = new QueuedThreadPool();
155153 threadPool.setMaxThreads(50);
156
-
154
+
157155 server = new Server();
158
-
156
+
159157 ServerConnector httpConnector = new ServerConnector(server);
160158 httpConnector.setPort(Config.getInt(Config.KEYS.SERVER_PORT, 9080));
161159 httpConnector.setHost(Config.get(Config.KEYS.SERVER_HOSTNAME, "0.0.0.0"));
162160 server.addConnector(httpConnector);
163
-
161
+
164162 ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
165163 context.setContextPath("/");
166164 context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
....@@ -191,33 +189,33 @@
191189 contexts.setHandlers(new Handler[] {
192190 staticResources, context
193191 });
194
-
192
+
195193 HttpConfiguration http_config = new HttpConfiguration();
196194 http_config.setSecureScheme("https");
197195 http_config.setSecurePort(Config.getInt(Config.KEYS.SERVER_SSL_PORT, 9443));
198196 http_config.setOutputBufferSize(32768);
199197 http_config.setSendServerVersion(true);
200198 http_config.setSendDateHeader(false);
201
-
202
-
199
+
203200 HttpConfiguration https_config = new HttpConfiguration(http_config);
204201 https_config.addCustomizer(new SecureRequestCustomizer());
205
-
202
+
206203 SslContextFactory sslContextFactory = new SslContextFactory();
207204 sslContextFactory.setKeyStorePath(Config.get(Config.KEYS.KEYSTORE_PATH));
208205 sslContextFactory.setKeyStoreType(Config.get(Config.KEYS.KEYSTORE_TYPE, "JKS"));
209206 sslContextFactory.setKeyStorePassword(Config.get(Config.KEYS.KEYSTORE_PASSWORD, ""));
210
- //sslContextFactory.setCertAlias("1");
211
-// sslContextFactory.setKeyManagerPassword("curist3c");
212
-// sslContextFactory.setTrustStorePath("/Users/rob/.ssh/keys/keystore");
213
-// sslContextFactory.setTrustStorePassword("curist3c");
207
+ // sslContextFactory.setCertAlias("1");
208
+ // sslContextFactory.setKeyManagerPassword("curist3c");
209
+ // sslContextFactory.setTrustStorePath("/Users/rob/.ssh/keys/keystore");
210
+ // sslContextFactory.setTrustStorePassword("curist3c");
214211 sslContextFactory.checkKeyStore();
215212 sslContextFactory.setNeedClientAuth(false);
216
-
217
- ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
213
+
214
+ ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
215
+ new HttpConnectionFactory(https_config));
218216 sslConnector.setPort(Config.getInt(Config.KEYS.SERVER_SSL_PORT, 9443));
219217 sslConnector.setHost(Config.get(Config.KEYS.SERVER_HOSTNAME, "0.0.0.0"));
220
- server.addConnector( sslConnector );
218
+ server.addConnector(sslConnector);
221219
222220 server.setHandler(context);
223221 server.setStopAtShutdown(true);
....@@ -233,9 +231,10 @@
233231 }
234232
235233 }
236
-
237
- static class ServerStoppedListener extends AbstractLifeCycleListener {
238
- @Override public void lifeCycleStopped(LifeCycle event) {
234
+
235
+ static class ServerStoppedListener extends AbstractLifeCycleListener {
236
+ @Override
237
+ public void lifeCycleStopped(LifeCycle event) {
239238 if (new File(PID_FILE).exists())
240239 new File(PID_FILE).delete();
241240 }