From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
---
src/main/java/com/gitblit/manager/FederationManager.java | 45 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/gitblit/manager/FederationManager.java b/src/main/java/com/gitblit/manager/FederationManager.java
index 07d2018..95d38af 100644
--- a/src/main/java/com/gitblit/manager/FederationManager.java
+++ b/src/main/java/com/gitblit/manager/FederationManager.java
@@ -17,6 +17,7 @@
import java.io.File;
import java.io.FileFilter;
+import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,6 +25,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +41,7 @@
import com.gitblit.models.FederationSet;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.Base64;
import com.gitblit.utils.FederationUtils;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.StringUtils;
@@ -69,7 +73,6 @@
public FederationManager(
IRuntimeManager runtimeManager,
INotificationManager notificationManager,
- IUserManager userManager,
IRepositoryManager repositoryManager) {
this.settings = runtimeManager.getSettings();
@@ -100,6 +103,17 @@
}
@Override
+ public boolean canFederate() {
+ String passphrase = settings.getString(Keys.federation.passphrase, "");
+ return !StringUtils.isEmpty(passphrase);
+ }
+
+ /**
+ * Returns the federation user account.
+ *
+ * @return the federation user account
+ */
+ @Override
public UserModel getFederationUser() {
// the federation user is an administrator
UserModel federationUser = new UserModel(Constants.FEDERATION_USER);
@@ -108,9 +122,30 @@
}
@Override
- public boolean canFederate() {
- String passphrase = settings.getString(Keys.federation.passphrase, "");
- return !StringUtils.isEmpty(passphrase);
+ public UserModel authenticate(HttpServletRequest httpRequest) {
+ if (canFederate()) {
+ // try to authenticate federation user for cloning
+ final String authorization = httpRequest.getHeader("Authorization");
+ if (authorization != null && authorization.startsWith("Basic")) {
+ // Authorization: Basic base64credentials
+ String base64Credentials = authorization.substring("Basic".length()).trim();
+ String credentials = new String(Base64.decode(base64Credentials),
+ Charset.forName("UTF-8"));
+ // credentials = username:password
+ final String[] values = credentials.split(":", 2);
+ if (values.length == 2) {
+ String username = StringUtils.decodeUsername(values[0]);
+ String password = values[1];
+ if (username.equalsIgnoreCase(Constants.FEDERATION_USER)) {
+ List<String> tokens = getFederationTokens();
+ if (tokens.contains(password)) {
+ return getFederationUser();
+ }
+ }
+ }
+ }
+ }
+ return null;
}
/**
@@ -357,7 +392,7 @@
// Determine the Gitblit clone url
StringBuilder sb = new StringBuilder();
sb.append(gitblitUrl);
- sb.append(Constants.GIT_PATH);
+ sb.append(Constants.R_PATH);
sb.append("{0}");
String cloneUrl = sb.toString();
--
Gitblit v1.9.1