Java Code Examples for org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytabAndReturnUGI()

The following are Jave code examples for showing how to use loginUserFromKeytabAndReturnUGI() of the org.apache.hadoop.security.UserGroupInformation class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hadoop-oss   File: ManualTestKeytabLogins.java   View Source Code Vote up 6 votes
public static void main(String []args) throws Exception {
  if (args.length != 4) {
    System.err.println(
      "usage: ManualTestKeytabLogins <principal 1> <keytab 1> <principal 2> <keytab 2>");
    System.exit(1);
  }

  UserGroupInformation ugi1 =
    UserGroupInformation.loginUserFromKeytabAndReturnUGI(
      args[0], args[1]);
  System.out.println("UGI 1 = " + ugi1);
  assertTrue(ugi1.getUserName().equals(args[0]));
  
  UserGroupInformation ugi2 =
    UserGroupInformation.loginUserFromKeytabAndReturnUGI(
      args[2], args[3]);
  System.out.println("UGI 2 = " + ugi2);
  assertTrue(ugi2.getUserName().equals(args[2]));
}
 
Example 2
Project: hadoop   File: ManualTestKeytabLogins.java   View Source Code Vote up 6 votes
public static void main(String []args) throws Exception {
  if (args.length != 4) {
    System.err.println(
      "usage: ManualTestKeytabLogins <principal 1> <keytab 1> <principal 2> <keytab 2>");
    System.exit(1);
  }

  UserGroupInformation ugi1 =
    UserGroupInformation.loginUserFromKeytabAndReturnUGI(
      args[0], args[1]);
  System.out.println("UGI 1 = " + ugi1);
  assertTrue(ugi1.getUserName().equals(args[0]));
  
  UserGroupInformation ugi2 =
    UserGroupInformation.loginUserFromKeytabAndReturnUGI(
      args[2], args[3]);
  System.out.println("UGI 2 = " + ugi2);
  assertTrue(ugi2.getUserName().equals(args[2]));
}
 
Example 3
Project: ditb   File: LoadTestTool.java   View Source Code Vote up 5 votes
public static UserGroupInformation loginAndReturnUGI(Configuration conf, String username)
    throws IOException {
  String hostname = InetAddress.getLocalHost().getHostName();
  String keyTabFileConfKey = "hbase." + username + ".keytab.file";
  String keyTabFileLocation = conf.get(keyTabFileConfKey);
  String principalConfKey = "hbase." + username + ".kerberos.principal";
  String principal = SecurityUtil.getServerPrincipal(conf.get(principalConfKey), hostname);
  if (keyTabFileLocation == null || principal == null) {
    LOG.warn("Principal or key tab file null for : " + principalConfKey + ", "
        + keyTabFileConfKey);
  }
  UserGroupInformation ugi =
      UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keyTabFileLocation);
  return ugi;
}
 
Example 4
Project: hadoop   File: RegistryTestHelper.java   View Source Code Vote up 3 votes
/**
 * Login via a UGI. Requres UGI to have been set up
 * @param user username
 * @param keytab keytab to list
 * @return the UGI
 * @throws IOException
 */
public static UserGroupInformation loginUGI(String user, File keytab) throws
    IOException {
  LOG.info("Logging in as {} from {}", user, keytab);
  return UserGroupInformation.loginUserFromKeytabAndReturnUGI(user,
      keytab.getAbsolutePath());
}