use of java.sql.Connection in project hive by apache.
the class TestHS2ImpersonationWithRemoteMS method testImpersonation.
@Test
public void testImpersonation() throws Exception {
assertTrue("Test setup failed. MiniHS2 is not initialized", miniHS2 != null && miniHS2.isStarted());
Class.forName(MiniHS2.getJdbcDriverName());
// Create two tables one as user "foo" and other as user "bar"
Connection hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL(), "foo", null);
Statement stmt = hs2Conn.createStatement();
String tableName = "foo_table";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (value string)");
stmt.close();
hs2Conn.close();
hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL(), "bar", null);
stmt = hs2Conn.createStatement();
tableName = "bar_table";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (value string)");
stmt.close();
hs2Conn.close();
MiniDFSShim dfs = miniHS2.getDfs();
FileSystem fs = dfs.getFileSystem();
FileStatus[] files = fs.listStatus(miniHS2.getWareHouseDir());
boolean fooTableValidated = false;
boolean barTableValidated = false;
for (FileStatus file : files) {
final String name = file.getPath().getName();
final String owner = file.getOwner();
if (name.equals("foo_table")) {
fooTableValidated = owner.equals("foo");
assertTrue(String.format("User 'foo' table has wrong ownership '%s'", owner), fooTableValidated);
} else if (name.equals("bar_table")) {
barTableValidated = owner.equals("bar");
assertTrue(String.format("User 'bar' table has wrong ownership '%s'", owner), barTableValidated);
} else {
fail(String.format("Unexpected table directory '%s' in warehouse", name));
}
System.out.println(String.format("File: %s, Owner: %s", name, owner));
}
assertTrue("User 'foo' table not found in warehouse", fooTableValidated);
assertTrue("User 'bar' table not found in warehouse", barTableValidated);
}
use of java.sql.Connection in project hive by apache.
the class TestCustomAuthentication method testCustomAuthentication.
@Test
public void testCustomAuthentication() throws Exception {
String url = "jdbc:hive2://localhost:10000/default";
Class.forName("org.apache.hive.jdbc.HiveDriver");
try {
DriverManager.getConnection(url, "wronguser", "pwd");
Assert.fail("Expected Exception");
} catch (SQLException e) {
Assert.assertNotNull(e.getMessage());
Assert.assertTrue(e.getMessage(), e.getMessage().contains("Peer indicated failure: Error validating the login"));
}
Connection connection = DriverManager.getConnection(url, "hiveuser", "hive");
connection.close();
System.out.println(">>> PASSED testCustomAuthentication");
}
use of java.sql.Connection in project hive by apache.
the class cbo_rp_TestJdbcDriver2 method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws SQLException, ClassNotFoundException {
Class.forName(driverName);
Connection con1 = getConnection("default");
System.setProperty(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LEVEL.varname, "verbose");
Statement stmt1 = con1.createStatement();
assertNotNull("Statement is null", stmt1);
stmt1.execute("set hive.support.concurrency = false");
DatabaseMetaData metadata = con1.getMetaData();
// Drop databases created by other test cases
ResultSet databaseRes = metadata.getSchemas();
while (databaseRes.next()) {
String db = databaseRes.getString(1);
if (!db.equals("default")) {
System.err.println("Dropping database " + db);
stmt1.execute("DROP DATABASE " + db + " CASCADE");
}
}
stmt1.close();
con1.close();
}
use of java.sql.Connection in project hive by apache.
the class TestXSRFFilter 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 TestHS2AuthzContext method verifyContextContents.
private void verifyContextContents(final String cmd, String ctxCmd) throws Exception, HiveAuthzPluginException, HiveAccessControlException {
Connection hs2Conn = getConnection("user1");
Statement stmt = hs2Conn.createStatement();
stmt.execute(cmd);
stmt.close();
hs2Conn.close();
ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);
verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class), Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class), contextCapturer.capture());
HiveAuthzContext context = contextCapturer.getValue();
assertEquals("Command ", ctxCmd, context.getCommandString());
assertTrue("ip address pattern check", context.getIpAddress().matches("[.:a-fA-F0-9]+"));
// ip address size check - check for something better than non zero
assertTrue("ip address size check", context.getIpAddress().length() > 7);
}
Aggregations