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.

GitBlitWebApp.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.wicket;
  17. import org.apache.wicket.Application;
  18. import org.apache.wicket.Page;
  19. import org.apache.wicket.Request;
  20. import org.apache.wicket.Response;
  21. import org.apache.wicket.Session;
  22. import org.apache.wicket.markup.html.WebPage;
  23. import org.apache.wicket.protocol.http.WebApplication;
  24. import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;
  25. import com.gitblit.GitBlit;
  26. import com.gitblit.Keys;
  27. import com.gitblit.wicket.pages.BlobDiffPage;
  28. import com.gitblit.wicket.pages.BlobPage;
  29. import com.gitblit.wicket.pages.BranchesPage;
  30. import com.gitblit.wicket.pages.CommitDiffPage;
  31. import com.gitblit.wicket.pages.CommitPage;
  32. import com.gitblit.wicket.pages.DocsPage;
  33. import com.gitblit.wicket.pages.HistoryPage;
  34. import com.gitblit.wicket.pages.LogPage;
  35. import com.gitblit.wicket.pages.MarkdownPage;
  36. import com.gitblit.wicket.pages.PatchPage;
  37. import com.gitblit.wicket.pages.RawPage;
  38. import com.gitblit.wicket.pages.RepositoriesPage;
  39. import com.gitblit.wicket.pages.SearchPage;
  40. import com.gitblit.wicket.pages.SummaryPage;
  41. import com.gitblit.wicket.pages.TagPage;
  42. import com.gitblit.wicket.pages.TagsPage;
  43. import com.gitblit.wicket.pages.TicketPage;
  44. import com.gitblit.wicket.pages.TicketsPage;
  45. import com.gitblit.wicket.pages.TreePage;
  46. public class GitBlitWebApp extends WebApplication {
  47. @Override
  48. public void init() {
  49. super.init();
  50. // Setup page authorization mechanism
  51. boolean useAuthentication = GitBlit.getBoolean(Keys.web.authenticateViewPages, false)
  52. || GitBlit.getBoolean(Keys.web.authenticateAdminPages, false);
  53. if (useAuthentication) {
  54. AuthorizationStrategy authStrategy = new AuthorizationStrategy();
  55. getSecuritySettings().setAuthorizationStrategy(authStrategy);
  56. getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);
  57. }
  58. // Grab Browser info (like timezone, etc)
  59. if (GitBlit.getBoolean(Keys.web.useClientTimezone, false)) {
  60. getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
  61. }
  62. // setup the standard gitweb-ish urls
  63. mount("/summary", SummaryPage.class, "r");
  64. mount("/log", LogPage.class, "r", "h");
  65. mount("/tags", TagsPage.class, "r");
  66. mount("/branches", BranchesPage.class, "r");
  67. mount("/commit", CommitPage.class, "r", "h");
  68. mount("/tag", TagPage.class, "r", "h");
  69. mount("/tree", TreePage.class, "r", "h", "f");
  70. mount("/blob", BlobPage.class, "r", "h", "f");
  71. mount("/raw", RawPage.class, "r", "h", "f");
  72. mount("/blobdiff", BlobDiffPage.class, "r", "h", "f");
  73. mount("/commitdiff", CommitDiffPage.class, "r", "h");
  74. mount("/patch", PatchPage.class, "r", "h", "f");
  75. mount("/history", HistoryPage.class, "r", "h", "f");
  76. mount("/search", SearchPage.class);
  77. // setup ticket urls
  78. mount("/tickets", TicketsPage.class, "r");
  79. mount("/ticket", TicketPage.class, "r", "h", "f");
  80. // setup the markdown urls
  81. mount("/docs", DocsPage.class, "r");
  82. mount("/markdown", MarkdownPage.class, "r", "h", "f");
  83. // setup login/logout urls, if we are using authentication
  84. if (useAuthentication) {
  85. mount("/login", LoginPage.class);
  86. mount("/logout", LogoutPage.class);
  87. }
  88. }
  89. private void mount(String location, Class<? extends WebPage> clazz, String... parameters) {
  90. if (parameters == null) {
  91. parameters = new String[] {};
  92. }
  93. mount(new MixedParamUrlCodingStrategy(location, clazz, parameters));
  94. }
  95. @Override
  96. public Class<? extends Page> getHomePage() {
  97. return RepositoriesPage.class;
  98. }
  99. @Override
  100. public final Session newSession(Request request, Response response) {
  101. return new GitBlitWebSession(request);
  102. }
  103. @Override
  104. public final String getConfigurationType() {
  105. if (GitBlit.self().isDebugMode()) {
  106. return Application.DEVELOPMENT;
  107. }
  108. return Application.DEPLOYMENT;
  109. }
  110. public static GitBlitWebApp get() {
  111. return (GitBlitWebApp) WebApplication.get();
  112. }
  113. }