public void addUpdate(UserCredential userCredential) {
   configManager.updateXML(
       USER_CREDENTIALS_CONFIG, newAddUpdateUserCredentialsDocumentAlteration(userCredential));
   if (userCredential.getServiceKey() != null) {
     usersWithServiceKey.add(userCredential.getUsername());
   }
 }
 public String getUserCredentialByServiceKey(String serviceKey) {
   for (String usernameWithServiceKey : usersWithServiceKey) {
     UserCredential userCredential = getUserCredential(usernameWithServiceKey);
     if (userCredential != null && serviceKey.equals(userCredential.getServiceKey())) {
       return userCredential.getUsername();
     }
   }
   return null;
 }
 public List<UserCredential> getUserCredentialsInGlobalGroup(String group) {
   List<UserCredential> userCredentials = new ArrayList<>();
   for (UserCredential userCredential : getActiveUserCredentials()) {
     if (userCredential.getGlobalGroups().contains(group)) {
       userCredentials.add(userCredential);
     }
   }
   return Collections.unmodifiableList(userCredentials);
 }
 List<UserCredential> getUserCredentialsByStatus(UserCredentialStatus status) {
   List<UserCredential> userCredentials = new ArrayList<>();
   for (UserCredential userCredential : getUserCredentials()) {
     if (status == userCredential.getStatus()) {
       userCredentials.add(userCredential);
     }
   }
   return Collections.unmodifiableList(userCredentials);
 }
 public String getServiceKeyByToken(String token) {
   for (String usernameWithServiceKey : usersWithServiceKey) {
     UserCredential userCredential = getUserCredential(usernameWithServiceKey);
     if (userCredential.getTokens().containsKey(token)
         && !userCredential.getTokens().get(token).isBefore(new LocalDateTime())) {
       return userCredential.getServiceKey();
     }
   }
   return null;
 }
 public void removedTimedOutTokens() {
   for (UserCredential userCredential : getUserCredentials()) {
     UserCredential modifiedUserCredential = null;
     for (Map.Entry<String, LocalDateTime> token : userCredential.getTokens().entrySet()) {
       if (!token.getValue().isAfter(TimeProvider.getLocalDateTime())) {
         if (modifiedUserCredential == null) {
           modifiedUserCredential = userCredential;
         }
         modifiedUserCredential = modifiedUserCredential.withRemovedToken(token.getKey());
       }
     }
     if (modifiedUserCredential != null) {
       addUpdate(modifiedUserCredential);
     }
   }
 }