@Test
  public void testUserLoginInSecureHadoop() throws Exception {
    // Default login is system user.
    UserGroupInformation defaultLogin = UserGroupInformation.getCurrentUser();

    String nnKeyTab = getKeytabFileForTesting();
    String dnPrincipal = getPrincipalForTesting();

    assertNotNull("KerberosKeytab was not specified", nnKeyTab);
    assertNotNull("KerberosPrincipal was not specified", dnPrincipal);

    Configuration conf = getSecuredConfiguration();
    UserGroupInformation.setConfiguration(conf);

    User.login(conf, HBaseKerberosUtils.KRB_KEYTAB_FILE, HBaseKerberosUtils.KRB_PRINCIPAL,
      "localhost");
    UserGroupInformation successLogin = UserGroupInformation.getLoginUser();
    assertFalse("ugi should be different in in case success login",
      defaultLogin.equals(successLogin));
  }
test login with security enabled configuration To run this test, we must specify the following
system properties:
<p>
<b> hbase.regionserver.kerberos.principal </b>
<p>
<b> hbase.regionserver.keytab.file </b>
hbase-server/src/test/java/org/apache/hadoop/hbase/security/TestUsersOperationsWithSecureHadoop.java