summaryrefslogtreecommitdiffstats
path: root/java/vaadin-u2f/src/run
diff options
context:
space:
mode:
Diffstat (limited to 'java/vaadin-u2f/src/run')
-rw-r--r--java/vaadin-u2f/src/run/java/ch/asynk/Main.java130
-rw-r--r--java/vaadin-u2f/src/run/resources/jetty-logging.properties6
-rw-r--r--java/vaadin-u2f/src/run/resources/keystore.jksbin0 -> 2230 bytes
3 files changed, 136 insertions, 0 deletions
diff --git a/java/vaadin-u2f/src/run/java/ch/asynk/Main.java b/java/vaadin-u2f/src/run/java/ch/asynk/Main.java
new file mode 100644
index 0000000..f6dfc4e
--- /dev/null
+++ b/java/vaadin-u2f/src/run/java/ch/asynk/Main.java
@@ -0,0 +1,130 @@
+package ch.asynk;
+
+import com.vaadin.server.DefaultUIProvider;
+import com.vaadin.server.UIProvider;
+import com.vaadin.server.VaadinServlet;
+import com.vaadin.ui.UI;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SecureRequestCustomizer;
+import org.eclipse.jetty.server.SslConnectionFactory;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+// https://github.com/eclipse/jetty.project/blob/jetty-9.3.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
+
+abstract class VaadinJettyServer extends Server
+{
+ public VaadinJettyServer(int port, final String webappDirectory, final String contextPath)
+ {
+ super();
+ configure(port, contextPath);
+ buildWebapp(webappDirectory, contextPath);
+ }
+
+ abstract protected void configure(int port, final String contextPath);
+
+ protected void buildWebapp(final String webappDirectory, final String contextPath)
+ {
+
+ WebAppContext context = new WebAppContext(webappDirectory, contextPath);
+
+ context.addServlet(buildVaadinServlet(new HelloWorldServlet(), HelloWorldUI.class), "/*");
+
+ setHandler(context);
+ }
+
+ protected void say(int port, boolean https, final String contextPath)
+ {
+ System.out.println(String.format("%s://localhost:%d%s", (https ? "https" : "http"), port, contextPath));
+ }
+
+ private ServletHolder buildVaadinServlet(VaadinServlet servlet, Class<? extends UI> uiClass)
+ {
+ ServletHolder servletHolder = new ServletHolder(servlet);
+ servletHolder.setInitParameter(VaadinServlet.SERVLET_PARAMETER_UI_PROVIDER, DefaultUIProvider.class.getName());
+ if (uiClass != null) servletHolder.setInitParameter("UI", uiClass.getName());
+ return servletHolder;
+ }
+
+ protected Connector httpConnector(int port)
+ {
+ ServerConnector connector = new ServerConnector(this);
+ connector.setPort(port);
+ return connector;
+ }
+
+ protected Connector httpsConnector(int port)
+ {
+ HttpConfiguration httpConf = new HttpConfiguration();
+ httpConf.addCustomizer(new SecureRequestCustomizer());
+
+ SslContextFactory sslContextFactory = new SslContextFactory();
+ // keytool -keystore src/run/resources/keystore.jks -genkey -alias asynk.ch -keyalg RSA -keysize 2048
+ sslContextFactory.setKeyStorePath(VaadinJettyServer.class.getResource("/keystore.jks").toExternalForm());
+ sslContextFactory.setKeyStorePassword("123456");
+ sslContextFactory.setKeyManagerPassword("123456");
+ ServerConnector connector = new ServerConnector(this,
+ new SslConnectionFactory(sslContextFactory, "http/1.1"),
+ new HttpConnectionFactory(httpConf));
+ connector.setPort(port);
+ return connector;
+ }
+}
+
+class HttpVaadinJettyServer extends VaadinJettyServer
+{
+ public HttpVaadinJettyServer(int port, final String webappDirectory, final String contextPath) { super(port, webappDirectory, contextPath); }
+
+ @Override
+ protected void configure(int port, final String contextPath)
+ {
+ say(port, false, contextPath);
+ addConnector(httpConnector(port));
+ }
+}
+
+class HttpsVaadinJettyServer extends VaadinJettyServer
+{
+ public HttpsVaadinJettyServer(int port, final String webappDirectory, final String contextPath) { super(port, webappDirectory, contextPath); }
+
+ @Override
+ protected void configure(int port, final String contextPath)
+ {
+ say(port, true, contextPath);
+ addConnector(httpsConnector(port));
+ }
+}
+class HttpHttpsVaadinJettyServer extends HttpsVaadinJettyServer
+{
+ public HttpHttpsVaadinJettyServer(int port, final String webappDirectory, final String contextPath) { super(port, webappDirectory, contextPath); }
+
+ @Override
+ protected void configure(int port, final String contextPath)
+ {
+ say(port, false, contextPath);
+ say(port + 1, true, contextPath);
+ this.setConnectors(new Connector[] { httpConnector(port), httpsConnector(port + 1) });
+ }
+}
+
+public class Main
+{
+ public static void main(String[] args) throws Exception
+ {
+ int port = 8666;
+ String webRoot = System.getProperty("WEBROOT");
+ if (webRoot == null) webRoot = "./src/main/WebContent";
+
+ new HttpsVaadinJettyServer(port, webRoot, "/test").start();
+ }
+}
diff --git a/java/vaadin-u2f/src/run/resources/jetty-logging.properties b/java/vaadin-u2f/src/run/resources/jetty-logging.properties
new file mode 100644
index 0000000..71495db
--- /dev/null
+++ b/java/vaadin-u2f/src/run/resources/jetty-logging.properties
@@ -0,0 +1,6 @@
+# Configure for System.err output
+org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
+# Configure StdErrLog to log all jetty namespace at default of WARN or above
+org.eclipse.jetty.LEVEL=WARN
+# Configure StdErrLog to log websocket specific namespace at DEBUG or above
+org.eclipse.jetty.websocket.LEVEL=INFO
diff --git a/java/vaadin-u2f/src/run/resources/keystore.jks b/java/vaadin-u2f/src/run/resources/keystore.jks
new file mode 100644
index 0000000..333fa20
--- /dev/null
+++ b/java/vaadin-u2f/src/run/resources/keystore.jks
Binary files differ