From 41dd02a437c174ed71fd6c8b3d76000bbbcbc3bd Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 17 Jun 2014 10:54:22 -0400
Subject: [PATCH] Fix WAR web.xml generation regression
---
src/main/java/com/gitblit/manager/ServicesManager.java | 78 +++++++++++++++++++++++++++++++++++++-
1 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/gitblit/manager/ServicesManager.java b/src/main/java/com/gitblit/manager/ServicesManager.java
index f75c6d1..3721578 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;
@@ -46,6 +47,7 @@
import com.gitblit.utils.IdGenerator;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
+import com.gitblit.utils.WorkQueue;
/**
* Services manager manages long-running services/processes that either have no
@@ -65,6 +67,10 @@
private final IGitblit gitblit;
+ private final IdGenerator idGenerator;
+
+ private final WorkQueue workQueue;
+
private FanoutService fanoutService;
private GitDaemon gitDaemon;
@@ -74,6 +80,9 @@
public ServicesManager(IGitblit gitblit) {
this.settings = gitblit.getSettings();
this.gitblit = gitblit;
+ int defaultThreadPoolSize = settings.getInteger(Keys.execution.defaultThreadPoolSize, 1);
+ this.idGenerator = new IdGenerator();
+ this.workQueue = new WorkQueue(idGenerator, defaultThreadPoolSize);
}
@Override
@@ -98,7 +107,26 @@
if (sshDaemon != null) {
sshDaemon.stop();
}
+ workQueue.stop();
return this;
+ }
+
+ public boolean isServingRepositories() {
+ return isServingHTTP()
+ || isServingGIT()
+ || isServingSSH();
+ }
+
+ public boolean isServingHTTP() {
+ return settings.getBoolean(Keys.git.enableGitServlet, true);
+ }
+
+ public boolean isServingGIT() {
+ return gitDaemon != null && gitDaemon.isRunning();
+ }
+
+ public boolean isServingSSH() {
+ return sshDaemon != null && sshDaemon.isRunning();
}
protected void configureFederation() {
@@ -151,7 +179,7 @@
String bindInterface = settings.getString(Keys.git.sshBindInterface, "localhost");
if (port > 0) {
try {
- sshDaemon = new SshDaemon(gitblit, new IdGenerator());
+ sshDaemon = new SshDaemon(gitblit, workQueue);
sshDaemon.start();
} catch (IOException e) {
sshDaemon = null;
@@ -199,8 +227,8 @@
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 +254,50 @@
return AccessPermission.NONE;
}
+ public String getSshDaemonUrl(HttpServletRequest request, UserModel user, RepositoryModel repository) {
+ if (user == null || UserModel.ANONYMOUS.equals(user)) {
+ // SSH always requires authentication - anonymous access prohibited
+ return null;
+ }
+ 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;
+ }
+
+
+ /**
+ * 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 {
--
Gitblit v1.9.1