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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.models.UserModel;
  25. /**
  26. * The upload pack factory creates an upload pack which controls what refs are
  27. * advertised to cloning/pulling clients.
  28. *
  29. * @author James Moger
  30. *
  31. * @param <X> the connection type
  32. */
  33. public class GitblitUploadPackFactory<X> implements UploadPackFactory<X> {
  34. @Override
  35. public UploadPack create(X req, Repository db)
  36. throws ServiceNotEnabledException, ServiceNotAuthorizedException {
  37. UserModel user = UserModel.ANONYMOUS;
  38. int timeout = 0;
  39. if (req instanceof HttpServletRequest) {
  40. // http/https request may or may not be authenticated
  41. user = GitBlit.self().authenticate((HttpServletRequest) req);
  42. if (user == null) {
  43. user = UserModel.ANONYMOUS;
  44. }
  45. } else if (req instanceof GitDaemonClient) {
  46. // git daemon request is always anonymous
  47. GitDaemonClient client = (GitDaemonClient) req;
  48. // set timeout from Git daemon
  49. timeout = client.getDaemon().getTimeout();
  50. }
  51. UploadPack up = new UploadPack(db);
  52. up.setTimeout(timeout);
  53. return up;
  54. }
  55. }