Return null as URL for SshScheme if user has no username

For SSH a username is required and returning null in this case is
better than returning an invalid URL. A null URL is already handled as
'scheme not available'.

At the moment in case of SSH the client makes an extra check whether
the user has an username and if not the SSH scheme is skipped.

Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
Change-Id: I827af45929ea34a490f52658c67a13cd4591dd27
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
index 8253b66..6e7cb15 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
@@ -17,6 +17,7 @@
 import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme.DEFAULT_DOWNLOADS;
 import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme.SSH;
 
+import com.google.common.base.Strings;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.extensions.config.DownloadScheme;
 import com.google.gerrit.server.CurrentUser;
@@ -59,10 +60,14 @@
     if (!isEnabled() || !userProvider.get().isIdentifiedUser()) {
       return null;
     }
+    String username = userProvider.get().getUserName();
+    if (Strings.isNullOrEmpty(username)) {
+      return null;
+    }
 
     StringBuilder r = new StringBuilder();
     r.append("ssh://");
-    r.append(userProvider.get().getUserName());
+    r.append(username);
     r.append("@");
     r.append(ensureSlash(sshdAddress));
     r.append(project);
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index e4eae75..f5b697e 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -16,6 +16,8 @@
 * `HTTP`: Scheme for authenticated downloads via the HTTP protocol.
 
 * `SSH`: Scheme for authenticated downloads via the SSH protocol.
+<br />
+Requires that users have a username.
 
 * `REPO`: Scheme for downloading with the Repo tool.