1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.authorization; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.kuali.rice.core.util.AttributeSet; |
22 | |
import org.kuali.rice.kim.api.services.IdentityManagementService; |
23 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
24 | |
import org.kuali.rice.kim.service.PersonService; |
25 | |
import org.kuali.rice.kim.util.KimConstants; |
26 | |
import org.kuali.rice.krad.bo.BusinessObject; |
27 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
28 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
29 | |
import org.kuali.rice.krad.service.KualiModuleService; |
30 | |
import org.kuali.rice.krad.service.PersistenceStructureService; |
31 | |
import org.kuali.rice.krad.util.GlobalVariables; |
32 | |
import org.kuali.rice.krad.util.KRADUtils; |
33 | |
|
34 | 0 | public class BusinessObjectAuthorizerBase implements BusinessObjectAuthorizer { |
35 | |
|
36 | |
|
37 | |
|
38 | |
private static IdentityManagementService identityManagementService; |
39 | |
private static PersonService personService; |
40 | |
private static KualiModuleService kualiModuleService; |
41 | |
private static DataDictionaryService dataDictionaryService; |
42 | |
private static PersistenceStructureService persistenceStructureService; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
protected void addRoleQualification( |
56 | |
Object primaryDataObjectOrDocument, |
57 | |
Map<String, String> attributes) { |
58 | 0 | addStandardAttributes(primaryDataObjectOrDocument, attributes); |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
protected void addPermissionDetails( |
72 | |
Object primaryDataObjectOrDocument, |
73 | |
Map<String, String> attributes) { |
74 | 0 | addStandardAttributes(primaryDataObjectOrDocument, attributes); |
75 | 0 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
private void addStandardAttributes( |
86 | |
Object primaryDataObjectOrDocument, |
87 | |
Map<String, String> attributes) { |
88 | 0 | attributes |
89 | |
.putAll(KRADUtils |
90 | |
.getNamespaceAndComponentSimpleName(primaryDataObjectOrDocument.getClass())); |
91 | 0 | } |
92 | |
|
93 | |
protected final boolean permissionExistsByTemplate( |
94 | |
BusinessObject businessObject, String namespaceCode, |
95 | |
String permissionTemplateName) { |
96 | 0 | return getIdentityManagementService() |
97 | |
.isPermissionDefinedForTemplateName( |
98 | |
namespaceCode, |
99 | |
permissionTemplateName, |
100 | |
new AttributeSet( |
101 | |
getPermissionDetailValues(businessObject))); |
102 | |
} |
103 | |
|
104 | |
protected final boolean permissionExistsByTemplate(String namespaceCode, |
105 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
106 | 0 | return getIdentityManagementService() |
107 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
108 | |
permissionTemplateName, |
109 | |
new AttributeSet(permissionDetails)); |
110 | |
} |
111 | |
|
112 | |
protected final boolean permissionExistsByTemplate( |
113 | |
BusinessObject businessObject, String namespaceCode, |
114 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
115 | 0 | AttributeSet combinedPermissionDetails = new AttributeSet( |
116 | |
getPermissionDetailValues(businessObject)); |
117 | 0 | combinedPermissionDetails.putAll(permissionDetails); |
118 | 0 | return getIdentityManagementService() |
119 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
120 | |
permissionTemplateName, combinedPermissionDetails); |
121 | |
} |
122 | |
|
123 | |
public final boolean isAuthorized(BusinessObject businessObject, |
124 | |
String namespaceCode, String permissionName, String principalId) { |
125 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
126 | |
namespaceCode, permissionName, |
127 | |
new AttributeSet(getPermissionDetailValues(businessObject)), |
128 | |
new AttributeSet(getRoleQualification(businessObject, principalId))); |
129 | |
} |
130 | |
|
131 | |
public final boolean isAuthorizedByTemplate(BusinessObject dataObject, |
132 | |
String namespaceCode, String permissionTemplateName, |
133 | |
String principalId) { |
134 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
135 | |
principalId, namespaceCode, permissionTemplateName, |
136 | |
new AttributeSet(getPermissionDetailValues(dataObject)), |
137 | |
new AttributeSet(getRoleQualification(dataObject, principalId))); |
138 | |
} |
139 | |
|
140 | |
public final boolean isAuthorized(BusinessObject businessObject, |
141 | |
String namespaceCode, String permissionName, String principalId, |
142 | |
Map<String, String> collectionOrFieldLevelPermissionDetails, |
143 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
144 | 0 | AttributeSet roleQualifiers = null; |
145 | 0 | AttributeSet permissionDetails = null; |
146 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
147 | 0 | roleQualifiers = new AttributeSet( |
148 | |
getRoleQualification(businessObject, principalId)); |
149 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
150 | |
} else { |
151 | 0 | roleQualifiers = new AttributeSet( |
152 | |
getRoleQualification(businessObject, principalId)); |
153 | |
} |
154 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
155 | 0 | permissionDetails = new AttributeSet( |
156 | |
getPermissionDetailValues(businessObject)); |
157 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
158 | |
} else { |
159 | 0 | permissionDetails = new AttributeSet( |
160 | |
getPermissionDetailValues(businessObject)); |
161 | |
} |
162 | |
|
163 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
164 | |
namespaceCode, permissionName, permissionDetails, |
165 | |
roleQualifiers); |
166 | |
} |
167 | |
|
168 | |
public final boolean isAuthorizedByTemplate(Object dataObject, |
169 | |
String namespaceCode, String permissionTemplateName, |
170 | |
String principalId, |
171 | |
Map<String, String> collectionOrFieldLevelPermissionDetails, |
172 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
173 | 0 | AttributeSet roleQualifiers = new AttributeSet( |
174 | |
getRoleQualification(dataObject, principalId)); |
175 | 0 | AttributeSet permissionDetails = new AttributeSet( |
176 | |
getPermissionDetailValues(dataObject)); |
177 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
178 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
179 | |
} |
180 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
181 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
182 | |
} |
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 | |
Object primaryDataObjectOrDocument, String principalId) { |
206 | 0 | Map<String, String> roleQualification = new HashMap<String, String>(); |
207 | 0 | addRoleQualification(primaryDataObjectOrDocument, |
208 | |
roleQualification); |
209 | 0 | roleQualification.put(KimConstants.AttributeConstants.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 | |
Object dataObject) { |
241 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
242 | 0 | addPermissionDetails(dataObject, permissionDetails); |
243 | 0 | return permissionDetails; |
244 | |
} |
245 | |
|
246 | |
protected static final IdentityManagementService getIdentityManagementService() { |
247 | 0 | if (identityManagementService == null) { |
248 | 0 | identityManagementService = KimApiServiceLocator |
249 | |
.getIdentityManagementService(); |
250 | |
} |
251 | 0 | return identityManagementService; |
252 | |
} |
253 | |
|
254 | |
protected static final PersonService getPersonService() { |
255 | 0 | if (personService == null) { |
256 | 0 | personService = KimApiServiceLocator.getPersonService(); |
257 | |
} |
258 | 0 | return personService; |
259 | |
} |
260 | |
|
261 | |
protected static final KualiModuleService getKualiModuleService() { |
262 | 0 | if (kualiModuleService == null) { |
263 | 0 | kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService(); |
264 | |
} |
265 | 0 | return kualiModuleService; |
266 | |
} |
267 | |
|
268 | |
protected static final DataDictionaryService getDataDictionaryService() { |
269 | 0 | if (dataDictionaryService == null) { |
270 | 0 | dataDictionaryService = KRADServiceLocatorWeb |
271 | |
.getDataDictionaryService(); |
272 | |
} |
273 | 0 | return dataDictionaryService; |
274 | |
} |
275 | |
} |