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.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.kns.bo.BusinessObject; |
27 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
28 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
29 | |
import org.kuali.rice.kns.service.KualiModuleService; |
30 | |
import org.kuali.rice.kns.service.PersistenceStructureService; |
31 | |
import org.kuali.rice.kns.util.GlobalVariables; |
32 | |
import org.kuali.rice.kns.util.KNSUtils; |
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(KNSUtils |
90 | |
.getNamespaceAndComponentSimpleName(primaryDataObjectOrDocument |
91 | |
.getClass())); |
92 | 0 | } |
93 | |
|
94 | |
protected final boolean permissionExistsByTemplate( |
95 | |
BusinessObject businessObject, String namespaceCode, |
96 | |
String permissionTemplateName) { |
97 | 0 | return getIdentityManagementService() |
98 | |
.isPermissionDefinedForTemplateName( |
99 | |
namespaceCode, |
100 | |
permissionTemplateName, |
101 | |
new AttributeSet( |
102 | |
getPermissionDetailValues(businessObject))); |
103 | |
} |
104 | |
|
105 | |
protected final boolean permissionExistsByTemplate(String namespaceCode, |
106 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
107 | 0 | return getIdentityManagementService() |
108 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
109 | |
permissionTemplateName, |
110 | |
new AttributeSet(permissionDetails)); |
111 | |
} |
112 | |
|
113 | |
protected final boolean permissionExistsByTemplate( |
114 | |
BusinessObject businessObject, String namespaceCode, |
115 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
116 | 0 | AttributeSet combinedPermissionDetails = new AttributeSet( |
117 | |
getPermissionDetailValues(businessObject)); |
118 | 0 | combinedPermissionDetails.putAll(permissionDetails); |
119 | 0 | return getIdentityManagementService() |
120 | |
.isPermissionDefinedForTemplateName(namespaceCode, |
121 | |
permissionTemplateName, combinedPermissionDetails); |
122 | |
} |
123 | |
|
124 | |
public final boolean isAuthorized(BusinessObject businessObject, |
125 | |
String namespaceCode, String permissionName, String principalId) { |
126 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
127 | |
namespaceCode, permissionName, |
128 | |
new AttributeSet(getPermissionDetailValues(businessObject)), |
129 | |
new AttributeSet(getRoleQualification(businessObject, principalId))); |
130 | |
} |
131 | |
|
132 | |
public final boolean isAuthorizedByTemplate(BusinessObject dataObject, |
133 | |
String namespaceCode, String permissionTemplateName, |
134 | |
String principalId) { |
135 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
136 | |
principalId, namespaceCode, permissionTemplateName, |
137 | |
new AttributeSet(getPermissionDetailValues(dataObject)), |
138 | |
new AttributeSet(getRoleQualification(dataObject, principalId))); |
139 | |
} |
140 | |
|
141 | |
public final boolean isAuthorized(BusinessObject businessObject, |
142 | |
String namespaceCode, String permissionName, String principalId, |
143 | |
Map<String, String> collectionOrFieldLevelPermissionDetails, |
144 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
145 | 0 | AttributeSet roleQualifiers = null; |
146 | 0 | AttributeSet permissionDetails = null; |
147 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
148 | 0 | roleQualifiers = new AttributeSet( |
149 | |
getRoleQualification(businessObject, principalId)); |
150 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
151 | |
} else { |
152 | 0 | roleQualifiers = new AttributeSet( |
153 | |
getRoleQualification(businessObject, principalId)); |
154 | |
} |
155 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
156 | 0 | permissionDetails = new AttributeSet( |
157 | |
getPermissionDetailValues(businessObject)); |
158 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
159 | |
} else { |
160 | 0 | permissionDetails = new AttributeSet( |
161 | |
getPermissionDetailValues(businessObject)); |
162 | |
} |
163 | |
|
164 | 0 | return getIdentityManagementService().isAuthorized(principalId, |
165 | |
namespaceCode, permissionName, permissionDetails, |
166 | |
roleQualifiers); |
167 | |
} |
168 | |
|
169 | |
public final boolean isAuthorizedByTemplate(Object dataObject, |
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(dataObject, principalId)); |
176 | 0 | AttributeSet permissionDetails = new AttributeSet( |
177 | |
getPermissionDetailValues(dataObject)); |
178 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
179 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
180 | |
} |
181 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
182 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
183 | |
} |
184 | |
|
185 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
186 | |
principalId, namespaceCode, permissionTemplateName, |
187 | |
permissionDetails, roleQualifiers); |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
protected final Map<String, String> getRoleQualification( |
200 | |
BusinessObject primaryBusinessObjectOrDocument) { |
201 | 0 | return getRoleQualification(primaryBusinessObjectOrDocument, GlobalVariables |
202 | |
.getUserSession().getPerson().getPrincipalId()); |
203 | |
} |
204 | |
|
205 | |
protected final Map<String, String> getRoleQualification( |
206 | |
Object primaryDataObjectOrDocument, String principalId) { |
207 | 0 | Map<String, String> roleQualification = new HashMap<String, String>(); |
208 | 0 | addRoleQualification(primaryDataObjectOrDocument, |
209 | |
roleQualification); |
210 | 0 | roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, principalId); |
211 | 0 | return roleQualification; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
public Map<String, String> getCollectionItemPermissionDetails( |
219 | |
BusinessObject collectionItemBusinessObject) { |
220 | 0 | return new AttributeSet(); |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public Map<String, String> getCollectionItemRoleQualifications( |
227 | |
BusinessObject collectionItemBusinessObject) { |
228 | 0 | return new AttributeSet(); |
229 | |
} |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
protected final Map<String, String> getPermissionDetailValues( |
241 | |
Object dataObject) { |
242 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
243 | 0 | addPermissionDetails(dataObject, permissionDetails); |
244 | 0 | return permissionDetails; |
245 | |
} |
246 | |
|
247 | |
protected static final IdentityManagementService getIdentityManagementService() { |
248 | 0 | if (identityManagementService == null) { |
249 | 0 | identityManagementService = KimApiServiceLocator |
250 | |
.getIdentityManagementService(); |
251 | |
} |
252 | 0 | return identityManagementService; |
253 | |
} |
254 | |
|
255 | |
protected static final PersonService getPersonService() { |
256 | 0 | if (personService == null) { |
257 | 0 | personService = KimApiServiceLocator.getPersonService(); |
258 | |
} |
259 | 0 | return personService; |
260 | |
} |
261 | |
|
262 | |
protected static final KualiModuleService getKualiModuleService() { |
263 | 0 | if (kualiModuleService == null) { |
264 | 0 | kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
265 | |
} |
266 | 0 | return kualiModuleService; |
267 | |
} |
268 | |
|
269 | |
protected static final DataDictionaryService getDataDictionaryService() { |
270 | 0 | if (dataDictionaryService == null) { |
271 | 0 | dataDictionaryService = KNSServiceLocatorWeb |
272 | |
.getDataDictionaryService(); |
273 | |
} |
274 | 0 | return dataDictionaryService; |
275 | |
} |
276 | |
} |