@Test public void testReloginFromKeytabNoopForNonKeytab() throws KerberosAuthException { user.setLogin(mockLoginContext); PowerMockito.mockStatic(KerberosUtil.class); when(KerberosUtil.hasKerberosKeyTab(subject)).thenReturn(false); ugi = new UserGroupInformation(subject); ugi.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS); session = new LoginSession("config", "principal", "keytab", ugi, subject, 1); PxfUserGroupInformation.reloginFromKeytab(serverName, session); verifyZeroInteractions(mockLoginContext); }
public static void reloginFromKeytab(String serverName, LoginSession loginSession) throws KerberosAuthException { UserGroupInformation ugi = loginSession.getLoginUser(); if (ugi.getAuthenticationMethod() != UserGroupInformation.AuthenticationMethod.KERBEROS || !ugi.isFromKeytab()) { LOG.error("Did not attempt to relogin from keytab: auth={}, fromKeyTab={}", ugi.getAuthenticationMethod(), ugi.isFromKeytab()); return; } synchronized (loginSession) { long now = Time.now(); if (!hasSufficientTimeElapsed(now, loginSession)) { return; } Subject subject = loginSession.getSubject(); KerberosTicket tgt = getTGT(subject); if (tgt != null && now < getRefreshTime(tgt)) { return; } User user = loginSession.getUser(); LoginContext login = user.getLogin(); String keytabFile = loginSession.getKeytabPath(); String keytabPrincipal = loginSession.getPrincipalName(); if (login == null || keytabFile == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } user.setLastLogin(now); try { LOG.debug("Initiating logout for {}", user.getName()); synchronized (UserGroupInformation.class) { login.logout(); login = newLoginContext( HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject, new HadoopConfiguration(keytabPrincipal, keytabFile)); LOG.info("Initiating re-login for {} for server {}", keytabPrincipal, serverName); login.login(); fixKerberosTicketOrder(subject); user.setLogin(login); } } catch (LoginException le) { KerberosAuthException kae = new KerberosAuthException(LOGIN_FAILURE, le); kae.setPrincipal(keytabPrincipal); kae.setKeytabFile(keytabFile); throw kae; } trackEventPerServer(serverName, reloginCountMap); } logStatistics(serverName); }
PxfUserGroupInformation { public static void reloginFromKeytab(String serverName, LoginSession loginSession) throws KerberosAuthException { UserGroupInformation ugi = loginSession.getLoginUser(); if (ugi.getAuthenticationMethod() != UserGroupInformation.AuthenticationMethod.KERBEROS || !ugi.isFromKeytab()) { LOG.error("Did not attempt to relogin from keytab: auth={}, fromKeyTab={}", ugi.getAuthenticationMethod(), ugi.isFromKeytab()); return; } synchronized (loginSession) { long now = Time.now(); if (!hasSufficientTimeElapsed(now, loginSession)) { return; } Subject subject = loginSession.getSubject(); KerberosTicket tgt = getTGT(subject); if (tgt != null && now < getRefreshTime(tgt)) { return; } User user = loginSession.getUser(); LoginContext login = user.getLogin(); String keytabFile = loginSession.getKeytabPath(); String keytabPrincipal = loginSession.getPrincipalName(); if (login == null || keytabFile == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } user.setLastLogin(now); try { LOG.debug("Initiating logout for {}", user.getName()); synchronized (UserGroupInformation.class) { login.logout(); login = newLoginContext( HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject, new HadoopConfiguration(keytabPrincipal, keytabFile)); LOG.info("Initiating re-login for {} for server {}", keytabPrincipal, serverName); login.login(); fixKerberosTicketOrder(subject); user.setLogin(login); } } catch (LoginException le) { KerberosAuthException kae = new KerberosAuthException(LOGIN_FAILURE, le); kae.setPrincipal(keytabPrincipal); kae.setKeytabFile(keytabFile); throw kae; } trackEventPerServer(serverName, reloginCountMap); } logStatistics(serverName); } }
PxfUserGroupInformation { public static void reloginFromKeytab(String serverName, LoginSession loginSession) throws KerberosAuthException { UserGroupInformation ugi = loginSession.getLoginUser(); if (ugi.getAuthenticationMethod() != UserGroupInformation.AuthenticationMethod.KERBEROS || !ugi.isFromKeytab()) { LOG.error("Did not attempt to relogin from keytab: auth={}, fromKeyTab={}", ugi.getAuthenticationMethod(), ugi.isFromKeytab()); return; } synchronized (loginSession) { long now = Time.now(); if (!hasSufficientTimeElapsed(now, loginSession)) { return; } Subject subject = loginSession.getSubject(); KerberosTicket tgt = getTGT(subject); if (tgt != null && now < getRefreshTime(tgt)) { return; } User user = loginSession.getUser(); LoginContext login = user.getLogin(); String keytabFile = loginSession.getKeytabPath(); String keytabPrincipal = loginSession.getPrincipalName(); if (login == null || keytabFile == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } user.setLastLogin(now); try { LOG.debug("Initiating logout for {}", user.getName()); synchronized (UserGroupInformation.class) { login.logout(); login = newLoginContext( HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject, new HadoopConfiguration(keytabPrincipal, keytabFile)); LOG.info("Initiating re-login for {} for server {}", keytabPrincipal, serverName); login.login(); fixKerberosTicketOrder(subject); user.setLogin(login); } } catch (LoginException le) { KerberosAuthException kae = new KerberosAuthException(LOGIN_FAILURE, le); kae.setPrincipal(keytabPrincipal); kae.setKeytabFile(keytabFile); throw kae; } trackEventPerServer(serverName, reloginCountMap); } logStatistics(serverName); }  }
PxfUserGroupInformation { public static void reloginFromKeytab(String serverName, LoginSession loginSession) throws KerberosAuthException { UserGroupInformation ugi = loginSession.getLoginUser(); if (ugi.getAuthenticationMethod() != UserGroupInformation.AuthenticationMethod.KERBEROS || !ugi.isFromKeytab()) { LOG.error("Did not attempt to relogin from keytab: auth={}, fromKeyTab={}", ugi.getAuthenticationMethod(), ugi.isFromKeytab()); return; } synchronized (loginSession) { long now = Time.now(); if (!hasSufficientTimeElapsed(now, loginSession)) { return; } Subject subject = loginSession.getSubject(); KerberosTicket tgt = getTGT(subject); if (tgt != null && now < getRefreshTime(tgt)) { return; } User user = loginSession.getUser(); LoginContext login = user.getLogin(); String keytabFile = loginSession.getKeytabPath(); String keytabPrincipal = loginSession.getPrincipalName(); if (login == null || keytabFile == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } user.setLastLogin(now); try { LOG.debug("Initiating logout for {}", user.getName()); synchronized (UserGroupInformation.class) { login.logout(); login = newLoginContext( HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject, new HadoopConfiguration(keytabPrincipal, keytabFile)); LOG.info("Initiating re-login for {} for server {}", keytabPrincipal, serverName); login.login(); fixKerberosTicketOrder(subject); user.setLogin(login); } } catch (LoginException le) { KerberosAuthException kae = new KerberosAuthException(LOGIN_FAILURE, le); kae.setPrincipal(keytabPrincipal); kae.setKeytabFile(keytabFile); throw kae; } trackEventPerServer(serverName, reloginCountMap); } logStatistics(serverName); }  synchronized static LoginSession loginUserFromKeytab(Configuration configuration, String serverName, String configDirectory, String principal, String keytabFilename); static void reloginFromKeytab(String serverName, LoginSession loginSession); static long getKerberosMinMillisBeforeRelogin(String serverName, Configuration configuration); }
PxfUserGroupInformation { public static void reloginFromKeytab(String serverName, LoginSession loginSession) throws KerberosAuthException { UserGroupInformation ugi = loginSession.getLoginUser(); if (ugi.getAuthenticationMethod() != UserGroupInformation.AuthenticationMethod.KERBEROS || !ugi.isFromKeytab()) { LOG.error("Did not attempt to relogin from keytab: auth={}, fromKeyTab={}", ugi.getAuthenticationMethod(), ugi.isFromKeytab()); return; } synchronized (loginSession) { long now = Time.now(); if (!hasSufficientTimeElapsed(now, loginSession)) { return; } Subject subject = loginSession.getSubject(); KerberosTicket tgt = getTGT(subject); if (tgt != null && now < getRefreshTime(tgt)) { return; } User user = loginSession.getUser(); LoginContext login = user.getLogin(); String keytabFile = loginSession.getKeytabPath(); String keytabPrincipal = loginSession.getPrincipalName(); if (login == null || keytabFile == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } user.setLastLogin(now); try { LOG.debug("Initiating logout for {}", user.getName()); synchronized (UserGroupInformation.class) { login.logout(); login = newLoginContext( HadoopConfiguration.KEYTAB_KERBEROS_CONFIG_NAME, subject, new HadoopConfiguration(keytabPrincipal, keytabFile)); LOG.info("Initiating re-login for {} for server {}", keytabPrincipal, serverName); login.login(); fixKerberosTicketOrder(subject); user.setLogin(login); } } catch (LoginException le) { KerberosAuthException kae = new KerberosAuthException(LOGIN_FAILURE, le); kae.setPrincipal(keytabPrincipal); kae.setKeytabFile(keytabFile); throw kae; } trackEventPerServer(serverName, reloginCountMap); } logStatistics(serverName); }  synchronized static LoginSession loginUserFromKeytab(Configuration configuration, String serverName, String configDirectory, String principal, String keytabFilename); static void reloginFromKeytab(String serverName, LoginSession loginSession); static long getKerberosMinMillisBeforeRelogin(String serverName, Configuration configuration);  }