From afbcba32133f1c85ef50a6515fabad2aa745b614 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 29 Sep 2014 10:01:35 -0400
Subject: [PATCH] Merge branch 'ticket/192' into develop
---
src/main/java/com/gitblit/git/GitblitReceivePackFactory.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
index b928d85..afda23b 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
@@ -15,6 +15,9 @@
*/
package com.gitblit.git;
+import java.util.HashSet;
+import java.util.Set;
+
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jgit.lib.PersonIdent;
@@ -26,13 +29,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.Constants.Transport;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.transport.git.GitDaemonClient;
-import com.gitblit.transport.ssh.SshSession;
+import com.gitblit.transport.ssh.SshDaemonClient;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.StringUtils;
@@ -66,6 +70,7 @@
String origin = "";
String gitblitUrl = "";
int timeout = 0;
+ Transport transport = null;
if (req instanceof HttpServletRequest) {
// http/https request may or may not be authenticated
@@ -82,6 +87,13 @@
user = u;
}
}
+
+ // determine the transport
+ if ("http".equals(client.getScheme())) {
+ transport = Transport.HTTP;
+ } else if ("https".equals(client.getScheme())) {
+ transport = Transport.HTTPS;
+ }
} else if (req instanceof GitDaemonClient) {
// git daemon request is always anonymous
GitDaemonClient client = (GitDaemonClient) req;
@@ -90,13 +102,20 @@
// set timeout from Git daemon
timeout = client.getDaemon().getTimeout();
- } else if (req instanceof SshSession) {
+
+ transport = Transport.GIT;
+ } else if (req instanceof SshDaemonClient) {
// SSH request is always authenticated
- SshSession client = (SshSession) req;
+ SshDaemonClient client = (SshDaemonClient) req;
repositoryName = client.getRepositoryName();
origin = client.getRemoteAddress().toString();
- String username = client.getRemoteUser();
- user = gitblit.getUserModel(username);
+ user = client.getUser();
+
+ transport = Transport.SSH;
+ }
+
+ if (!acceptPush(transport)) {
+ throw new ServiceNotAuthorizedException();
}
boolean allowAnonymousPushes = settings.getBoolean(Keys.git.allowAnonymousPushes, false);
@@ -126,4 +145,30 @@
return rp;
}
+
+ protected boolean acceptPush(Transport byTransport) {
+ if (byTransport == null) {
+ logger.info("Unknown transport, push rejected!");
+ return false;
+ }
+
+ Set<Transport> transports = new HashSet<Transport>();
+ for (String value : gitblit.getSettings().getStrings(Keys.git.acceptedPushTransports)) {
+ Transport transport = Transport.fromString(value);
+ if (transport == null) {
+ logger.info(String.format("Ignoring unknown registered transport %s", value));
+ continue;
+ }
+
+ transports.add(transport);
+ }
+
+ if (transports.isEmpty()) {
+ // no transports are explicitly specified, all are acceptable
+ return true;
+ }
+
+ // verify that the transport is permitted
+ return transports.contains(byTransport);
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1