use of java.sql.Connection in project hive by apache.
the class TestJdbcMetadataApiAuth method testMetaApiDisAllowed.
/**
* Call the HS2 metadata api's with authorizer disallowing those calls
* @throws Exception
*/
@Test
public void testMetaApiDisAllowed() throws Exception {
TestAuthValidator.allowActions = false;
Connection hs2Conn = getConnection("user1");
DatabaseMetaData dbmetadata = hs2Conn.getMetaData();
try {
dbmetadata.getCatalogs();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getSchemas();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTypeInfo();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTables(null, "default", "t%", null);
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getTableTypes();
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getColumns(null, "default", "nosuchtable", null);
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
try {
dbmetadata.getFunctions(null, null, "trim");
fail("HiveAccessControlException expected");
} catch (SQLException e) {
assertErrorContains(e, TestAuthValidator.DENIED_ERR);
} catch (Exception e) {
fail("HiveAccessControlException expected");
}
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithSQLAuthorization method testConfigWhiteList.
@Test
public void testConfigWhiteList() throws Exception {
// create tables as user1
Connection hs2Conn = getConnection("user1");
Statement stmt = hs2Conn.createStatement();
try {
stmt.execute("set hive.metastore.uris=x");
fail("exception expected");
} catch (SQLException e) {
String msg = "Cannot modify hive.metastore.uris at runtime. " + "It is not in list of params that are allowed to be modified at runtime";
assertTrue(e.getMessage().contains(msg));
}
stmt.execute("set hive.exec.reducers.bytes.per.reducer=10000");
//no exception should be thrown
stmt.close();
hs2Conn.close();
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithMiniHS2 method testUdfBlackListOverride.
/** Test UDF blacklist overrides whitelist
* @throws Exception
*/
@Test
public void testUdfBlackListOverride() throws Exception {
stopMiniHS2();
// setup whitelist
HiveConf testConf = new HiveConf();
Set<String> funcNames = FunctionRegistry.getFunctionNames();
String funcNameStr = "";
for (String funcName : funcNames) {
funcNameStr += "," + funcName;
}
// remove ',' at begining
funcNameStr = funcNameStr.substring(1);
testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST, funcNameStr);
testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_BLACKLIST, "reflect");
startMiniHS2(testConf);
Connection conn = getConnection(miniHS2.getJdbcURL(testDbName), System.getProperty("user.name"), "bar");
Statement stmt = conn.createStatement();
// verify that udf in black list fails even though it's included in whitelist
try {
stmt.executeQuery("SELECT reflect('java.lang.String', 'valueOf', 1) ");
fail("reflect() udf invocation should fail");
} catch (SQLException e) {
// expected
}
conn.close();
// Restore original state
restoreMiniHS2AndConnections();
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithMiniLlap method getConnection.
private Connection getConnection(String jdbcURL, String user, String pwd) throws SQLException {
Connection conn = DriverManager.getConnection(jdbcURL, user, pwd);
conn.createStatement().execute("set hive.support.concurrency = false");
return conn;
}
use of java.sql.Connection in project hive by apache.
the class TestMultiSessionsHS2WithLocalClusterSpark method createConnection.
private void createConnection() throws Exception {
Connection connection = DriverManager.getConnection(miniHS2.getJdbcURL(dbName), System.getProperty("user.name"), "bar");
Statement statement = connection.createStatement();
localConnection.set(connection);
localStatement.set(statement);
statement.execute("USE " + dbName);
}
Aggregations