@Test public void loginUsingKeytab() throws Exception { File keytabFile = generateKeytab(keytabFileName, principal); Subject subject = SecurityUtil.loginUsingKeytab(principal, keytabFile); Assert.assertEquals(principal, subject.getPrincipals().iterator().next().getName()); System.out.println("Login successful for user: " + subject.getPrincipals().iterator().next()); }
public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principalConfig = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); String principal = org.apache.hadoop.security.SecurityUtil.getServerPrincipal(principalConfig, (String) null); try { SecurityUtil.loginUsingKeytab(keytabPath.getAbsolutePath(), principal); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); }
SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principalConfig = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); String principal = org.apache.hadoop.security.SecurityUtil.getServerPrincipal(principalConfig, (String) null); try { SecurityUtil.loginUsingKeytab(keytabPath.getAbsolutePath(), principal); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); } }
SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principalConfig = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); String principal = org.apache.hadoop.security.SecurityUtil.getServerPrincipal(principalConfig, (String) null); try { SecurityUtil.loginUsingKeytab(keytabPath.getAbsolutePath(), principal); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); }  }
SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principalConfig = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); String principal = org.apache.hadoop.security.SecurityUtil.getServerPrincipal(principalConfig, (String) null); try { SecurityUtil.loginUsingKeytab(keytabPath.getAbsolutePath(), principal); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); }  static synchronized Subject loginUserFromTgtTicket(String smartSecurity); static Subject loginUsingTicketCache(String principal); static void loginUsingKeytab(SmartConf conf); static void loginUsingKeytab(String keytabFilename, String principal); static Subject loginUsingKeytab(
      String principal, File keytabFile); static Configuration useTicketCache(String principal, String ticketCacheFileName); static Configuration useKeytab(String principal, File keytabFile); static boolean isSecurityEnabled(SmartConf conf); }
SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principalConfig = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); String principal = org.apache.hadoop.security.SecurityUtil.getServerPrincipal(principalConfig, (String) null); try { SecurityUtil.loginUsingKeytab(keytabPath.getAbsolutePath(), principal); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); }  static synchronized Subject loginUserFromTgtTicket(String smartSecurity); static Subject loginUsingTicketCache(String principal); static void loginUsingKeytab(SmartConf conf); static void loginUsingKeytab(String keytabFilename, String principal); static Subject loginUsingKeytab(
      String principal, File keytabFile); static Configuration useTicketCache(String principal, String ticketCacheFileName); static Configuration useKeytab(String principal, File keytabFile); static boolean isSecurityEnabled(SmartConf conf); static final Logger LOG; static final boolean ENABLE_DEBUG; }