--- /src/test/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java 2012-02-08 10:22:28.205411100 +0800 +++ /src/test/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java 2012-02-08 10:28:38.548194000 +0800 @@ -46,7 +46,9 @@ import java.sql.Struct; import java.util.Map; import java.util.Properties; - +import java.nio.ByteBuffer; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; /** * HiveConnection. * @@ -94,6 +96,34 @@ client = new HiveClient(protocol); try { transport.open(); + if (!info.getProperty("user").equals("") && !info.getProperty("password").equals("")) { + byte[] value = null; + byte[] scramble = null; + try { + scramble = protocol.readBinary().array(); + MessageDigest md = MessageDigest.getInstance("SHA-1"); + md.update(info.getProperty("password").getBytes()); + value = md.digest(); + md.reset(); + md.update(value); + md.update(scramble); + value = md.digest(); + ByteBuffer bb = ByteBuffer.wrap(value); + protocol.writeString(info.getProperty("user")); + protocol.writeBinary(bb); + + transport.flush(); + protocol.readBool(); + } + catch(TException e){ + throw new SQLException("Could not read protocol " + + uri + ": " + e.getMessage(), "08S01"); + } + catch(NoSuchAlgorithmException e){ + throw new SQLException("Could not find sha-1 algorithm " + + uri + ": " + e.getMessage(), "08S01"); + } + } } catch (TTransportException e) { throw new SQLException("Could not establish connection to " + uri + ": " + e.getMessage(), "08S01");