Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 d0ea85837 -> 5bfb7440b
  refs/heads/4.x-HBase-1.1 170524e33 -> ab5d507fa
  refs/heads/master 54ddb916e -> 3519b3b54


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/3519b3b5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/3519b3b5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/3519b3b5

Branch: refs/heads/master
Commit: 3519b3b549ac05a2ec0713ba94077cf4c6c2fe20
Parents: 54ddb91
Author: Josh Elser <els...@apache.org>
Authored: Fri Feb 3 18:45:16 2017 -0500
Committer: Josh Elser <els...@apache.org>
Committed: Mon Feb 6 10:53:19 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/3519b3b5/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/3519b3b5/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++) {

Reply via email to