James Moger
2011-10-02 f762b160efd5cafd919a6fd7f9587f578eceb454
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) {
40         return url;
41     }
42
892570 43     /**
JM 44      * Analyze the url and returns the action of the request.
45      * 
46      * @param url
47      * @return action of the request
48      */
8c9a20 49     @Override
892570 50     protected String getUrlRequestAction(String url) {
JM 51         return "VIEW";
8c9a20 52     }
JM 53
892570 54     /**
JM 55      * Determine if the repository requires authentication.
56      * 
57      * @param repository
58      * @return true if authentication required
59      */
8c9a20 60     @Override
JM 61     protected boolean requiresAuthentication(RepositoryModel repository) {
62         return repository.accessRestriction.atLeast(AccessRestrictionType.VIEW);
63     }
64
892570 65     /**
JM 66      * Determine if the user can access the repository and perform the specified
67      * action.
68      * 
69      * @param repository
70      * @param user
71      * @param action
72      * @return true if user may execute the action on the repository
73      */
8c9a20 74     @Override
892570 75     protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {
8c9a20 76         return user.canAccessRepository(repository.name);
JM 77     }
78
79 }