commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
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 |
*/
|
5fe7df
|
16 |
package com.gitblit;
|
JM |
17 |
|
20714a
|
18 |
import java.lang.annotation.Documented;
|
JM |
19 |
import java.lang.annotation.Retention;
|
|
20 |
import java.lang.annotation.RetentionPolicy;
|
f6b200
|
21 |
import java.net.URL;
|
JM |
22 |
import java.util.jar.Attributes;
|
|
23 |
import java.util.jar.Manifest;
|
d896e6
|
24 |
|
892570
|
25 |
/**
|
JM |
26 |
* Constant values used by Gitblit.
|
|
27 |
*
|
|
28 |
* @author James Moger
|
|
29 |
*
|
|
30 |
*/
|
5fe7df
|
31 |
public class Constants {
|
JM |
32 |
|
2a7306
|
33 |
public static final String NAME = "Gitblit";
|
5fe7df
|
34 |
|
2a7306
|
35 |
public static final String FULL_NAME = "Gitblit - a pure Java Git solution";
|
155bf7
|
36 |
|
2a7306
|
37 |
public static final String ADMIN_ROLE = "#admin";
|
1e1b85
|
38 |
|
JM |
39 |
public static final String FORK_ROLE = "#fork";
|
6662e3
|
40 |
|
JM |
41 |
public static final String CREATE_ROLE = "#create";
|
2a7306
|
42 |
|
831469
|
43 |
public static final String NOT_FEDERATED_ROLE = "#notfederated";
|
ce2a40
|
44 |
|
JM |
45 |
public static final String NO_ROLE = "#none";
|
831469
|
46 |
|
2a7306
|
47 |
public static final String PROPERTIES_FILE = "gitblit.properties";
|
JM |
48 |
|
5450d0
|
49 |
public static final String GIT_PATH = "/git/";
|
2a7306
|
50 |
|
5450d0
|
51 |
public static final String ZIP_PATH = "/zip/";
|
85c2e6
|
52 |
|
5450d0
|
53 |
public static final String SYNDICATION_PATH = "/feed/";
|
85c2e6
|
54 |
|
831469
|
55 |
public static final String FEDERATION_PATH = "/federation/";
|
31abc2
|
56 |
|
93f0b1
|
57 |
public static final String RPC_PATH = "/rpc/";
|
6d874a
|
58 |
|
b7502e
|
59 |
public static final String PAGES = "/pages/";
|
JM |
60 |
|
|
61 |
public static final String SPARKLESHARE_INVITE_PATH = "/sparkleshare/";
|
831469
|
62 |
|
1f9dae
|
63 |
public static final String BORDER = "***********************************************************";
|
db653a
|
64 |
|
831469
|
65 |
public static final String FEDERATION_USER = "$gitblit";
|
JM |
66 |
|
|
67 |
public static final String PROPOSAL_EXT = ".json";
|
6d874a
|
68 |
|
JM |
69 |
public static final String ENCODING = "UTF-8";
|
|
70 |
|
75705a
|
71 |
public static final int LEN_SHORTLOG = 78;
|
a45caa
|
72 |
|
JM |
73 |
public static final int LEN_SHORTLOG_REFS = 60;
|
|
74 |
|
1aabf0
|
75 |
public static final String DEFAULT_BRANCH = "default";
|
JM |
76 |
|
380afa
|
77 |
public static final String CONFIG_GITBLIT = "gitblit";
|
4a5a55
|
78 |
|
380afa
|
79 |
public static final String CONFIG_CUSTOM_FIELDS = "customFields";
|
4a5a55
|
80 |
|
e92c6d
|
81 |
public static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ssZ";
|
JM |
82 |
|
f8bb95
|
83 |
public static final String R_GITBLIT = "refs/gitblit/";
|
JM |
84 |
|
93d506
|
85 |
public static final String baseFolder = "baseFolder";
|
JM |
86 |
|
|
87 |
public static final String baseFolder$ = "${" + baseFolder + "}";
|
|
88 |
|
|
89 |
public static final String contextFolder$ = "${contextFolder}";
|
f6b200
|
90 |
|
JM |
91 |
public static String getVersion() {
|
|
92 |
String v = Constants.class.getPackage().getImplementationVersion();
|
|
93 |
if (v == null) {
|
|
94 |
return "0.0.0-SNAPSHOT";
|
|
95 |
}
|
|
96 |
return v;
|
|
97 |
}
|
|
98 |
|
831469
|
99 |
public static String getGitBlitVersion() {
|
f6b200
|
100 |
return NAME + " v" + getVersion();
|
JM |
101 |
}
|
|
102 |
|
|
103 |
public static String getBuildDate() {
|
|
104 |
return getManifestValue("build-date", "PENDING");
|
|
105 |
}
|
|
106 |
|
|
107 |
private static String getManifestValue(String attrib, String defaultValue) {
|
|
108 |
Class<?> clazz = Constants.class;
|
|
109 |
String className = clazz.getSimpleName() + ".class";
|
|
110 |
String classPath = clazz.getResource(className).toString();
|
|
111 |
if (!classPath.startsWith("jar")) {
|
|
112 |
// Class not from JAR
|
|
113 |
return defaultValue;
|
|
114 |
}
|
|
115 |
try {
|
|
116 |
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
|
|
117 |
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
|
|
118 |
Attributes attr = manifest.getMainAttributes();
|
|
119 |
String value = attr.getValue(attrib);
|
|
120 |
return value;
|
|
121 |
} catch (Exception e) {
|
|
122 |
}
|
|
123 |
return defaultValue;
|
831469
|
124 |
}
|
93d506
|
125 |
|
88598b
|
126 |
/**
|
831469
|
127 |
* Enumeration representing the four access restriction levels.
|
88598b
|
128 |
*/
|
dfb889
|
129 |
public static enum AccessRestrictionType {
|
JM |
130 |
NONE, PUSH, CLONE, VIEW;
|
|
131 |
|
d0d438
|
132 |
public static AccessRestrictionType fromName(String name) {
|
dfb889
|
133 |
for (AccessRestrictionType type : values()) {
|
d0d438
|
134 |
if (type.name().equalsIgnoreCase(name)) {
|
dfb889
|
135 |
return type;
|
JM |
136 |
}
|
|
137 |
}
|
|
138 |
return NONE;
|
|
139 |
}
|
f98825
|
140 |
|
JM |
141 |
public boolean exceeds(AccessRestrictionType type) {
|
|
142 |
return this.ordinal() > type.ordinal();
|
|
143 |
}
|
|
144 |
|
dfb889
|
145 |
public boolean atLeast(AccessRestrictionType type) {
|
JM |
146 |
return this.ordinal() >= type.ordinal();
|
|
147 |
}
|
|
148 |
|
|
149 |
public String toString() {
|
f98825
|
150 |
return name();
|
dfb889
|
151 |
}
|
9a6a42
|
152 |
|
JM |
153 |
public boolean isValidPermission(AccessPermission permission) {
|
|
154 |
switch (this) {
|
|
155 |
case VIEW:
|
|
156 |
// VIEW restriction
|
|
157 |
// all access permissions are valid
|
|
158 |
return true;
|
|
159 |
case CLONE:
|
|
160 |
// CLONE restriction
|
|
161 |
// only CLONE or greater access permissions are valid
|
|
162 |
return permission.atLeast(AccessPermission.CLONE);
|
|
163 |
case PUSH:
|
|
164 |
// PUSH restriction
|
|
165 |
// only PUSH or greater access permissions are valid
|
|
166 |
return permission.atLeast(AccessPermission.PUSH);
|
|
167 |
case NONE:
|
|
168 |
// NO access restriction
|
|
169 |
// all access permissions are invalid
|
|
170 |
return false;
|
|
171 |
}
|
|
172 |
return false;
|
|
173 |
}
|
dfb889
|
174 |
}
|
6adf56
|
175 |
|
JM |
176 |
/**
|
|
177 |
* Enumeration representing the types of authorization control for an
|
|
178 |
* access restricted resource.
|
|
179 |
*/
|
|
180 |
public static enum AuthorizationControl {
|
|
181 |
AUTHENTICATED, NAMED;
|
|
182 |
|
|
183 |
public static AuthorizationControl fromName(String name) {
|
|
184 |
for (AuthorizationControl type : values()) {
|
|
185 |
if (type.name().equalsIgnoreCase(name)) {
|
|
186 |
return type;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
return NAMED;
|
|
190 |
}
|
|
191 |
|
|
192 |
public String toString() {
|
|
193 |
return name();
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
dfb889
|
197 |
|
831469
|
198 |
/**
|
JM |
199 |
* Enumeration representing the types of federation tokens.
|
|
200 |
*/
|
|
201 |
public static enum FederationToken {
|
|
202 |
ALL, USERS_AND_REPOSITORIES, REPOSITORIES;
|
|
203 |
|
|
204 |
public static FederationToken fromName(String name) {
|
|
205 |
for (FederationToken type : values()) {
|
|
206 |
if (type.name().equalsIgnoreCase(name)) {
|
|
207 |
return type;
|
|
208 |
}
|
|
209 |
}
|
|
210 |
return REPOSITORIES;
|
|
211 |
}
|
|
212 |
|
|
213 |
public String toString() {
|
|
214 |
return name();
|
|
215 |
}
|
5fe7df
|
216 |
}
|
831469
|
217 |
|
JM |
218 |
/**
|
|
219 |
* Enumeration representing the types of federation requests.
|
|
220 |
*/
|
|
221 |
public static enum FederationRequest {
|
df162c
|
222 |
POKE, PROPOSAL, PULL_REPOSITORIES, PULL_USERS, PULL_TEAMS, PULL_SETTINGS, PULL_SCRIPTS, STATUS;
|
831469
|
223 |
|
JM |
224 |
public static FederationRequest fromName(String name) {
|
|
225 |
for (FederationRequest type : values()) {
|
|
226 |
if (type.name().equalsIgnoreCase(name)) {
|
|
227 |
return type;
|
|
228 |
}
|
|
229 |
}
|
|
230 |
return PULL_REPOSITORIES;
|
|
231 |
}
|
|
232 |
|
|
233 |
public String toString() {
|
|
234 |
return name();
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
/**
|
|
239 |
* Enumeration representing the statii of federation requests.
|
|
240 |
*/
|
|
241 |
public static enum FederationPullStatus {
|
c729c5
|
242 |
PENDING, FAILED, SKIPPED, PULLED, MIRRORED, NOCHANGE, EXCLUDED;
|
831469
|
243 |
|
JM |
244 |
public static FederationPullStatus fromName(String name) {
|
|
245 |
for (FederationPullStatus type : values()) {
|
|
246 |
if (type.name().equalsIgnoreCase(name)) {
|
|
247 |
return type;
|
|
248 |
}
|
|
249 |
}
|
|
250 |
return PENDING;
|
|
251 |
}
|
|
252 |
|
|
253 |
@Override
|
|
254 |
public String toString() {
|
|
255 |
return name();
|
|
256 |
}
|
|
257 |
}
|
8f73a7
|
258 |
|
831469
|
259 |
/**
|
JM |
260 |
* Enumeration representing the federation types.
|
|
261 |
*/
|
|
262 |
public static enum FederationStrategy {
|
|
263 |
EXCLUDE, FEDERATE_THIS, FEDERATE_ORIGIN;
|
|
264 |
|
|
265 |
public static FederationStrategy fromName(String name) {
|
|
266 |
for (FederationStrategy type : values()) {
|
|
267 |
if (type.name().equalsIgnoreCase(name)) {
|
|
268 |
return type;
|
|
269 |
}
|
|
270 |
}
|
|
271 |
return FEDERATE_THIS;
|
|
272 |
}
|
|
273 |
|
8f73a7
|
274 |
public boolean exceeds(FederationStrategy type) {
|
JM |
275 |
return this.ordinal() > type.ordinal();
|
|
276 |
}
|
|
277 |
|
|
278 |
public boolean atLeast(FederationStrategy type) {
|
|
279 |
return this.ordinal() >= type.ordinal();
|
|
280 |
}
|
|
281 |
|
831469
|
282 |
@Override
|
JM |
283 |
public String toString() {
|
|
284 |
return name();
|
|
285 |
}
|
|
286 |
}
|
|
287 |
|
4aafd4
|
288 |
/**
|
JM |
289 |
* Enumeration representing the possible results of federation proposal
|
|
290 |
* requests.
|
|
291 |
*/
|
|
292 |
public static enum FederationProposalResult {
|
|
293 |
ERROR, FEDERATION_DISABLED, MISSING_DATA, NO_PROPOSALS, NO_POKE, ACCEPTED;
|
|
294 |
|
|
295 |
@Override
|
|
296 |
public String toString() {
|
|
297 |
return name();
|
|
298 |
}
|
|
299 |
}
|
93f0b1
|
300 |
|
JM |
301 |
/**
|
|
302 |
* Enumeration representing the possible remote procedure call requests from
|
|
303 |
* a client.
|
|
304 |
*/
|
|
305 |
public static enum RpcRequest {
|
ec5a88
|
306 |
// Order is important here. anything above LIST_SETTINGS requires
|
JM |
307 |
// administrator privileges and web.allowRpcManagement.
|
4ebaf6
|
308 |
CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS,
|
f08aab
|
309 |
CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
|
JM |
310 |
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER,
|
|
311 |
LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,
|
|
312 |
LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS,
|
822dfe
|
313 |
LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS,
|
f08aab
|
314 |
LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
|
4ebaf6
|
315 |
EDIT_SETTINGS, LIST_STATUS;
|
31abc2
|
316 |
|
93f0b1
|
317 |
public static RpcRequest fromName(String name) {
|
JM |
318 |
for (RpcRequest type : values()) {
|
|
319 |
if (type.name().equalsIgnoreCase(name)) {
|
|
320 |
return type;
|
|
321 |
}
|
|
322 |
}
|
b2fde8
|
323 |
return null;
|
ec5a88
|
324 |
}
|
31abc2
|
325 |
|
ca9d0f
|
326 |
public boolean exceeds(RpcRequest type) {
|
JM |
327 |
return this.ordinal() > type.ordinal();
|
|
328 |
}
|
31abc2
|
329 |
|
93f0b1
|
330 |
@Override
|
JM |
331 |
public String toString() {
|
|
332 |
return name();
|
|
333 |
}
|
|
334 |
}
|
33d8d8
|
335 |
|
JM |
336 |
/**
|
|
337 |
* Enumeration of the search types.
|
|
338 |
*/
|
|
339 |
public static enum SearchType {
|
|
340 |
AUTHOR, COMMITTER, COMMIT;
|
|
341 |
|
|
342 |
public static SearchType forName(String name) {
|
|
343 |
for (SearchType type : values()) {
|
|
344 |
if (type.name().equalsIgnoreCase(name)) {
|
|
345 |
return type;
|
|
346 |
}
|
|
347 |
}
|
|
348 |
return COMMIT;
|
|
349 |
}
|
|
350 |
|
|
351 |
@Override
|
|
352 |
public String toString() {
|
|
353 |
return name().toLowerCase();
|
|
354 |
}
|
|
355 |
}
|
d896e6
|
356 |
|
JM |
357 |
/**
|
|
358 |
* The types of objects that can be indexed and queried.
|
|
359 |
*/
|
|
360 |
public static enum SearchObjectType {
|
|
361 |
commit, blob, issue;
|
|
362 |
|
|
363 |
static SearchObjectType fromName(String name) {
|
|
364 |
for (SearchObjectType value : values()) {
|
|
365 |
if (value.name().equals(name)) {
|
|
366 |
return value;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
return null;
|
|
370 |
}
|
|
371 |
}
|
20714a
|
372 |
|
JM |
373 |
/**
|
|
374 |
* The access permissions available for a repository.
|
|
375 |
*/
|
|
376 |
public static enum AccessPermission {
|
7ba85b
|
377 |
NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");
|
20714a
|
378 |
|
2d48e2
|
379 |
public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };
|
b0e164
|
380 |
|
20714a
|
381 |
public static AccessPermission LEGACY = REWIND;
|
JM |
382 |
|
|
383 |
public final String code;
|
|
384 |
|
|
385 |
private AccessPermission(String code) {
|
|
386 |
this.code = code;
|
|
387 |
}
|
9715e1
|
388 |
|
JM |
389 |
public boolean atMost(AccessPermission perm) {
|
|
390 |
return ordinal() <= perm.ordinal();
|
|
391 |
}
|
|
392 |
|
20714a
|
393 |
public boolean atLeast(AccessPermission perm) {
|
JM |
394 |
return ordinal() >= perm.ordinal();
|
|
395 |
}
|
|
396 |
|
|
397 |
public boolean exceeds(AccessPermission perm) {
|
|
398 |
return ordinal() > perm.ordinal();
|
|
399 |
}
|
|
400 |
|
|
401 |
public String asRole(String repository) {
|
|
402 |
return code + ":" + repository;
|
|
403 |
}
|
|
404 |
|
|
405 |
@Override
|
|
406 |
public String toString() {
|
|
407 |
return code;
|
|
408 |
}
|
|
409 |
|
|
410 |
public static AccessPermission permissionFromRole(String role) {
|
|
411 |
String [] fields = role.split(":", 2);
|
|
412 |
if (fields.length == 1) {
|
|
413 |
// legacy/undefined assume full permissions
|
|
414 |
return AccessPermission.LEGACY;
|
|
415 |
} else {
|
|
416 |
// code:repository
|
|
417 |
return AccessPermission.fromCode(fields[0]);
|
|
418 |
}
|
|
419 |
}
|
|
420 |
|
|
421 |
public static String repositoryFromRole(String role) {
|
|
422 |
String [] fields = role.split(":", 2);
|
|
423 |
if (fields.length == 1) {
|
|
424 |
// legacy/undefined assume full permissions
|
|
425 |
return role;
|
|
426 |
} else {
|
|
427 |
// code:repository
|
|
428 |
return fields[1];
|
|
429 |
}
|
|
430 |
}
|
|
431 |
|
|
432 |
public static AccessPermission fromCode(String code) {
|
|
433 |
for (AccessPermission perm : values()) {
|
|
434 |
if (perm.code.equalsIgnoreCase(code)) {
|
|
435 |
return perm;
|
|
436 |
}
|
|
437 |
}
|
|
438 |
return AccessPermission.NONE;
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
822dfe
|
442 |
public static enum RegistrantType {
|
JM |
443 |
REPOSITORY, USER, TEAM;
|
|
444 |
}
|
|
445 |
|
092f0a
|
446 |
public static enum PermissionType {
|
9a6a42
|
447 |
MISSING, ANONYMOUS, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;
|
092f0a
|
448 |
}
|
JM |
449 |
|
e92c6d
|
450 |
public static enum GCStatus {
|
JM |
451 |
READY, COLLECTING;
|
|
452 |
|
|
453 |
public boolean exceeds(GCStatus s) {
|
|
454 |
return ordinal() > s.ordinal();
|
|
455 |
}
|
|
456 |
}
|
8fef1f
|
457 |
|
JM |
458 |
public static enum AuthenticationType {
|
37fa66
|
459 |
CREDENTIALS, COOKIE, CERTIFICATE, CONTAINER;
|
8fef1f
|
460 |
|
JM |
461 |
public boolean isStandard() {
|
|
462 |
return ordinal() <= COOKIE.ordinal();
|
|
463 |
}
|
|
464 |
}
|
4e3c15
|
465 |
|
JM |
466 |
public static enum AccountType {
|
|
467 |
LOCAL, LDAP, REDMINE;
|
|
468 |
|
|
469 |
public boolean isLocal() {
|
|
470 |
return this == LOCAL;
|
|
471 |
}
|
|
472 |
}
|
8fef1f
|
473 |
|
20714a
|
474 |
@Documented
|
JM |
475 |
@Retention(RetentionPolicy.RUNTIME)
|
|
476 |
public @interface Unused {
|
|
477 |
}
|
5fe7df
|
478 |
}
|