@Test
  public void testAllowedCommands() throws Exception {

    // using different code blocks so that jdbc variables are not accidentally re-used
    // between the actions. Different connection/statement object should be used for each action.
    {
      // create tables as user1
      Connection hs2Conn = getConnection("user1");
      boolean caughtException = false;
      Statement stmt = hs2Conn.createStatement();
      // create tables
      try {
        stmt.execute("dfs -ls /tmp/");
      } catch (SQLException e) {
        caughtException = true;
        String msg = "Permission denied: Principal [name=user1, type=USER] does not have "
            + "following privileges for operation DFS [[ADMIN PRIVILEGE] on "
            + "Object [type=COMMAND_PARAMS, name=[-ls, /tmp/]]]";
        assertTrue("Checking content of error message:" + e.getMessage(),
            e.getMessage().contains(msg));
      } finally {
        stmt.close();
        hs2Conn.close();
      }
      assertTrue("Exception expected ", caughtException);
    }
  }
Test SQL standard authorization with jdbc/hiveserver2
itests/hive-unit/src/test/java/org/apache/hive/jdbc/authorization/TestJdbcWithSQLAuthorization.java