1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.authorization; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.kuali.rice.kim.bo.Person; |
22 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
23 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
24 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
25 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
26 | |
import org.kuali.rice.kim.service.PersonService; |
27 | |
import org.kuali.rice.kim.util.KimCommonUtils; |
28 | |
import org.kuali.rice.kns.bo.BusinessObject; |
29 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
30 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
31 | |
import org.kuali.rice.kns.service.KualiModuleService; |
32 | |
import org.kuali.rice.kns.service.PersistenceStructureService; |
33 | |
import org.kuali.rice.kns.util.GlobalVariables; |
34 | |
|
35 | 0 | public class BusinessObjectAuthorizerBase implements BusinessObjectAuthorizer { |
36 | |
|
37 | |
|
38 | |
|
39 | |
private static IdentityManagementService identityManagementService; |
40 | |
private static PersonService<Person> personService; |
41 | |
private static KualiModuleService kualiModuleService; |
42 | |
private static DataDictionaryService dataDictionaryService; |
43 | |
private static PersistenceStructureService persistenceStructureService; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
protected void addRoleQualification( |
57 | |
BusinessObject primaryBusinessObjectOrDocument, |
58 | |
Map<String, String> attributes) { |
59 | 0 | addStandardAttributes(primaryBusinessObjectOrDocument, attributes); |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
protected void addPermissionDetails( |
73 | |
BusinessObject primaryBusinessObjectOrDocument, |
74 | |
Map<String, String> attributes) { |
75 | 0 | addStandardAttributes(primaryBusinessObjectOrDocument, attributes); |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
private void addStandardAttributes( |
87 | |
BusinessObject primaryBusinessObjectOrDocument, |
88 | |
Map<String, String> attributes) { |
89 | 0 | attributes |
90 | |
.putAll(KimCommonUtils |
91 | |
.getNamespaceAndComponentSimpleName(primaryBusinessObjectOrDocument |
92 | |
.getClass())); |
93 | 0 | } |
94 | |
|
95 | |
protected final boolean permissionExistsByTemplate( |
96 | |
BusinessObject businessObject, String namespaceCode, |
97 | |
String permissionTemplateName) { |
98 | 0 | return getIdentityManagementService() |
99 | |
.isPermissionDefinedForTemplateName( |
100 | |
namespaceCode, |
101 | |
permissionTemplateName, |
102 | |
new AttributeSet( |
103 | |
getPermissionDetailValues(businessObject))); |
104 | |
} |
105 | |
|
106 | |
protected final boolean permissionExistsByTemplate(String namespaceCode, |
107 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
108 | 0 | return getIdentityManagementService() |
109 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
110 | |
permissionTemplateName, |
111 | |
new AttributeSet(permissionDetails)); |
112 | |
} |
113 | |
|
114 | |
protected final boolean permissionExistsByTemplate( |
115 | |
BusinessObject businessObject, String namespaceCode, |
116 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
117 | 0 | AttributeSet combinedPermissionDetails = new AttributeSet( |
118 | |
getPermissionDetailValues(businessObject)); |
119 | 0 | combinedPermissionDetails.putAll(permissionDetails); |
120 | 0 | return getIdentityManagementService() |
121 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
122 | |
permissionTemplateName, combinedPermissionDetails); |
123 | |
} |
124 | |
|
125 | |
public final boolean isAuthorized(BusinessObject businessObject, |
126 | |
String namespaceCode, String permissionName, String principalId) { |
127 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
128 | |
namespaceCode, permissionName, |
129 | |
new AttributeSet(getPermissionDetailValues(businessObject)), |
130 | |
new AttributeSet(getRoleQualification(businessObject, principalId))); |
131 | |
} |
132 | |
|
133 | |
public final boolean isAuthorizedByTemplate(BusinessObject businessObject, |
134 | |
String namespaceCode, String permissionTemplateName, |
135 | |
String principalId) { |
136 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
137 | |
principalId, namespaceCode, permissionTemplateName, |
138 | |
new AttributeSet(getPermissionDetailValues(businessObject)), |
139 | |
new AttributeSet(getRoleQualification(businessObject, principalId))); |
140 | |
} |
141 | |
|
142 | |
public final boolean isAuthorized(BusinessObject businessObject, |
143 | |
String namespaceCode, String permissionName, String principalId, |
144 | |
Map<String, String> collectionOrFieldLevelPermissionDetails, |
145 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
146 | 0 | AttributeSet roleQualifiers = null; |
147 | 0 | AttributeSet permissionDetails = null; |
148 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
149 | 0 | roleQualifiers = new AttributeSet( |
150 | |
getRoleQualification(businessObject, principalId)); |
151 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
152 | |
} else { |
153 | 0 | roleQualifiers = new AttributeSet( |
154 | |
getRoleQualification(businessObject, principalId)); |
155 | |
} |
156 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
157 | 0 | permissionDetails = new AttributeSet( |
158 | |
getPermissionDetailValues(businessObject)); |
159 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
160 | |
} else { |
161 | 0 | permissionDetails = new AttributeSet( |
162 | |
getPermissionDetailValues(businessObject)); |
163 | |
} |
164 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
165 | |
namespaceCode, permissionName, permissionDetails, |
166 | |
roleQualifiers); |
167 | |
} |
168 | |
|
169 | |
public final boolean isAuthorizedByTemplate(BusinessObject businessObject, |
170 | |
String namespaceCode, String permissionTemplateName, |
171 | |
String principalId, |
172 | |
Map<String, String> collectionOrFieldLevelPermissionDetails, |
173 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
174 | 0 | AttributeSet roleQualifiers = new AttributeSet( |
175 | |
getRoleQualification(businessObject, principalId)); |
176 | 0 | AttributeSet permissionDetails = new AttributeSet( |
177 | |
getPermissionDetailValues(businessObject)); |
178 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
179 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
180 | |
} |
181 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
182 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
183 | |
} |
184 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
185 | |
principalId, namespaceCode, permissionTemplateName, |
186 | |
permissionDetails, roleQualifiers); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
protected final Map<String, String> getRoleQualification( |
199 | |
BusinessObject primaryBusinessObjectOrDocument) { |
200 | 0 | return getRoleQualification(primaryBusinessObjectOrDocument, GlobalVariables |
201 | |
.getUserSession().getPerson().getPrincipalId()); |
202 | |
} |
203 | |
|
204 | |
protected final Map<String, String> getRoleQualification( |
205 | |
BusinessObject primaryBusinessObjectOrDocument, String principalId) { |
206 | 0 | Map<String, String> roleQualification = new HashMap<String, String>(); |
207 | 0 | addRoleQualification(primaryBusinessObjectOrDocument, |
208 | |
roleQualification); |
209 | 0 | roleQualification.put(KimAttributes.PRINCIPAL_ID, principalId); |
210 | 0 | return roleQualification; |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public Map<String, String> getCollectionItemPermissionDetails( |
218 | |
BusinessObject collectionItemBusinessObject) { |
219 | 0 | return new AttributeSet(); |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public Map<String, String> getCollectionItemRoleQualifications( |
226 | |
BusinessObject collectionItemBusinessObject) { |
227 | 0 | return new AttributeSet(); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
protected final Map<String, String> getPermissionDetailValues( |
240 | |
BusinessObject businessObject) { |
241 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
242 | 0 | addPermissionDetails(businessObject, permissionDetails); |
243 | 0 | return permissionDetails; |
244 | |
} |
245 | |
|
246 | |
protected static final IdentityManagementService getIdentityManagementService() { |
247 | 0 | if (identityManagementService == null) { |
248 | 0 | identityManagementService = KIMServiceLocator |
249 | |
.getIdentityManagementService(); |
250 | |
} |
251 | 0 | return identityManagementService; |
252 | |
} |
253 | |
|
254 | |
protected static final PersonService<Person> getPersonService() { |
255 | 0 | if (personService == null) { |
256 | 0 | personService = KIMServiceLocator.getPersonService(); |
257 | |
} |
258 | 0 | return personService; |
259 | |
} |
260 | |
|
261 | |
protected static final KualiModuleService getKualiModuleService() { |
262 | 0 | if (kualiModuleService == null) { |
263 | 0 | kualiModuleService = KNSServiceLocator.getKualiModuleService(); |
264 | |
} |
265 | 0 | return kualiModuleService; |
266 | |
} |
267 | |
|
268 | |
protected static final DataDictionaryService getDataDictionaryService() { |
269 | 0 | if (dataDictionaryService == null) { |
270 | 0 | dataDictionaryService = KNSServiceLocator |
271 | |
.getDataDictionaryService(); |
272 | |
} |
273 | 0 | return dataDictionaryService; |
274 | |
} |
275 | |
} |