code: protected E getValidTokenForUser(User user, Integer expirationTimeInMinutes) throws NoSuchMethodException,
          SecurityException, InstantiationException, IllegalAccessException,
          IllegalArgumentException, InvocationTargetException {
  
          // check if the user has an open reset request / not used token
          E userToken = findByUser(user);
  
          // if there is already an existing token for the user...
          if (userToken != null) {
  
              if (userToken.expiresWithin(EXPIRY_THRESHOLD_MINUTES)) {
                  LOG.debug("User already has an expired token (or at least a "
                      + "token that expires within the next "
                      + EXPIRY_THRESHOLD_MINUTES + " minutes). This token "
                      + "will be deleted.");
  
                  // delete the expired token
                  dao.delete(userToken);
              } else {
                  LOG.debug("Returning existing token for user '"
                      + user.getAccountName() + "'");
                  // return the existing and valid token
                  return userToken;
              }
  
          }
  
          userToken = buildConcreteInstance(user, expirationTimeInMinutes);
  
          // persist the user token
          dao.saveOrUpdate(userToken);
  
          final String tokenType = userToken.getClass().getSimpleName();
          LOG.debug("Successfully created a user token of type '" + tokenType
              + "' for user '" + user.getAccountName() + "'");
  
          return userToken;
      }
docs: Returns a valid (i.e. non-expired) {@link UserToken} for the given user.
  If the user already owns a valid token, it will be returned. If the user
  has an invalid/expired token, it will be deleted and a new one will be
  generated and returned by this method.
  <p>
  An expiration time in minutes can also be passed. If this value is null,
  the default value will be used.
  
  @param user                    The user that needs a token.
  @param expirationTimeInMinutes The expiration time in minutes. If null, the default value
  will be used.
  @return A valid user token.
  @throws SecurityException
  @throws NoSuchMethodException
  @throws InvocationTargetException
  @throws IllegalArgumentException
  @throws IllegalAccessException
  @throws InstantiationException