You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitblitUploadPackFactory.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.git;
  17. import javax.servlet.http.HttpServletRequest;
  18. import org.eclipse.jgit.lib.Repository;
  19. import org.eclipse.jgit.transport.UploadPack;
  20. import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
  21. import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
  22. import org.eclipse.jgit.transport.resolver.UploadPackFactory;
  23. import com.gitblit.GitBlit;
  24. import com.gitblit.manager.ISessionManager;
  25. import com.gitblit.models.UserModel;
  26. /**
  27. * The upload pack factory creates an upload pack which controls what refs are
  28. * advertised to cloning/pulling clients.
  29. *
  30. * @author James Moger
  31. *
  32. * @param <X> the connection type
  33. */
  34. public class GitblitUploadPackFactory<X> implements UploadPackFactory<X> {
  35. @Override
  36. public UploadPack create(X req, Repository db)
  37. throws ServiceNotEnabledException, ServiceNotAuthorizedException {
  38. ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
  39. UserModel user = UserModel.ANONYMOUS;
  40. int timeout = 0;
  41. if (req instanceof HttpServletRequest) {
  42. // http/https request may or may not be authenticated
  43. user = sessionManager.authenticate((HttpServletRequest) req);
  44. if (user == null) {
  45. user = UserModel.ANONYMOUS;
  46. }
  47. } else if (req instanceof GitDaemonClient) {
  48. // git daemon request is always anonymous
  49. GitDaemonClient client = (GitDaemonClient) req;
  50. // set timeout from Git daemon
  51. timeout = client.getDaemon().getTimeout();
  52. }
  53. UploadPack up = new UploadPack(db);
  54. up.setTimeout(timeout);
  55. return up;
  56. }
  57. }