drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [5/8] drill git commit: DRILL-4353: Add HttpSessionListener to release resources of expired/invalidated sessions
Date Tue, 09 Feb 2016 00:26:56 GMT
DRILL-4353: Add HttpSessionListener to release resources of expired/invalidated sessions

Closes #359


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

Branch: refs/heads/master
Commit: 282dfd762f1bd6628b293c68b20cdff321bd70a3
Parents: bd14e1a
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Thu Feb 4 13:06:54 2016 -0800
Committer: Jason Altekruse <altekrusejason@gmail.com>
Committed: Mon Feb 8 14:55:29 2016 -0800

----------------------------------------------------------------------
 .../drill/exec/server/rest/WebServer.java       | 30 ++++++++++++++++++--
 .../server/rest/auth/DrillUserPrincipal.java    |  4 +--
 2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/282dfd76/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 358e847..6519169 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
@@ -44,6 +44,7 @@ import org.eclipse.jetty.security.ConstraintSecurityHandler;
 import org.eclipse.jetty.security.LoginService;
 import org.eclipse.jetty.security.SecurityHandler;
 import org.eclipse.jetty.security.authentication.FormAuthenticator;
+import org.eclipse.jetty.security.authentication.SessionAuthentication;
 import org.eclipse.jetty.server.HttpConfiguration;
 import org.eclipse.jetty.server.HttpConnectionFactory;
 import org.eclipse.jetty.server.SecureRequestCustomizer;
@@ -62,6 +63,9 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.glassfish.jersey.servlet.ServletContainer;
 import org.joda.time.DateTime;
 
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
 import java.math.BigInteger;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
@@ -145,8 +149,8 @@ public class WebServer implements AutoCloseable {
     staticHolder.setInitParameter("pathInfoOnly", "true");
     servletContextHandler.addServlet(staticHolder, "/static/*");
 
-    servletContextHandler.setSessionHandler(createSessionHandler());
     servletContextHandler.setSecurityHandler(createSecurityHandler());
+    servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
 
     embeddedJetty.start();
   }
@@ -154,9 +158,31 @@ public class WebServer implements AutoCloseable {
   /**
    * @return A {@link SessionHandler} which contains a {@link HashSessionManager}
    */
-  private SessionHandler createSessionHandler() {
+  private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
     SessionManager sessionManager = new HashSessionManager();
     sessionManager.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
+    sessionManager.addEventListener(new HttpSessionListener() {
+      @Override
+      public void sessionCreated(HttpSessionEvent se) {
+        // No-op
+      }
+
+      @Override
+      public void sessionDestroyed(HttpSessionEvent se) {
+        final HttpSession session = se.getSession();
+        if (session == null) {
+          return;
+        }
+
+        final Object authCreds = session.getAttribute(SessionAuthentication.__J_AUTHENTICATED);
+        if (authCreds != null) {
+          final SessionAuthentication sessionAuth = (SessionAuthentication) authCreds;
+          securityHandler.logout(sessionAuth);
+          session.removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
+        }
+      }
+    });
+
     return new SessionHandler(sessionManager);
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/282dfd76/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillUserPrincipal.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillUserPrincipal.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillUserPrincipal.java
index a7c3425..16e6f38 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillUserPrincipal.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillUserPrincipal.java
@@ -19,7 +19,6 @@ package org.apache.drill.exec.server.rest.auth;
 
 import com.google.common.collect.ImmutableList;
 import org.apache.drill.exec.client.DrillClient;
-import org.apache.drill.exec.proto.UserBitShared.QueryProfile;
 import org.eclipse.jetty.security.MappedLoginService.RolePrincipal;
 
 import java.security.Principal;
@@ -46,7 +45,7 @@ public class DrillUserPrincipal implements Principal, AutoCloseable {
 
   private final String userName;
   private final boolean isAdmin;
-  private final DrillClient drillClient;
+  private DrillClient drillClient;
 
   public DrillUserPrincipal(final String userName, final boolean isAdmin, final DrillClient
drillClient) {
     this.userName = userName;
@@ -88,6 +87,7 @@ public class DrillUserPrincipal implements Principal, AutoCloseable {
   public void close() throws Exception {
     if (drillClient != null) {
       drillClient.close();
+      drillClient = null; // Reset it to null to avoid closing multiple times.
     }
   }
 }
\ No newline at end of file


Mime
View raw message