protected boolean validate(
      MirrorSettings ms, Settings settings, SettingsValidationErrors errors) {

    boolean result = true;
    boolean isHttp = false;

    if (ms.mirrorRepoUrl.isEmpty()) {
      result = false;
      errors.addFieldError(SETTING_MIRROR_REPO_URL + ms.suffix, "The mirror repo url is required.");
    } else {
      try {
        URI uri = URI.create(ms.mirrorRepoUrl);
        String scheme = uri.getScheme().toLowerCase();

        if (scheme.startsWith("http")) {
          isHttp = true;
          if (ms.mirrorRepoUrl.contains("@")) {
            result = false;
            errors.addFieldError(
                SETTING_MIRROR_REPO_URL + ms.suffix,
                "The username and password should not be included.");
          }
        }
      } catch (Exception ex) {
        // Not a valid url, assume it is something git can read

      }
    }

    // HTTP must have username and password
    if (isHttp) {
      if (ms.username.isEmpty()) {
        result = false;
        errors.addFieldError(
            SETTING_USERNAME + ms.suffix, "The username is required when using http(s).");
      }

      if (ms.password.isEmpty()) {
        result = false;
        errors.addFieldError(
            SETTING_PASSWORD + ms.suffix, "The password is required when using http(s).");
      }
    } else {
      // Only http should have username or password
      ms.password = ms.username = "";
    }

    return result;
  }
  protected List<MirrorSettings> getMirrorSettings(Settings settings) {

    List<MirrorSettings> results = new ArrayList<MirrorSettings>();
    Map<String, Object> allSettings = settings.asMap();
    int count = 0;

    for (String key : allSettings.keySet()) {
      if (key.startsWith(SETTING_MIRROR_REPO_URL)) {
        String suffix = key.substring(SETTING_MIRROR_REPO_URL.length());

        MirrorSettings ms = new MirrorSettings();
        ms.mirrorRepoUrl = settings.getString(SETTING_MIRROR_REPO_URL + suffix, "");
        ms.username = settings.getString(SETTING_USERNAME + suffix, "");
        ms.password = settings.getString(SETTING_PASSWORD + suffix, "");
        ms.suffix = String.valueOf(count++);

        results.add(ms);
      }
    }

    return results;
  }