drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [24/29] drill git commit: DRILL-4280: CORE (web client)
Date Sat, 25 Feb 2017 07:18:17 GMT
DRILL-4280: CORE (web client)

+ Disabled web server when authentication is enabled but PLAIN mechanism
  is not configured; log a warning


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/5fff4981
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/5fff4981
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/5fff4981

Branch: refs/heads/master
Commit: 5fff49813b2298c02748dc1da501980e16cab43d
Parents: e2582a1
Author: Sudheesh Katkam <sudheesh@apache.org>
Authored: Wed Jan 25 19:05:23 2017 -0800
Committer: Sudheesh Katkam <sudheesh@apache.org>
Committed: Fri Feb 24 19:01:43 2017 -0800

----------------------------------------------------------------------
 .../drill/exec/server/rest/WebServer.java       | 29 ++++++++++++++------
 1 file changed, 20 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/5fff4981/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebServer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebServer.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebServer.java
index 0b19dce..685a823 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebServer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebServer.java
@@ -26,6 +26,8 @@ import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.rpc.security.plain.PlainFactory;
+import org.apache.drill.exec.server.BootStrapContext;
 import org.apache.drill.exec.server.rest.auth.DrillRestLoginService;
 import org.apache.drill.exec.work.WorkManager;
 import org.bouncycastle.asn1.x500.X500NameBuilder;
@@ -91,16 +93,18 @@ public class WebServer implements AutoCloseable {
   private final MetricRegistry metrics;
   private final WorkManager workManager;
   private final Server embeddedJetty;
+  private final BootStrapContext context;
 
   /**
    * Create Jetty based web server.
-   * @param config DrillConfig instance.
-   * @param metrics Metrics registry.
+   *
+   * @param context Bootstrap context.
    * @param workManager WorkManager instance.
    */
-  public WebServer(final DrillConfig config, final MetricRegistry metrics, final WorkManager
workManager) {
-    this.config = config;
-    this.metrics = metrics;
+  public WebServer(final BootStrapContext context, final WorkManager workManager) {
+    this.context = context;
+    this.config = context.getConfig();
+    this.metrics = context.getMetrics();
     this.workManager = workManager;
 
     if (config.getBoolean(ExecConstants.HTTP_ENABLE)) {
@@ -121,6 +125,13 @@ public class WebServer implements AutoCloseable {
     if (embeddedJetty == null) {
       return;
     }
+    final boolean authEnabled = config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED);
+    if (authEnabled && !context.getAuthProvider()
+        .containsFactory(PlainFactory.SIMPLE_NAME)) {
+      logger.warn("Not starting web server. Currently Drill supports web authentication only
through " +
+          "username/password. But PLAIN mechanism is not configured.");
+      return;
+    }
 
     final ServerConnector serverConnector;
     if (config.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
@@ -138,7 +149,6 @@ public class WebServer implements AutoCloseable {
     final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
     servletContextHandler.setErrorHandler(errorHandler);
     servletContextHandler.setContextPath("/");
-    embeddedJetty.setHandler(servletContextHandler);
 
     final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager)));
     servletHolder.setInitOrder(1);
@@ -159,9 +169,9 @@ public class WebServer implements AutoCloseable {
     staticHolder.setInitParameter("pathInfoOnly", "true");
     servletContextHandler.addServlet(staticHolder, "/static/*");
 
-    if (config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED)) {
-      servletContextHandler.setSecurityHandler(createSecurityHandler());
-      servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
+    if (authEnabled) {
+        servletContextHandler.setSecurityHandler(createSecurityHandler());
+        servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
     }
 
     if (config.getBoolean(ExecConstants.HTTP_CORS_ENABLED)) {
@@ -180,6 +190,7 @@ public class WebServer implements AutoCloseable {
       }
     }
 
+    embeddedJetty.setHandler(servletContextHandler);
     embeddedJetty.start();
   }
 


Mime
View raw message