summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/manager/FederationManager.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-25 10:07:46 -0500
committerJames Moger <james.moger@gitblit.com>2013-11-29 11:05:51 -0500
commit23e08cdfd5f61e06f584c7fce4e765dd8b6e6643 (patch)
tree842bbe90d0bf15819c948f7eab8638a1f25b9132 /src/main/java/com/gitblit/manager/FederationManager.java
parent5ae529ea8a73edc8e2bb1e7f9576e51c9d870224 (diff)
downloadgitblit-23e08cdfd5f61e06f584c7fce4e765dd8b6e6643.tar.gz
gitblit-23e08cdfd5f61e06f584c7fce4e765dd8b6e6643.zip
Refactor managers and authentication for federation
Change-Id: I5ff18b2768095fb14e7fbece2e756115829abbde
Diffstat (limited to 'src/main/java/com/gitblit/manager/FederationManager.java')
-rw-r--r--src/main/java/com/gitblit/manager/FederationManager.java43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/manager/FederationManager.java b/src/main/java/com/gitblit/manager/FederationManager.java
index 568e87fc..95d38af1 100644
--- a/src/main/java/com/gitblit/manager/FederationManager.java
+++ b/src/main/java/com/gitblit/manager/FederationManager.java
@@ -17,6 +17,7 @@ package com.gitblit.manager;
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;
@@ -25,6 +26,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.FederationProposal;
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 class FederationManager implements IFederationManager {
public FederationManager(
IRuntimeManager runtimeManager,
INotificationManager notificationManager,
- IUserManager userManager,
IRepositoryManager repositoryManager) {
this.settings = runtimeManager.getSettings();
@@ -100,6 +103,17 @@ public class FederationManager implements IFederationManager {
}
@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 @@ public class FederationManager implements IFederationManager {
}
@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;
}
/**