use of org.syncany.operations.daemon.handlers.InternalWebInterfaceHandler in project syncany by syncany.
the class WebServer method initServer.
private void initServer(DaemonConfigTO daemonConfigTO) throws Exception {
WebServerTO webServerConfig = daemonConfigTO.getWebServer();
// Bind address and port
String bindAddress = webServerConfig.getBindAddress();
int bindPort = webServerConfig.getBindPort();
// Users (incl. CLI user!)
List<UserTO> users = readWebServerUsers(daemonConfigTO);
IdentityManager identityManager = new MapIdentityManager(users);
// (Re-)generate keypair/certificate (if requested)
boolean certificateAutoGenerate = webServerConfig.isCertificateAutoGenerate();
String certificateCommonName = webServerConfig.getCertificateCommonName();
if (certificateAutoGenerate && certificateCommonNameChanged(certificateCommonName)) {
generateNewKeyPairAndCertificate(certificateCommonName);
}
// Set up the handlers for WebSocket, REST and the web interface
HttpHandler pathHttpHandler = path().addPrefixPath(API_ENDPOINT_WS_XML, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.XML))).addPrefixPath(API_ENDPOINT_WS_JSON, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.JSON))).addPrefixPath(API_ENDPOINT_REST_XML, new InternalRestHandler(this, RequestFormatType.XML)).addPrefixPath(API_ENDPOINT_REST_JSON, new InternalRestHandler(this, RequestFormatType.JSON)).addPrefixPath("/", new InternalWebInterfaceHandler());
// Add some security spices
HttpHandler securityPathHttpHandler = addSecurity(pathHttpHandler, identityManager);
SSLContext sslContext = UserConfig.createUserSSLContext();
// And go for it!
webServer = Undertow.builder().addHttpsListener(bindPort, bindAddress, sslContext).setHandler(securityPathHttpHandler).build();
logger.log(Level.INFO, "Initialized web server.");
}
Aggregations