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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 * This document is a part of the source code and related artifacts
25 * for CollectionSpace, an open source collections management system
26 * for museums and related institutions:
28 * http://www.collectionspace.org
29 * http://wiki.collectionspace.org
31 * Copyright 2009 University of California at Berkeley
33 * Licensed under the Educational Community License (ECL), Version 2.0.
34 * You may not use this file except in compliance with this License.
36 * You may obtain a copy of the ECL 2.0 License at
38 * https://source.collectionspace.org/collection-space/LICENSE.txt
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
47 * To change this template, choose Tools | Templates
48 * and open the template in the editor.
50 package org.collectionspace.services.authorization.spring;
52 import java.util.ArrayList;
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55 import org.collectionspace.services.authorization.CSpaceAction;
56 import org.collectionspace.services.authorization.CSpaceResource;
57 import org.collectionspace.services.authorization.spi.CSpaceAuthorizationProvider;
58 import org.collectionspace.services.authorization.spi.CSpacePermissionEvaluator;
59 import org.collectionspace.services.authorization.spi.CSpacePermissionManager;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.security.access.PermissionEvaluator;
62 import org.springframework.security.acls.domain.BasePermission;
63 import org.springframework.security.acls.domain.GrantedAuthoritySid;
64 import org.springframework.security.acls.domain.ObjectIdentityImpl;
65 import org.springframework.security.acls.model.MutableAclService;
66 import org.springframework.security.acls.model.ObjectIdentity;
67 import org.springframework.security.acls.model.Permission;
68 import org.springframework.security.acls.model.Sid;
71 * SpringAuthorizationProvider Spring Security provider
74 public class SpringAuthorizationProvider implements CSpaceAuthorizationProvider {
76 final Log log = LogFactory.getLog(SpringPermissionEvaluator.class);
78 private MutableAclService providerAclService;
80 private PermissionEvaluator providerPermissionEvaluator;
81 private SpringPermissionEvaluator permissionEvaluator;
82 private SpringPermissionManager permissionManager;
83 private String version = "1.0";
85 public SpringAuthorizationProvider() {
86 permissionManager = new SpringPermissionManager(this);
87 permissionEvaluator = new SpringPermissionEvaluator(this);
90 MutableAclService getProviderAclService() {
91 return providerAclService;
94 public void setProviderAclService(MutableAclService mutableAclService) {
95 this.providerAclService = mutableAclService;
96 if (log.isDebugEnabled()) {
97 log.debug("mutableAclService set");
102 public String getName() {
103 return this.getClass().getSimpleName();
107 public String getVersion() {
111 PermissionEvaluator getProviderPermissionEvaluator() {
112 return providerPermissionEvaluator;
115 public void setProviderPermissionEvaluator(PermissionEvaluator permEval) {
116 this.providerPermissionEvaluator = permEval;
117 if (log.isDebugEnabled()) {
118 log.debug("permission evaluator set");
123 public CSpacePermissionEvaluator getPermissionEvaluator() {
124 return permissionEvaluator;
128 public CSpacePermissionManager getPermissionManager() {
129 return permissionManager;
132 static ObjectIdentity mapResource(CSpaceResource res) {
133 return new ObjectIdentityImpl(res.getType().toString(), Long.valueOf(res.getId().hashCode()));
136 static Sid[] mapPrincipal(String[] principals) {
137 ArrayList<Sid> sids = new ArrayList<Sid>();
138 for (String principal : principals) {
139 sids.add(new GrantedAuthoritySid(principal));
141 return sids.toArray(new Sid[0]);
144 static Permission mapPermssion(CSpaceAction perm) {
147 return BasePermission.ADMINISTRATION;
149 return BasePermission.CREATE;
151 return BasePermission.READ;
153 return BasePermission.WRITE;
155 return BasePermission.DELETE;