commit | author | age
|
78753b
|
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 |
*/
|
|
16 |
package com.gitblit;
|
|
17 |
|
|
18 |
import com.gitblit.Constants.AccessRestrictionType;
|
|
19 |
import com.gitblit.models.RepositoryModel;
|
|
20 |
import com.gitblit.models.UserModel;
|
|
21 |
|
|
22 |
/**
|
|
23 |
* The DownloadZipFilter is an AccessRestrictionFilter which ensures that zip
|
|
24 |
* requests for view-restricted repositories have proper authentication
|
|
25 |
* credentials and are authorized.
|
699e71
|
26 |
*
|
78753b
|
27 |
* @author James Moger
|
699e71
|
28 |
*
|
78753b
|
29 |
*/
|
JM |
30 |
public class DownloadZipFilter extends AccessRestrictionFilter {
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Extract the repository name from the url.
|
699e71
|
34 |
*
|
78753b
|
35 |
* @param url
|
JM |
36 |
* @return repository name
|
|
37 |
*/
|
|
38 |
@Override
|
|
39 |
protected String extractRepositoryName(String url) {
|
|
40 |
int a = url.indexOf("r=");
|
|
41 |
String repository = url.substring(a + 2);
|
|
42 |
if (repository.indexOf('&') > -1) {
|
|
43 |
repository = repository.substring(0, repository.indexOf('&'));
|
|
44 |
}
|
|
45 |
return repository;
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Analyze the url and returns the action of the request.
|
699e71
|
50 |
*
|
78753b
|
51 |
* @param url
|
JM |
52 |
* @return action of the request
|
|
53 |
*/
|
|
54 |
@Override
|
|
55 |
protected String getUrlRequestAction(String url) {
|
|
56 |
return "DOWNLOAD";
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
72cb19
|
60 |
* Determine if a non-existing repository can be created using this filter.
|
699e71
|
61 |
*
|
72cb19
|
62 |
* @return true if the filter allows repository creation
|
JM |
63 |
*/
|
|
64 |
@Override
|
|
65 |
protected boolean isCreationAllowed() {
|
|
66 |
return false;
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
b74031
|
70 |
* Determine if the action may be executed on the repository.
|
699e71
|
71 |
*
|
b74031
|
72 |
* @param repository
|
JM |
73 |
* @param action
|
|
74 |
* @return true if the action may be performed
|
|
75 |
*/
|
|
76 |
@Override
|
|
77 |
protected boolean isActionAllowed(RepositoryModel repository, String action) {
|
|
78 |
return true;
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
78753b
|
82 |
* Determine if the repository requires authentication.
|
699e71
|
83 |
*
|
78753b
|
84 |
* @param repository
|
3f8cd4
|
85 |
* @param action
|
78753b
|
86 |
* @return true if authentication required
|
JM |
87 |
*/
|
|
88 |
@Override
|
3f8cd4
|
89 |
protected boolean requiresAuthentication(RepositoryModel repository, String action) {
|
78753b
|
90 |
return repository.accessRestriction.atLeast(AccessRestrictionType.VIEW);
|
JM |
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Determine if the user can access the repository and perform the specified
|
|
95 |
* action.
|
699e71
|
96 |
*
|
78753b
|
97 |
* @param repository
|
JM |
98 |
* @param user
|
|
99 |
* @param action
|
|
100 |
* @return true if user may execute the action on the repository
|
|
101 |
*/
|
|
102 |
@Override
|
|
103 |
protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {
|
20714a
|
104 |
return user.canView(repository);
|
78753b
|
105 |
}
|
JM |
106 |
|
|
107 |
}
|