| .. | .. |
|---|
| 52 | 52 | private static final Logger CONSOLE = LogManager.getLogger("console");
|
|---|
| 53 | 53 |
|
|---|
| 54 | 54 | private static final String PID_FILE = System.getProperty("user.home") + "/.SeCuris/securis-server.pid";
|
|---|
| 55 | | -
|
|---|
| 55 | +
|
|---|
| 56 | 56 | private static Server server;
|
|---|
| 57 | 57 | private static Injector injector = null;
|
|---|
| 58 | 58 |
|
|---|
| .. | .. |
|---|
| 64 | 64 | CONSOLE.info("Execute SeCuris server using:");
|
|---|
| 65 | 65 | CONSOLE.info(" $ ./securis-server.sh {start|stop}");
|
|---|
| 66 | 66 | }
|
|---|
| 67 | | -
|
|---|
| 68 | | - private void testMail() {
|
|---|
| 69 | | -
|
|---|
| 70 | | - }
|
|---|
| 71 | | -
|
|---|
| 67 | +
|
|---|
| 72 | 68 | public static void main(String[] args) throws Exception {
|
|---|
| 73 | | - String command;
|
|---|
| 69 | + String command;
|
|---|
| 74 | 70 | if (args.length > 0) {
|
|---|
| 75 | 71 | command = args[0].toLowerCase();
|
|---|
| 76 | 72 | } else {
|
|---|
| 77 | 73 | command = "start";
|
|---|
| 78 | 74 | }
|
|---|
| 79 | | -
|
|---|
| 75 | +
|
|---|
| 80 | 76 | switch (command) {
|
|---|
| 81 | 77 | case "start":
|
|---|
| 82 | 78 | startServer();
|
|---|
| .. | .. |
|---|
| 90 | 86 | System.exit(-1);
|
|---|
| 91 | 87 | }
|
|---|
| 92 | 88 | }
|
|---|
| 93 | | -
|
|---|
| 89 | +
|
|---|
| 94 | 90 | private static void stopServer() {
|
|---|
| 95 | 91 | if (!new File(PID_FILE).exists()) {
|
|---|
| 96 | 92 | CONSOLE.error("SeCuris server is NOT running or PID file is missing");
|
|---|
| .. | .. |
|---|
| 105 | 101 | LOG.error("Error getting SeCuris server process PID from file: {}", PID_FILE);
|
|---|
| 106 | 102 | }
|
|---|
| 107 | 103 | }
|
|---|
| 108 | | -
|
|---|
| 104 | +
|
|---|
| 109 | 105 | private static void startServer() {
|
|---|
| 110 | 106 |
|
|---|
| 111 | 107 | if (new File(PID_FILE).exists()) {
|
|---|
| .. | .. |
|---|
| 116 | 112 | }
|
|---|
| 117 | 113 | System.exit(-2);
|
|---|
| 118 | 114 | }
|
|---|
| 119 | | -
|
|---|
| 115 | +
|
|---|
| 120 | 116 | SecurisModule securisModule = new SecurisModule();
|
|---|
| 121 | 117 | JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
|
|---|
| 122 | 118 | Properties props = new Properties();
|
|---|
| 123 | 119 | props.put("javax.persistence.jdbc.password", securisModule.getPassword());
|
|---|
| 124 | 120 | 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());
|
|---|
| 126 | 124 | jpaPersistModule.properties(props);
|
|---|
| 127 | 125 |
|
|---|
| 128 | 126 | injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
|
|---|
| 129 | 127 |
|
|---|
| 130 | 128 | try {
|
|---|
| 131 | 129 | startServer(injector.getInstance(Key.get(URI.class, Names.named("base-uri"))));
|
|---|
| 132 | | -
|
|---|
| 130 | +
|
|---|
| 133 | 131 | } catch (SeCurisException e) {
|
|---|
| 134 | 132 | CONSOLE.error("Error launching the SeCuris server, {}", e);
|
|---|
| 135 | 133 | }
|
|---|
| .. | .. |
|---|
| 153 | 151 |
|
|---|
| 154 | 152 | QueuedThreadPool threadPool = new QueuedThreadPool();
|
|---|
| 155 | 153 | threadPool.setMaxThreads(50);
|
|---|
| 156 | | -
|
|---|
| 154 | +
|
|---|
| 157 | 155 | server = new Server();
|
|---|
| 158 | | -
|
|---|
| 156 | +
|
|---|
| 159 | 157 | ServerConnector httpConnector = new ServerConnector(server);
|
|---|
| 160 | 158 | httpConnector.setPort(Config.getInt(Config.KEYS.SERVER_PORT, 9080));
|
|---|
| 161 | 159 | httpConnector.setHost(Config.get(Config.KEYS.SERVER_HOSTNAME, "0.0.0.0"));
|
|---|
| 162 | 160 | server.addConnector(httpConnector);
|
|---|
| 163 | | -
|
|---|
| 161 | +
|
|---|
| 164 | 162 | ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
|---|
| 165 | 163 | context.setContextPath("/");
|
|---|
| 166 | 164 | context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
|
|---|
| .. | .. |
|---|
| 191 | 189 | contexts.setHandlers(new Handler[] {
|
|---|
| 192 | 190 | staticResources, context
|
|---|
| 193 | 191 | });
|
|---|
| 194 | | -
|
|---|
| 192 | +
|
|---|
| 195 | 193 | HttpConfiguration http_config = new HttpConfiguration();
|
|---|
| 196 | 194 | http_config.setSecureScheme("https");
|
|---|
| 197 | 195 | http_config.setSecurePort(Config.getInt(Config.KEYS.SERVER_SSL_PORT, 9443));
|
|---|
| 198 | 196 | http_config.setOutputBufferSize(32768);
|
|---|
| 199 | 197 | http_config.setSendServerVersion(true);
|
|---|
| 200 | 198 | http_config.setSendDateHeader(false);
|
|---|
| 201 | | -
|
|---|
| 202 | | -
|
|---|
| 199 | +
|
|---|
| 203 | 200 | HttpConfiguration https_config = new HttpConfiguration(http_config);
|
|---|
| 204 | 201 | https_config.addCustomizer(new SecureRequestCustomizer());
|
|---|
| 205 | | -
|
|---|
| 202 | +
|
|---|
| 206 | 203 | SslContextFactory sslContextFactory = new SslContextFactory();
|
|---|
| 207 | 204 | sslContextFactory.setKeyStorePath(Config.get(Config.KEYS.KEYSTORE_PATH));
|
|---|
| 208 | 205 | sslContextFactory.setKeyStoreType(Config.get(Config.KEYS.KEYSTORE_TYPE, "JKS"));
|
|---|
| 209 | 206 | 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");
|
|---|
| 214 | 211 | sslContextFactory.checkKeyStore();
|
|---|
| 215 | 212 | 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));
|
|---|
| 218 | 216 | sslConnector.setPort(Config.getInt(Config.KEYS.SERVER_SSL_PORT, 9443));
|
|---|
| 219 | 217 | sslConnector.setHost(Config.get(Config.KEYS.SERVER_HOSTNAME, "0.0.0.0"));
|
|---|
| 220 | | - server.addConnector( sslConnector );
|
|---|
| 218 | + server.addConnector(sslConnector);
|
|---|
| 221 | 219 |
|
|---|
| 222 | 220 | server.setHandler(context);
|
|---|
| 223 | 221 | server.setStopAtShutdown(true);
|
|---|
| .. | .. |
|---|
| 233 | 231 | }
|
|---|
| 234 | 232 |
|
|---|
| 235 | 233 | }
|
|---|
| 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) {
|
|---|
| 239 | 238 | if (new File(PID_FILE).exists())
|
|---|
| 240 | 239 | new File(PID_FILE).delete();
|
|---|
| 241 | 240 | }
|
|---|