static void initialize(String transportMode, boolean useProperTrustedDomain) throws Exception {
    Assert.assertNotNull(transportMode);
    Assert.assertTrue(transportMode.equals(HS2_TRANSPORT_MODE_HTTP) ||
            transportMode.equals(HS2_TRANSPORT_MODE_BINARY));
    hs2TransportMode = transportMode;
    properTrustedDomain = useProperTrustedDomain;

    hiveConf = new HiveConf();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    hiveConf.writeXml(baos);
    baos.close();
    hiveConfBackup = baos.toByteArray();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_TRANSPORT_MODE, hs2TransportMode);
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_AUTHENTICATION, "CUSTOM");

    // query history adds no value to this test
    // this should be handled with HiveConfForTests when it's used here too
    hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_ENABLED, false);

    // These tests run locally and hence all connections are from localhost. So, when we want to
    // test whether trusted domain setting works, use "localhost". When we want to test
    // otherwise, use some string other than that. Other authentication tests test empty trusted
    // domain so that's not covered under these tests.
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_TRUSTED_DOMAIN,
            properTrustedDomain ? "localhost" : "no_such_domain");
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_CUSTOM_AUTHENTICATION_CLASS,
            "org.apache.hive.service.auth.TrustDomainAuthenticationTest$SimpleAuthenticationProviderImpl");
    FileOutputStream fos = new FileOutputStream(new File(hiveConf.getHiveSiteLocation().toURI()));
    hiveConf.writeXml(fos);
    fos.close();
    hiveserver2 = new HiveServer2();
    hiveserver2.init(hiveConf);
    hiveserver2.start();
    Thread.sleep(1000);
    LOG.info("hiveServer2 start ......");
  }
An abstract implementation of TrustDomainAuthentication Test.
itests/hive-unit/src/test/java/org/apache/hive/service/auth/TrustDomainAuthenticationTest.java