Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

GitblitUploadPackFactory.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.manager.IAuthenticationManager;
  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. private final IAuthenticationManager authenticationManager;
  35. public GitblitUploadPackFactory(IAuthenticationManager authenticationManager) {
  36. this.authenticationManager = authenticationManager;
  37. }
  38. @Override
  39. public UploadPack create(X req, Repository db)
  40. throws ServiceNotEnabledException, ServiceNotAuthorizedException {
  41. UserModel user = UserModel.ANONYMOUS;
  42. int timeout = 0;
  43. if (req instanceof HttpServletRequest) {
  44. // http/https request may or may not be authenticated
  45. user = authenticationManager.authenticate((HttpServletRequest) req);
  46. if (user == null) {
  47. user = UserModel.ANONYMOUS;
  48. }
  49. } else if (req instanceof GitDaemonClient) {
  50. // git daemon request is always anonymous
  51. GitDaemonClient client = (GitDaemonClient) req;
  52. // set timeout from Git daemon
  53. timeout = client.getDaemon().getTimeout();
  54. }
  55. UploadPack up = new UploadPack(db);
  56. up.setTimeout(timeout);
  57. return up;
  58. }
  59. }