+
+ String sshdPort = this.cmsState.getDeployProperty(CmsDeployProperty.SSHD_PORT.getProperty());
+ sshdExpected = sshdPort != null;
+ }
+
+ public void setHttpServer(HttpServer httpServer) {
+ this.httpServer = httpServer;
+ // create contexts whose handles had already been published
+ for (String contextPath : httpHandlers.keySet()) {
+ HttpHandler httpHandler = httpHandlers.get(contextPath);
+ CmsAuthenticator authenticator = httpAuthenticators.get(contextPath);
+ createHttpContext(contextPath, httpHandler, authenticator);
+ }
+ }
+
+ public void addHttpHandler(HttpHandler httpHandler, Map<String, String> properties) {
+ final String contextPath = properties.get(CONTEXT_PATH);
+ if (contextPath == null) {
+ log.warn("Property " + CONTEXT_PATH + " not set on HTTP handler " + properties + ". Ignoring it.");
+ return;
+ }
+ boolean isPublic = Boolean.parseBoolean(properties.get(CmsConstants.CONTEXT_PUBLIC));
+ CmsAuthenticator authenticator = isPublic ? new PublicCmsAuthenticator() : new CmsAuthenticator();
+ httpHandlers.put(contextPath, httpHandler);
+ httpAuthenticators.put(contextPath, authenticator);
+ if (httpServer == null) {
+ return;
+ } else {
+ createHttpContext(contextPath, httpHandler, authenticator);
+ }
+ }
+
+ public void createHttpContext(String contextPath, HttpHandler httpHandler, CmsAuthenticator authenticator) {
+ HttpContext httpContext = httpServer.createContext(contextPath);
+ // we want to set the authenticator BEFORE the handler actually becomes active
+ httpContext.setAuthenticator(authenticator);
+ httpContext.setHandler(httpHandler);
+ log.debug(() -> "Added handler " + contextPath + " : " + httpHandler.getClass().getName());
+ }
+
+ public void removeHttpHandler(HttpHandler httpHandler, Map<String, String> properties) {
+ final String contextPath = properties.get(CmsConstants.CONTEXT_PATH);
+ if (contextPath == null)
+ return; // ignore silently
+ httpHandlers.remove(contextPath);
+ if (httpServer == null)
+ return;
+ httpServer.removeContext(contextPath);
+ log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName());
+ }
+
+ public boolean allExpectedServicesAvailable() {
+ if (httpExpected && httpServer == null)
+ return false;
+ if (sshdExpected && cmsSshd == null)
+ return false;
+ return true;