]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b986bd6866be7933d53bdfc010e8b3f7813fbf90
[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  *  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:
27
28  *  http://www.collectionspace.org
29  *  http://wiki.collectionspace.org
30
31  *  Copyright 2009 University of California at Berkeley
32
33  *  Licensed under the Educational Community License (ECL), Version 2.0.
34  *  You may not use this file except in compliance with this License.
35
36  *  You may obtain a copy of the ECL 2.0 License at
37
38  *  https://source.collectionspace.org/collection-space/LICENSE.txt
39
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.
45  */
46 /*
47  * To change this template, choose Tools | Templates
48  * and open the template in the editor.
49  */
50 package org.collectionspace.services.authorization.spring;
51
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;
69
70 /**
71  * SpringAuthorizationProvider Spring Security provider
72  * @author 
73  */
74 public class SpringAuthorizationProvider implements CSpaceAuthorizationProvider {
75
76     final Log log = LogFactory.getLog(SpringPermissionEvaluator.class);
77     @Autowired
78     private MutableAclService providerAclService;
79     @Autowired
80     private PermissionEvaluator providerPermissionEvaluator;
81     private SpringPermissionEvaluator permissionEvaluator;
82     private SpringPermissionManager permissionManager;
83     private String version = "1.0";
84
85     public SpringAuthorizationProvider() {
86         permissionManager = new SpringPermissionManager(this);
87         permissionEvaluator = new SpringPermissionEvaluator(this);
88     }
89
90     MutableAclService getProviderAclService() {
91         return providerAclService;
92     }
93
94     public void setProviderAclService(MutableAclService mutableAclService) {
95          this.providerAclService = mutableAclService;
96         if (log.isDebugEnabled()) {
97             log.debug("mutableAclService set");
98         }
99     }
100
101     @Override
102     public String getName() {
103         return this.getClass().getSimpleName();
104     }
105
106     @Override
107     public String getVersion() {
108         return version;
109     }
110
111     PermissionEvaluator getProviderPermissionEvaluator() {
112         return providerPermissionEvaluator;
113     }
114
115     public void setProviderPermissionEvaluator(PermissionEvaluator permEval) {
116         this.providerPermissionEvaluator = permEval;
117         if (log.isDebugEnabled()) {
118             log.debug("permission evaluator set");
119         }
120     }
121
122     @Override
123     public CSpacePermissionEvaluator getPermissionEvaluator() {
124         return permissionEvaluator;
125     }
126
127     @Override
128     public CSpacePermissionManager getPermissionManager() {
129         return permissionManager;
130     }
131
132     static ObjectIdentity mapResource(CSpaceResource res) {
133         return new ObjectIdentityImpl(res.getType().toString(), Long.valueOf(res.getId().hashCode()));
134     }
135
136     static Sid[] mapPrincipal(String[] principals) {
137         ArrayList<Sid> sids = new ArrayList<Sid>();
138         for (String principal : principals) {
139             sids.add(new GrantedAuthoritySid(principal));
140         }
141         return sids.toArray(new Sid[0]);
142     }
143
144     static Permission mapPermssion(CSpaceAction perm) {
145         switch (perm) {
146             case ADMIN:
147                 return BasePermission.ADMINISTRATION;
148             case CREATE:
149                 return BasePermission.CREATE;
150             case READ:
151                 return BasePermission.READ;
152             case UPDATE:
153                 return BasePermission.WRITE;
154             case DELETE:
155                 return BasePermission.DELETE;
156         }
157         return null;
158     }
159 }