@Test
  public void testCancelRenewTokenFlow() throws Exception {
    miniHiveKdc.loginUser(MiniHiveKdc.HIVE_TEST_SUPER_USER);
    hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL());

    // retrieve token and store in the cache
    String token = ((HiveConnection) hs2Conn)
        .getDelegationToken(MiniHiveKdc.HIVE_TEST_USER_1, MiniHiveKdc.HIVE_SERVICE_PRINCIPAL);
    assertTrue(token != null && !token.isEmpty());

    Exception ex = null;
    ((HiveConnection) hs2Conn).cancelDelegationToken(token);
    try {
      ((HiveConnection) hs2Conn).renewDelegationToken(token);
    } catch (Exception SQLException) {
      ex = SQLException;
    }
    assertTrue(ex != null && ex instanceof HiveSQLException);
    // retrieve token and store in the cache
    token = ((HiveConnection) hs2Conn)
        .getDelegationToken(MiniHiveKdc.HIVE_TEST_USER_1, MiniHiveKdc.HIVE_SERVICE_PRINCIPAL);
    assertTrue(token != null && !token.isEmpty());

    hs2Conn.close();
  }
Test token based authentication over kerberos
Login as super user and retrieve the token for normal user
use the token to connect connect as normal user
@throws Exception
itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java