1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
* Copyright 2011 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.wicket;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.wicket.Application;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebApplication;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.manager.IAuthenticationManager;
import com.gitblit.manager.IFederationManager;
import com.gitblit.manager.IGitblit;
import com.gitblit.manager.INotificationManager;
import com.gitblit.manager.IProjectManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.pages.ActivityPage;
import com.gitblit.wicket.pages.BlamePage;
import com.gitblit.wicket.pages.BlobDiffPage;
import com.gitblit.wicket.pages.BlobPage;
import com.gitblit.wicket.pages.BranchesPage;
import com.gitblit.wicket.pages.CommitDiffPage;
import com.gitblit.wicket.pages.CommitPage;
import com.gitblit.wicket.pages.ComparePage;
import com.gitblit.wicket.pages.DocPage;
import com.gitblit.wicket.pages.DocsPage;
import com.gitblit.wicket.pages.FederationRegistrationPage;
import com.gitblit.wicket.pages.ForkPage;
import com.gitblit.wicket.pages.ForksPage;
import com.gitblit.wicket.pages.GitSearchPage;
import com.gitblit.wicket.pages.GravatarProfilePage;
import com.gitblit.wicket.pages.HistoryPage;
import com.gitblit.wicket.pages.LogPage;
import com.gitblit.wicket.pages.LogoutPage;
import com.gitblit.wicket.pages.LuceneSearchPage;
import com.gitblit.wicket.pages.MetricsPage;
import com.gitblit.wicket.pages.MyDashboardPage;
import com.gitblit.wicket.pages.OverviewPage;
import com.gitblit.wicket.pages.PatchPage;
import com.gitblit.wicket.pages.ProjectPage;
import com.gitblit.wicket.pages.ProjectsPage;
import com.gitblit.wicket.pages.RawPage;
import com.gitblit.wicket.pages.ReflogPage;
import com.gitblit.wicket.pages.RepositoriesPage;
import com.gitblit.wicket.pages.ReviewProposalPage;
import com.gitblit.wicket.pages.SummaryPage;
import com.gitblit.wicket.pages.TagPage;
import com.gitblit.wicket.pages.TagsPage;
import com.gitblit.wicket.pages.TreePage;
import com.gitblit.wicket.pages.UserPage;
import com.gitblit.wicket.pages.UsersPage;
public class GitBlitWebApp extends WebApplication {
private final Class<? extends WebPage> homePageClass = MyDashboardPage.class;
private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>();
private final IStoredSettings settings;
private final IRuntimeManager runtimeManager;
private final INotificationManager notificationManager;
private final IUserManager userManager;
private final IAuthenticationManager authenticationManager;
private final IRepositoryManager repositoryManager;
private final IProjectManager projectManager;
private final IFederationManager federationManager;
private final IGitblit gitblit;
public GitBlitWebApp(
IRuntimeManager runtimeManager,
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager,
IGitblit gitblit) {
super();
this.settings = runtimeManager.getSettings();
this.runtimeManager = runtimeManager;
this.notificationManager = notificationManager;
this.userManager = userManager;
this.authenticationManager = authenticationManager;
this.repositoryManager = repositoryManager;
this.projectManager = projectManager;
this.federationManager = federationManager;
this.gitblit = gitblit;
}
@Override
public void init() {
super.init();
// Setup page authorization mechanism
boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false)
|| settings.getBoolean(Keys.web.authenticateAdminPages, false);
if (useAuthentication) {
AuthorizationStrategy authStrategy = new AuthorizationStrategy(settings, homePageClass);
getSecuritySettings().setAuthorizationStrategy(authStrategy);
getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);
}
// Grab Browser info (like timezone, etc)
if (settings.getBoolean(Keys.web.useClientTimezone, false)) {
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}
// configure the resource cache duration to 90 days for deployment
if (!isDebugMode()) {
getResourceSettings().setDefaultCacheDuration(90 * 86400);
}
// setup the standard gitweb-ish urls
mount("/repositories", RepositoriesPage.class);
mount("/overview", OverviewPage.class, "r", "h");
mount("/summary", SummaryPage.class, "r");
mount("/reflog", ReflogPage.class, "r", "h");
mount("/commits", LogPage.class, "r", "h");
mount("/log", LogPage.class, "r", "h");
mount("/tags", TagsPage.class, "r");
mount("/branches", BranchesPage.class, "r");
mount("/commit", CommitPage.class, "r", "h");
mount("/tag", TagPage.class, "r", "h");
mount("/tree", TreePage.class, "r", "h", "f");
mount("/blob", BlobPage.class, "r", "h", "f");
mount("/raw", RawPage.class, "r", "h", "f");
mount("/blobdiff", BlobDiffPage.class, "r", "h", "f");
mount("/commitdiff", CommitDiffPage.class, "r", "h");
mount("/compare", ComparePage.class, "r", "h");
mount("/patch", PatchPage.class, "r", "h", "f");
mount("/history", HistoryPage.class, "r", "h", "f");
mount("/search", GitSearchPage.class);
mount("/metrics", MetricsPage.class, "r");
mount("/blame", BlamePage.class, "r", "h", "f");
mount("/users", UsersPage.class);
mount("/logout", LogoutPage.class);
// setup the markup document urls
mount("/docs", DocsPage.class, "r");
mount("/doc", DocPage.class, "r", "h", "f");
// federation urls
mount("/proposal", ReviewProposalPage.class, "t");
mount("/registration", FederationRegistrationPage.class, "u", "n");
mount("/activity", ActivityPage.class, "r", "h");
mount("/gravatar", GravatarProfilePage.class, "h");
mount("/lucene", LuceneSearchPage.class);
mount("/project", ProjectPage.class, "p");
mount("/projects", ProjectsPage.class);
mount("/user", UserPage.class, "user");
mount("/forks", ForksPage.class, "r");
mount("/fork", ForkPage.class, "r");
getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
super.init();
}
private void mount(String location, Class<? extends WebPage> clazz, String... parameters) {
if (parameters == null) {
parameters = new String[] {};
}
if (!settings.getBoolean(Keys.web.mountParameters, true)) {
parameters = new String[] {};
}
mount(new GitblitParamUrlCodingStrategy(settings, location, clazz, parameters));
// map the mount point to the cache control definition
if (clazz.isAnnotationPresent(CacheControl.class)) {
CacheControl cacheControl = clazz.getAnnotation(CacheControl.class);
cacheablePages.put(location.substring(1), cacheControl);
}
}
@Override
public Class<? extends WebPage> getHomePage() {
return homePageClass;
}
public boolean isCacheablePage(String mountPoint) {
return cacheablePages.containsKey(mountPoint);
}
public CacheControl getCacheControl(String mountPoint) {
return cacheablePages.get(mountPoint);
}
@Override
public final Session newSession(Request request, Response response) {
GitBlitWebSession gitBlitWebSession = new GitBlitWebSession(request);
String forcedLocale = settings.getString(Keys.web.forceDefaultLocale, null);
if (!StringUtils.isEmpty(forcedLocale)) {
gitBlitWebSession.setLocale(new Locale(forcedLocale));
}
return gitBlitWebSession;
}
public IStoredSettings settings() {
return settings;
}
/**
* Is Gitblit running in debug mode?
*
* @return true if Gitblit is running in debug mode
*/
public boolean isDebugMode() {
return runtimeManager.isDebugMode();
}
/*
* These methods look strange... and they are... but they are the first
* step towards modularization across multiple commits.
*/
public Date getBootDate() {
return runtimeManager.getBootDate();
}
public Date getLastActivityDate() {
return repositoryManager.getLastActivityDate();
}
public IRuntimeManager runtime() {
return runtimeManager;
}
public INotificationManager notifier() {
return notificationManager;
}
public IUserManager users() {
return userManager;
}
public IAuthenticationManager authentication() {
return authenticationManager;
}
public IRepositoryManager repositories() {
return repositoryManager;
}
public IProjectManager projects() {
return projectManager;
}
public IFederationManager federation() {
return federationManager;
}
public IGitblit gitblit() {
return gitblit;
}
public TimeZone getTimezone() {
return runtimeManager.getTimezone();
}
@Override
public final String getConfigurationType() {
if (runtimeManager.isDebugMode()) {
return Application.DEVELOPMENT;
}
return Application.DEPLOYMENT;
}
public static GitBlitWebApp get() {
return (GitBlitWebApp) WebApplication.get();
}
}
|