David Ostrovsky
2014-03-11 b799d545f37f7123aaa1ee1d0ff3b61f1f3cc8c2
src/main/java/com/gitblit/git/GitblitUploadPackFactory.java
@@ -23,8 +23,10 @@
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import com.gitblit.GitBlit;
import com.gitblit.manager.IAuthenticationManager;
import com.gitblit.models.UserModel;
import com.gitblit.transport.git.GitDaemonClient;
import com.gitblit.transport.ssh.SshSession;
/**
 * The upload pack factory creates an upload pack which controls what refs are
@@ -36,6 +38,12 @@
 */
public class GitblitUploadPackFactory<X> implements UploadPackFactory<X> {
   private final IAuthenticationManager authenticationManager;
   public GitblitUploadPackFactory(IAuthenticationManager authenticationManager) {
      this.authenticationManager = authenticationManager;
   }
   @Override
   public UploadPack create(X req, Repository db)
         throws ServiceNotEnabledException, ServiceNotAuthorizedException {
@@ -45,7 +53,8 @@
      if (req instanceof HttpServletRequest) {
         // http/https request may or may not be authenticated
         user = GitBlit.self().authenticate((HttpServletRequest) req);
         HttpServletRequest client = (HttpServletRequest) req;
         user = authenticationManager.authenticate(client);
         if (user == null) {
            user = UserModel.ANONYMOUS;
         }
@@ -54,6 +63,13 @@
         GitDaemonClient client = (GitDaemonClient) req;
         // set timeout from Git daemon
         timeout = client.getDaemon().getTimeout();
      } else if (req instanceof SshSession) {
         // SSH request is always authenticated
         SshSession client = (SshSession) req;
         user = authenticationManager.authenticate(client);
         if (user == null) {
            throw new ServiceNotAuthorizedException();
         }
      }
      UploadPack up = new UploadPack(db);