/** A running node process. */
public interface CmsState {
- String getHostname();
-
Long getAvailableSince();
UUID getUuid();
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.argeo.cms.auth.RemoteAuthSession;
+import org.argeo.cms.servlet.ServletHttpSession;
+
import com.sun.net.httpserver.Authenticator;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpHandler;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try (ServletHttpExchange httpExchange = new ServletHttpExchange(httpContext, req, resp)) {
+ ServletHttpSession httpSession = new ServletHttpSession(req.getSession());
+ httpExchange.setAttribute(RemoteAuthSession.class.getName(), httpSession);
Authenticator authenticator = httpContext.getAuthenticator();
if (authenticator != null) {
Authenticator.Result authenticationResult = authenticator.authenticate(httpExchange);
HttpPrincipal httpPrincipal = ((Authenticator.Success) authenticationResult).getPrincipal();
httpExchange.setPrincipal(httpPrincipal);
} else if (authenticationResult instanceof Authenticator.Retry) {
- resp.setStatus(((Authenticator.Retry) authenticationResult).getResponseCode());
+ httpExchange.sendResponseHeaders((((Authenticator.Retry) authenticationResult).getResponseCode()),
+ -1);
+ resp.flushBuffer();
return;
} else if (authenticationResult instanceof Authenticator.Failure) {
- resp.setStatus(((Authenticator.Failure) authenticationResult).getResponseCode());
+ httpExchange.sendResponseHeaders(((Authenticator.Failure) authenticationResult).getResponseCode(),
+ -1);
+ resp.flushBuffer();
return;
} else {
throw new UnsupportedOperationException(
httpHandler.handle(httpExchange);
}
}
-
}
<implementation class="org.argeo.cms.equinox.http.jetty.EquinoxJettyServer"/>
<property name="service.pid" type="String" value="org.argeo.equinox.jetty.config"/>
<reference bind="setCmsState" cardinality="1..1" interface="org.argeo.api.cms.CmsState" name="CmsState" policy="static"/>
+ <reference bind="setDefaultAuthenticator" cardinality="1..1" interface="com.sun.net.httpserver.Authenticator" policy="static"/>
+ <service>
+ <provide interface="com.sun.net.httpserver.HttpServer"/>
+ </service>
</scr:component>
import javax.websocket.DeploymentException;
import javax.websocket.server.ServerContainer;
import javax.websocket.server.ServerEndpointConfig;
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpContext;
import org.argeo.api.cms.CmsState;
import org.argeo.cms.CmsDeployProperty;
private CmsState cmsState;
+ private Authenticator defaultAuthenticator;
+
protected void addServlets(ServletContextHandler servletContextHandler) throws ServletException {
}
}
+ @Override
+ public synchronized HttpContext createContext(String path) {
+ HttpContext httpContext = super.createContext(path);
+ httpContext.setAuthenticator(defaultAuthenticator);
+ return httpContext;
+ }
+
protected void enableWebSocket(ServletContextHandler servletContextHandler) {
String webSocketEnabled = getDeployProperty(CmsDeployProperty.WEBSOCKET_ENABLED);
// web socket
this.cmsState = cmsState;
}
+ public void setDefaultAuthenticator(Authenticator defaultAuthenticator) {
+ this.defaultAuthenticator = defaultAuthenticator;
+ }
+
}
import org.argeo.cms.servlet.httpserver.HttpContextServlet;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
this.httpServer = httpServer;
this.path = path;
+ // Jetty context handler
ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setContextPath(path);
HttpContextServlet servlet = new HttpContextServlet(this);
servletContextHandler.addServlet(new ServletHolder(servlet), "/*");
+ SessionHandler sessionHandler = new SessionHandler();
+ // FIXME find a better default
+ sessionHandler.setMaxInactiveInterval(-1);
+ servletContextHandler.setSessionHandler(sessionHandler);
contextHandler = servletContextHandler;
attributes = new ContextAttributes();
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.argeo.cms.internal.runtime.CmsAcrHttpHandler"/>
+ <service>
+ <provide interface="com.sun.net.httpserver.HttpHandler"/>
+ <property name="contextPath" type="String" value="/api/acr" />
+ </service>
+</scr:component>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.argeo.cms">
+ <implementation class="org.argeo.cms.internal.http.CmsAuthenticator"/>
+ <service>
+ <provide interface="com.sun.net.httpserver.Authenticator"/>
+ </service>
+ <reference cardinality="1..1" interface="org.osgi.service.useradmin.UserAdmin" name="UserAdmin" policy="static"/>
+</scr:component>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="CMS Deployment">
<implementation class="org.argeo.cms.internal.runtime.CmsDeploymentImpl"/>
<reference bind="setCmsState" cardinality="1..1" interface="org.argeo.api.cms.CmsState" name="CmsState" policy="static"/>
+ <reference bind="setHttpServer" cardinality="1..1" interface="com.sun.net.httpserver.HttpServer" policy="static"/>
+ <reference bind="addHttpHandler" unbind="removeHttpHandlerler" cardinality="0..1" interface="com.sun.net.httpserver.HttpHandler" policy="dynamic"/>
<service>
<provide interface="org.argeo.api.cms.CmsDeployment"/>
</service>
OSGI-INF/simpleTransactionManager.xml,\
OSGI-INF/nodeUserAdmin.xml,\
OSGI-INF/cmsUserManager.xml,\
+OSGI-INF/cmsAuthenticator.xml,\
OSGI-INF/uuidFactory.xml,\
OSGI-INF/acrContentRepository.xml,\
+OSGI-INF/cmsAcrHttpHandler.xml,\
OSGI-INF/cmsDeployment.xml,\
OSGI-INF/cmsContext.xml,\
bin.includes = META-INF/,\
.,\
bin/,\
- OSGI-INF/
+ OSGI-INF/,\
+ OSGI-INF/cmsAuthenticator.xml,\
+ OSGI-INF/cmsAcrHttpHandler.xml
source.. = src/
}
protected boolean authIsRequired(HttpExchange httpExchange) {
- return false;
+ return true;
}
protected LoginContext processUnauthorized(HttpExchange httpExchange) {
import java.util.Collections;
import java.util.List;
import java.util.Locale;
+import java.util.Objects;
import org.argeo.cms.auth.RemoteAuthRequest;
import org.argeo.cms.auth.RemoteAuthResponse;
import com.sun.net.httpserver.HttpExchange;
public class RemoteAuthHttpExchange implements RemoteAuthRequest, RemoteAuthResponse {
- private HttpExchange httpExchange;
+ private final HttpExchange httpExchange;
+ private RemoteAuthSession remoteAuthSession;
public RemoteAuthHttpExchange(HttpExchange httpExchange) {
this.httpExchange = httpExchange;
+ this.remoteAuthSession = (RemoteAuthSession) httpExchange.getAttribute(RemoteAuthSession.class.getName());
+ Objects.requireNonNull(this.remoteAuthSession);
}
@Override
@Override
public RemoteAuthSession getSession() {
- // TODO Auto-generated method stub
- return null;
+ return remoteAuthSession;
}
@Override
public RemoteAuthSession createSession() {
- // TODO Auto-generated method stub
- return null;
+ throw new UnsupportedOperationException("Cannot create remote session");
}
@Override
--- /dev/null
+package org.argeo.cms.internal.runtime;
+
+import org.argeo.util.dav.DavServerHandler;
+
+public class CmsAcrHttpHandler extends DavServerHandler {
+
+}
package org.argeo.cms.internal.runtime;
+import java.util.Map;
+
import org.argeo.api.cms.CmsDeployment;
import org.argeo.api.cms.CmsLog;
import org.argeo.api.cms.CmsState;
import org.argeo.cms.CmsDeployProperty;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
/** Implementation of a CMS deployment. */
public class CmsDeploymentImpl implements CmsDeployment {
private final CmsLog log = CmsLog.getLog(getClass());
private CmsState cmsState;
// private DeployConfig deployConfig;
+ private HttpServer httpServer;
+
public void start() {
// httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
// if (deployConfig.hasDomain()) {
httpExpected = httpPort != null || httpsPort != null;
}
+ public void setHttpServer(HttpServer httpServer) {
+ this.httpServer = httpServer;
+ }
+
+ public void addHttpHandler(HttpHandler httpHandler, Map<String, String> properties) {
+ if (httpServer == null)
+ return;
+ final String contextPath = properties.get("contextPath");
+ httpServer.createContext(contextPath, httpHandler);
+ log.debug(() -> "Added handler " + contextPath + " : " + httpHandler.getClass().getName());
+
+ }
+
+ public void removeHttpHandler(HttpHandler httpHandler, Map<String, String> properties) {
+ if (httpServer == null)
+ return;
+ final String contextPath = properties.get("contextPath");
+ httpServer.removeContext(contextPath);
+ log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName());
+ }
// public void setHttpService(HttpService httpService) {
// this.httpService = httpService;
// }
private UUID uuid;
// private final boolean cleanState;
- private String hostname;
+// private String hostname;
private UuidFactory uuidFactory;
// this.uuid = UUID.fromString(stateUuidStr);
this.uuid = uuidFactory.timeUUID();
// this.cleanState = stateUuid.equals(frameworkUuid);
- try {
- this.hostname = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException e) {
- log.error("Cannot set hostname: " + e);
- }
+// try {
+// this.hostname = InetAddress.getLocalHost().getHostName();
+// } catch (UnknownHostException e) {
+// log.error("Cannot set hostname: " + e);
+// }
availableSince = System.currentTimeMillis();
if (log.isDebugEnabled()) {
/*
* ACCESSORS
*/
- public String getHostname() {
- return hostname;
- }
-
@Override
public UUID getUuid() {
return uuid;
import java.io.IOException;
+import org.argeo.util.http.HttpMethod;
+
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
String method = exchange.getRequestMethod();
if (DavMethod.PROPFIND.name().equals(method)) {
handle(exchange);
+ } else if (HttpMethod.GET.name().equals(method)) {
+ exchange.getResponseBody().write("Hello Dav!".getBytes());
} else {
throw new IllegalArgumentException("Unsupported method " + method);
}
--- /dev/null
+package org.argeo.util.http;
+
+public enum HttpMethod {
+ GET,//
+ ;
+}
Label label = new Label(composite, SWT.WRAP);
CmsSwtUtils.markup(label);
if (nodeDeploymentRef == null) {
- label.setText("Not yet deployed on <br>" + nodeState.getHostname() + "</br>, please configure below.");
+ label.setText("Not yet deployed on, please configure below.");
} else {
Object stateUuid = nodeStateRef.getProperty(CmsConstants.CN);
CmsContext nodeDeployment = bc.getService(nodeDeploymentRef);
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(nodeDeployment.getAvailableSince());
calendar.setTimeZone(TimeZone.getDefault());
- label.setText("[" + "<b>" + nodeState.getHostname() + "</b>]# " + "Deployment state " + stateUuid
- + ", available since <b>" + calendar.getTime() + "</b>");
+ label.setText("Deployment state " + stateUuid + ", available since <b>" + calendar.getTime() + "</b>");
}
}