]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2f5b6d03084d66af6177c48c4ad7b7bb9fd1f9f7
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.authorization.spring;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.collectionspace.services.authorization.CSpaceAction;
29 import org.collectionspace.services.authorization.spi.CSpacePermissionEvaluator;
30
31 import org.collectionspace.services.authorization.CSpaceResource;
32 import org.springframework.security.access.PermissionEvaluator;
33 import org.springframework.security.acls.model.Permission;
34 import org.springframework.security.core.Authentication;
35 import org.springframework.security.core.context.SecurityContextHolder;
36
37 /**
38  * SpringPermissionEvaluator evaluates permissions in Spring Security
39  * @author 
40  */
41 public class SpringPermissionEvaluator implements CSpacePermissionEvaluator {
42
43     final Log log = LogFactory.getLog(SpringPermissionEvaluator.class);
44     private SpringAuthorizationProvider provider;
45
46     SpringPermissionEvaluator(SpringAuthorizationProvider provider) {
47         this.provider = provider;
48     }
49
50     @Override
51     public boolean hasPermission(CSpaceResource res, CSpaceAction perm) {
52         PermissionEvaluator eval = provider.getProviderPermissionEvaluator();
53         Permission p = SpringAuthorizationProvider.mapPermssion(perm);
54         Authentication authToken = SecurityContextHolder.getContext().getAuthentication();
55         return eval.hasPermission(authToken, Long.valueOf(res.getId().hashCode()), res.getType().toString(), p);
56     }
57 }