summaryrefslogtreecommitdiffstats
path: root/src/main/java/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-03-08 20:12:36 -0500
committerJames Moger <james.moger@gitblit.com>2014-04-10 18:58:08 -0400
commit58baee31462f6b3c60546d450e89e21b897412ce (patch)
treed9aeb3d3eeb6dc348488170be8f6c76fa46ef4e2 /src/main/java/com
parent860d2ca577520850a705298a2b19a0de0459b82e (diff)
downloadgitblit-58baee31462f6b3c60546d450e89e21b897412ce.tar.gz
gitblit-58baee31462f6b3c60546d450e89e21b897412ce.zip
Display ssh clone urls in the repository url panel
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/gitblit/GitBlit.java10
-rw-r--r--src/main/java/com/gitblit/manager/ServicesManager.java63
2 files changed, 71 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index bbc8bd37..a15bed89 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -121,6 +121,7 @@ public class GitBlit extends GitblitManager {
String username = StringUtils.encodeUsername(UserModel.ANONYMOUS.equals(user) ? "" : user.username);
List<RepositoryUrl> list = new ArrayList<RepositoryUrl>();
+
// http/https url
if (settings.getBoolean(Keys.git.enableGitServlet, true)) {
AccessPermission permission = user.getRepositoryPermission(repository).permission;
@@ -129,6 +130,15 @@ public class GitBlit extends GitblitManager {
}
}
+ // ssh daemon url
+ String sshDaemonUrl = servicesManager.getSshDaemonUrl(request, user, repository);
+ if (!StringUtils.isEmpty(sshDaemonUrl)) {
+ AccessPermission permission = servicesManager.getSshDaemonAccessPermission(user, repository);
+ if (permission.exceeds(AccessPermission.NONE)) {
+ list.add(new RepositoryUrl(sshDaemonUrl, permission));
+ }
+ }
+
// git daemon url
String gitDaemonUrl = servicesManager.getGitDaemonUrl(request, user, repository);
if (!StringUtils.isEmpty(gitDaemonUrl)) {
diff --git a/src/main/java/com/gitblit/manager/ServicesManager.java b/src/main/java/com/gitblit/manager/ServicesManager.java
index f75c6d14..1f494055 100644
--- a/src/main/java/com/gitblit/manager/ServicesManager.java
+++ b/src/main/java/com/gitblit/manager/ServicesManager.java
@@ -16,6 +16,7 @@
package com.gitblit.manager;
import java.io.IOException;
+import java.net.URI;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Date;
@@ -199,8 +200,8 @@ public class ServicesManager implements IManager {
return null;
}
if (user.canClone(repository)) {
- String servername = request.getServerName();
- String url = gitDaemon.formatUrl(servername, repository.name);
+ String hostname = getHostname(request);
+ String url = gitDaemon.formatUrl(hostname, repository.name);
return url;
}
}
@@ -226,6 +227,64 @@ public class ServicesManager implements IManager {
return AccessPermission.NONE;
}
+ public String getSshDaemonUrl(HttpServletRequest request, UserModel user, RepositoryModel repository) {
+ if (sshDaemon != null) {
+ String bindInterface = settings.getString(Keys.git.sshBindInterface, "localhost");
+ if (bindInterface.equals("localhost")
+ && (!request.getServerName().equals("localhost") && !request.getServerName().equals("127.0.0.1"))) {
+ // ssh daemon is bound to localhost and the request is from elsewhere
+ return null;
+ }
+ if (user.canClone(repository)) {
+ String hostname = getHostname(request);
+ String url = sshDaemon.formatUrl(user.username, hostname, repository.name);
+ return url;
+ }
+ }
+ return null;
+ }
+
+ public AccessPermission getSshDaemonAccessPermission(UserModel user, RepositoryModel repository) {
+ if (sshDaemon != null && user.canClone(repository)) {
+ AccessPermission sshDaemonPermission = user.getRepositoryPermission(repository).permission;
+ if (sshDaemonPermission.atLeast(AccessPermission.CLONE)) {
+ if (repository.accessRestriction.atLeast(AccessRestrictionType.CLONE)) {
+ // can not authenticate clone via anonymous ssh protocol
+ sshDaemonPermission = AccessPermission.NONE;
+ } else if (repository.accessRestriction.atLeast(AccessRestrictionType.PUSH)) {
+ // can not authenticate push via anonymous ssh protocol
+ sshDaemonPermission = AccessPermission.CLONE;
+ } else {
+ // normal user permission
+ }
+ }
+ return sshDaemonPermission;
+ }
+ return AccessPermission.NONE;
+ }
+
+ /**
+ * Extract the hostname from the canonical url or return the
+ * hostname from the servlet request.
+ *
+ * @param request
+ * @return
+ */
+ protected String getHostname(HttpServletRequest request) {
+ String hostname = request.getServerName();
+ String canonicalUrl = gitblit.getSettings().getString(Keys.web.canonicalUrl, null);
+ if (!StringUtils.isEmpty(canonicalUrl)) {
+ try {
+ URI uri = new URI(canonicalUrl);
+ String host = uri.getHost();
+ if (!StringUtils.isEmpty(host) && !"localhost".equals(host)) {
+ hostname = host;
+ }
+ } catch (Exception e) {
+ }
+ }
+ return hostname;
+ }
private class FederationPuller extends FederationPullService {