You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by el...@apache.org on 2017/02/06 19:01:30 UTC

[4/4] phoenix git commit: PHOENIX-1754 Try to handle keytab paths on Windows filesystems

PHOENIX-1754 Try to handle keytab paths on Windows filesystems


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

Branch: refs/heads/4.8-HBase-0.98
Commit: e437f22fa263e5cfe4589ae02938020701480bbf
Parents: 55cf908
Author: Josh Elser <el...@apache.org>
Authored: Fri Feb 3 18:45:16 2017 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Mon Feb 6 13:55:23 2017 -0500

----------------------------------------------------------------------
 .../phoenix/jdbc/PhoenixEmbeddedDriver.java     | 24 +++++++++++++++++++-
 .../phoenix/jdbc/PhoenixEmbeddedDriverTest.java |  4 ++++
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e437f22f/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
index 272fb22..d41826f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriver.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.jdbc;
 
 import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM;
 
+import java.io.File;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.Driver;
@@ -36,6 +37,7 @@ import javax.annotation.concurrent.Immutable;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.security.UserGroupInformation;
@@ -199,6 +201,7 @@ public abstract class PhoenixEmbeddedDriver implements Driver, SQLCloseable {
     public static class ConnectionInfo {
         private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ConnectionInfo.class);
         private static final Object KERBEROS_LOGIN_LOCK = new Object();
+        private static final char WINDOWS_SEPARATOR_CHAR = '\\';
         private static SQLException getMalFormedUrlException(String url) {
             return new SQLExceptionInfo.Builder(SQLExceptionCode.MALFORMED_CONNECTION_URL)
             .setMessage(url).build().buildException();
@@ -249,8 +252,18 @@ public abstract class PhoenixEmbeddedDriver implements Driver, SQLCloseable {
                 }
                 tokens[nTokens++] = token;
             }
+            // Look-forward to see if the last token is actually the C:\\ path
             if (tokenizer.hasMoreTokens() && !TERMINATOR.equals(token)) {
-                throw getMalFormedUrlException(url);
+                String extraToken = tokenizer.nextToken();
+                if (WINDOWS_SEPARATOR_CHAR == extraToken.charAt(0)) {
+                  String prevToken = tokens[nTokens - 1];
+                  tokens[nTokens - 1] = prevToken + ":" + extraToken;
+                  if (tokenizer.hasMoreTokens() && !(token=tokenizer.nextToken()).equals(TERMINATOR)) {
+                      throw getMalFormedUrlException(url);
+                  }
+                } else {
+                    throw getMalFormedUrlException(url);
+                }
             }
             String quorum = null;
             Integer port = null;
@@ -280,6 +293,15 @@ public abstract class PhoenixEmbeddedDriver implements Driver, SQLCloseable {
                             principal = tokens[tokenIndex++]; // Found principal
                             if (nTokens > tokenIndex) {
                                 keytabFile = tokens[tokenIndex++]; // Found keytabFile
+                                // There's still more after, try to see if it's a windows file path
+                                if (tokenIndex < tokens.length) {
+                                    String nextToken = tokens[tokenIndex++];
+                                    // The next token starts with the directory separator, assume
+                                    // it's still the keytab path.
+                                    if (null != nextToken && WINDOWS_SEPARATOR_CHAR == nextToken.charAt(0)) {
+                                        keytabFile = keytabFile + ":" + nextToken;
+                                    }
+                                }
                             }
                         }
                     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e437f22f/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java
index 98a028c..9d7fbfc 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixEmbeddedDriverTest.java
@@ -69,6 +69,8 @@ public class PhoenixEmbeddedDriverTest {
             "jdbc:phoenix:v1,v2,v3:/hbase:user/principal:/user.keytab;test=false",
             "jdbc:phoenix:v1,v2,v3:LongRunningQueries;test=false",
             "jdbc:phoenix:v1,v2,v3:345:LongRunningQueries;test=false",
+            "jdbc:phoenix:localhost:1234:user:C:\\user.keytab",
+            "jdbc:phoenix:v1,v2,v3:345:/hbase:user1:C:\\Documents and Settings\\user1\\user1.keytab;test=false",
         };
         ConnectionInfo[] infos = new ConnectionInfo[] {
             new ConnectionInfo("localhost",2181,"/hbase"),
@@ -106,6 +108,8 @@ public class PhoenixEmbeddedDriverTest {
             new ConnectionInfo("v1,v2,v3",null,"/hbase","user/principal", "/user.keytab" ),
             new ConnectionInfo("v1,v2,v3",null,null,"LongRunningQueries", null ),
             new ConnectionInfo("v1,v2,v3",345,null,"LongRunningQueries", null ),
+            new ConnectionInfo("localhost", 1234, null, "user", "C:\\user.keytab"),
+            new ConnectionInfo("v1,v2,v3", 345, "/hbase", "user1", "C:\\Documents and Settings\\user1\\user1.keytab"),
         };
         assertEquals(urls.length,infos.length);
         for (int i = 0; i < urls.length; i++) {