UserGroupInformation { private boolean hasSufficientTimeElapsed(long now) { if (!shouldRenewImmediatelyForTests && now - user.getLastLogin() < kerberosMinSecondsBeforeRelogin ) { LOG.warn("Not attempting to re-login since the last re-login was " + "attempted less than " + (kerberosMinSecondsBeforeRelogin/1000) + " seconds before. Last Login=" + user.getLastLogin()); return false; } return true; } UserGroupInformation(Subject subject); @VisibleForTesting static void setShouldRenewImmediatelyForTests(boolean immediate); static void reattachMetrics(); static boolean isInitialized(); @InterfaceAudience.Public @InterfaceStability.Evolving static void setConfiguration(Configuration conf); @InterfaceAudience.Private @VisibleForTesting static void reset(); static boolean isSecurityEnabled(); boolean hasKerberosCredentials(); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation getCurrentUser(); static UserGroupInformation getBestUGI(
      String ticketCachePath, String user); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation getUGIFromTicketCache(
            String ticketCache, String user); static UserGroupInformation getUGIFromSubject(Subject subject); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation getLoginUser(); static String trimLoginMethod(String userName); @InterfaceAudience.Public @InterfaceStability.Evolving static void loginUserFromSubject(Subject subject); @InterfaceAudience.Private @InterfaceStability.Unstable @VisibleForTesting static void setLoginUser(UserGroupInformation ugi); boolean isFromKeytab(); @InterfaceAudience.Private @InterfaceStability.Unstable boolean shouldRelogin(); @InterfaceAudience.Public @InterfaceStability.Evolving static void loginUserFromKeytab(String user,
                                  String path
                                  ); @InterfaceAudience.Public @InterfaceStability.Evolving void logoutUserFromKeytab(); void checkTGTAndReloginFromKeytab(); @InterfaceAudience.Public @InterfaceStability.Evolving void reloginFromKeytab(); @InterfaceAudience.Public @InterfaceStability.Evolving void forceReloginFromKeytab(); @InterfaceAudience.Public @InterfaceStability.Evolving void reloginFromTicketCache(); static UserGroupInformation loginUserFromKeytabAndReturnUGI(String user,
                                  String path
                                  ); @InterfaceAudience.Public @InterfaceStability.Evolving static boolean isLoginKeytabBased(); static boolean isLoginTicketBased(); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation createRemoteUser(String user); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation createRemoteUser(String user, AuthMethod authMethod); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation createProxyUser(String user,
      UserGroupInformation realUser); @InterfaceAudience.Public @InterfaceStability.Evolving UserGroupInformation getRealUser(); @InterfaceAudience.Public @InterfaceStability.Evolving static UserGroupInformation createUserForTesting(String user, 
                                                          String[] userGroups); static UserGroupInformation createProxyUserForTesting(String user,
      UserGroupInformation realUser, String[] userGroups); String getShortUserName(); String getPrimaryGroupName(); @InterfaceAudience.Public @InterfaceStability.Evolving String getUserName(); synchronized boolean addTokenIdentifier(TokenIdentifier tokenId); synchronized Set<TokenIdentifier> getTokenIdentifiers(); boolean addToken(Token<? extends TokenIdentifier> token); boolean addToken(Text alias, Token<? extends TokenIdentifier> token); Collection<Token<? extends TokenIdentifier>> getTokens(); Credentials getCredentials(); void addCredentials(Credentials credentials); String[] getGroupNames(); @Deprecated List<String> getGroups(); Set<String> getGroupsSet(); @Override String toString(); synchronized void setAuthenticationMethod(AuthenticationMethod authMethod); void setAuthenticationMethod(AuthMethod authMethod); synchronized AuthenticationMethod getAuthenticationMethod(); synchronized AuthenticationMethod getRealAuthenticationMethod(); static AuthenticationMethod getRealAuthenticationMethod(
      UserGroupInformation ugi); @Override boolean equals(Object o); @Override int hashCode(); @InterfaceAudience.Public @InterfaceStability.Evolving T doAs(PrivilegedAction<T> action); @InterfaceAudience.Public @InterfaceStability.Evolving T doAs(PrivilegedExceptionAction<T> action
                    ); @InterfaceAudience.LimitedPrivate({"HDFS", "KMS"}) @InterfaceStability.Unstable static void logUserInfo(Logger log, String caption,
      UserGroupInformation ugi); @InterfaceAudience.LimitedPrivate({"HDFS", "KMS"}) @InterfaceStability.Unstable static void logAllUserInfo(Logger log, UserGroupInformation ugi); static void logAllUserInfo(UserGroupInformation ugi); static void main(String [] args); static final String HADOOP_TOKEN_FILE_LOCATION; static final String HADOOP_TOKEN; }
@Test (timeout = 30000) public void testHasSufficientTimeElapsed() throws Exception { Method method = UserGroupInformation.class .getDeclaredMethod("hasSufficientTimeElapsed", long.class); method.setAccessible(true); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); User user = ugi.getSubject().getPrincipals(User.class).iterator().next(); long now = System.currentTimeMillis(); user.setLastLogin(now - 2 * 60 * 1000); assertTrue((Boolean)method.invoke(ugi, now)); user.setLastLogin(now - 30 * 1000); assertFalse((Boolean)method.invoke(ugi, now)); Configuration conf2 = new Configuration(conf); conf2.setLong( CommonConfigurationKeysPublic.HADOOP_KERBEROS_MIN_SECONDS_BEFORE_RELOGIN, 10 * 60); UserGroupInformation.setConfiguration(conf2); user.setLastLogin(now - 15 * 60 * 1000); assertTrue((Boolean)method.invoke(ugi, now)); user.setLastLogin(now - 6 * 60 * 1000); assertFalse((Boolean)method.invoke(ugi, now)); UserGroupInformation.setConfiguration(conf); method.setAccessible(false); }