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 5.2KB

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