commit | author | age
|
8c9a20
|
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 |
|
892570
|
22 |
/**
|
JM |
23 |
* The SyndicationFilter is an AccessRestrictionFilter which ensures that feed
|
|
24 |
* requests for view-restricted repositories have proper authentication
|
|
25 |
* credentials and are authorized for the requested feed.
|
|
26 |
*
|
|
27 |
* @author James Moger
|
|
28 |
*
|
|
29 |
*/
|
8c9a20
|
30 |
public class SyndicationFilter extends AccessRestrictionFilter {
|
JM |
31 |
|
892570
|
32 |
/**
|
JM |
33 |
* Extract the repository name from the url.
|
|
34 |
*
|
|
35 |
* @param url
|
|
36 |
* @return repository name
|
|
37 |
*/
|
8c9a20
|
38 |
@Override
|
JM |
39 |
protected String extractRepositoryName(String url) {
|
565ee0
|
40 |
if (url.indexOf('?') > -1) {
|
JM |
41 |
return url.substring(0, url.indexOf('?'));
|
|
42 |
}
|
8c9a20
|
43 |
return url;
|
JM |
44 |
}
|
|
45 |
|
892570
|
46 |
/**
|
JM |
47 |
* Analyze the url and returns the action of the request.
|
|
48 |
*
|
|
49 |
* @param url
|
|
50 |
* @return action of the request
|
|
51 |
*/
|
8c9a20
|
52 |
@Override
|
892570
|
53 |
protected String getUrlRequestAction(String url) {
|
JM |
54 |
return "VIEW";
|
8c9a20
|
55 |
}
|
JM |
56 |
|
892570
|
57 |
/**
|
b74031
|
58 |
* Determine if the action may be executed on the repository.
|
JM |
59 |
*
|
|
60 |
* @param repository
|
|
61 |
* @param action
|
|
62 |
* @return true if the action may be performed
|
|
63 |
*/
|
|
64 |
@Override
|
|
65 |
protected boolean isActionAllowed(RepositoryModel repository, String action) {
|
|
66 |
return true;
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
892570
|
70 |
* Determine if the repository requires authentication.
|
JM |
71 |
*
|
|
72 |
* @param repository
|
|
73 |
* @return true if authentication required
|
|
74 |
*/
|
8c9a20
|
75 |
@Override
|
JM |
76 |
protected boolean requiresAuthentication(RepositoryModel repository) {
|
|
77 |
return repository.accessRestriction.atLeast(AccessRestrictionType.VIEW);
|
|
78 |
}
|
|
79 |
|
892570
|
80 |
/**
|
JM |
81 |
* Determine if the user can access the repository and perform the specified
|
|
82 |
* action.
|
|
83 |
*
|
|
84 |
* @param repository
|
|
85 |
* @param user
|
|
86 |
* @param action
|
|
87 |
* @return true if user may execute the action on the repository
|
|
88 |
*/
|
8c9a20
|
89 |
@Override
|
892570
|
90 |
protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {
|
efe8ec
|
91 |
return user.canAccessRepository(repository);
|
8c9a20
|
92 |
}
|
JM |
93 |
|
|
94 |
}
|