public static void validateUrlAuthMethod()

in git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/VcsPropertiesProcessor.java [122:157]


  public static void validateUrlAuthMethod(@NotNull String url, @NotNull AuthenticationMethod authMethod, @NotNull String urlName) throws VcsException {
    url = url.toLowerCase(Locale.ROOT);
    if (url.contains("\n") || url.contains("\r"))
      throw new VcsException("Newline in " + urlName + " url '" + url + "'");

    String protocol = "";
    boolean invalid = false;
    if (url.startsWith("http://")) {
      if (authMethod.isKeyAuth()) {
        protocol = "http";
        invalid = true;
      }
    } else if (url.startsWith("https://")) {
      if (authMethod.isKeyAuth()) {
        protocol = "https";
        invalid = true;
      }
    } else if (url.startsWith("ssh://")) {
      if (!authMethod.isKeyAuth()) {
        protocol = "ssh";
        invalid = true;
      }
    } else {
      int index1 = url.indexOf('@');
      int index2 = url.indexOf(':');
      if (index1 > 0 && index2 > index1 + 1 && index2 < url.length() - 1 && !authMethod.isKeyAuth()) { // user@server:project.git
        protocol = "ssh";
        invalid = true;
      }
    }

    if (invalid) {
      throw new VcsException(String.format("The '%s' authentication method is incompatible with the '%s' protocol of the %s url", authMethod.uiName(), protocol, urlName));
    }

  }