Search in sources :

Example 1 with InternalWebInterfaceHandler

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.");
}
Also used : WebServerTO(org.syncany.config.to.WebServerTO) HttpHandler(io.undertow.server.HttpHandler) IdentityManager(io.undertow.security.idm.IdentityManager) InternalWebSocketHandler(org.syncany.operations.daemon.handlers.InternalWebSocketHandler) SSLContext(javax.net.ssl.SSLContext) InternalRestHandler(org.syncany.operations.daemon.handlers.InternalRestHandler) UserTO(org.syncany.config.to.UserTO) InternalWebInterfaceHandler(org.syncany.operations.daemon.handlers.InternalWebInterfaceHandler)

Aggregations

IdentityManager (io.undertow.security.idm.IdentityManager)1 HttpHandler (io.undertow.server.HttpHandler)1 SSLContext (javax.net.ssl.SSLContext)1 UserTO (org.syncany.config.to.UserTO)1 WebServerTO (org.syncany.config.to.WebServerTO)1 InternalRestHandler (org.syncany.operations.daemon.handlers.InternalRestHandler)1 InternalWebInterfaceHandler (org.syncany.operations.daemon.handlers.InternalWebInterfaceHandler)1 InternalWebSocketHandler (org.syncany.operations.daemon.handlers.InternalWebSocketHandler)1