diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index 8f47323700..83ab34ada6 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -1627,28 +1627,33 @@ public boolean connect(Properties props) throws IOException { } } - String auth = getProperty(props, new String[] {JdbcConnectionParams.AUTH_TYPE}); - if (auth == null) { - auth = beeLine.getOpts().getAuthType(); - if (auth != null) { - props.setProperty(JdbcConnectionParams.AUTH_TYPE, auth); - } - } + String auth = getAuthType(props); + beeLine.info("Authentication type:" + auth); beeLine.info("Connecting to " + url); - if (Utils.parsePropertyFromUrl(url, JdbcConnectionParams.AUTH_PRINCIPAL) == null) { - String urlForPrompt = url.substring(0, url.contains(";") ? url.indexOf(';') : url.length()); + if ("NONE".equals(auth)) { if (username == null) { - username = beeLine.getConsoleReader().readLine("Enter username for " + urlForPrompt + ": "); + username = "hive"; } - props.setProperty(JdbcConnectionParams.AUTH_USER, username); if (password == null) { - password = beeLine.getConsoleReader().readLine("Enter password for " + urlForPrompt + ": ", - new Character('*')); + password = "DUMMY"; + } + } else { + if (Utils.parsePropertyFromUrl(url, JdbcConnectionParams.AUTH_PRINCIPAL) == null) { + String urlForPrompt = url.substring(0, url.contains(";") ? url.indexOf(';') : url.length()); + if (username == null) { + username = beeLine.getConsoleReader().readLine("Enter username for " + urlForPrompt + ": "); + } + if (password == null) { + password = beeLine.getConsoleReader().readLine("Enter password for " + urlForPrompt + ": ", + new Character('*')); + } } - props.setProperty(JdbcConnectionParams.AUTH_PASSWD, password); } + props.setProperty(JdbcConnectionParams.AUTH_USER, username); + props.setProperty(JdbcConnectionParams.AUTH_PASSWD, password); + try { beeLine.getDatabaseConnections().setConnection( new DatabaseConnection(beeLine, driver, url, props)); @@ -1677,6 +1682,17 @@ public boolean connect(Properties props) throws IOException { } } + private String getAuthType(Properties props) { + String auth = getProperty(props, new String[] {JdbcConnectionParams.AUTH_TYPE}); + if (auth == null) { + auth = beeLine.getOpts().getAuthType(); + if (auth != null) { + props.setProperty(JdbcConnectionParams.AUTH_TYPE, auth); + } + } + return auth; + } + public boolean rehash(String line) { try { if (!(beeLine.assertConnection())) { diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeelinePasswordOption.java itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeelinePasswordOption.java index b6d01ce578..2a33d5c018 100644 --- itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeelinePasswordOption.java +++ itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeelinePasswordOption.java @@ -207,6 +207,19 @@ public void testNoPasswordPrompt2() throws Exception { output.contains(tableName.toLowerCase())); } + /** + * Tests if beeline doesn't prompt for username and password and connects with auth=NONE provided in the JDBC url + */ + @Test + public void testNoPasswordPromptWithNoneAuthTypeJdbcParam() throws Exception { + List argList = getBaseArgs(miniHS2.getJdbcURL("default", "auth=NONE")); + argList.add("-e"); + argList.add("show tables;"); + String output = connectBeelineWithUserPrompt(argList); + Assert.assertTrue("Table name " + tableName + " not found in the output", + output.contains(tableName.toLowerCase())); + } + /** * Tests if Beeline prompts for password when -p is the last argument and argList has CommandLine * options as well as BeelineOpts