1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.document.authorization; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
import org.kuali.rice.kew.dto.DocumentTypeDTO; |
25 | |
import org.kuali.rice.kew.dto.ProcessDTO; |
26 | |
import org.kuali.rice.kew.exception.WorkflowException; |
27 | |
import org.kuali.rice.kew.routeheader.service.RouteHeaderService; |
28 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
29 | |
import org.kuali.rice.kew.util.KEWConstants; |
30 | |
import org.kuali.rice.kim.bo.Person; |
31 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
32 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
33 | |
import org.kuali.rice.kim.util.KimConstants; |
34 | |
import org.kuali.rice.kns.authorization.BusinessObjectAuthorizerBase; |
35 | |
import org.kuali.rice.kns.bo.BusinessObject; |
36 | |
import org.kuali.rice.kns.document.Document; |
37 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
38 | |
import org.kuali.rice.kns.util.KNSConstants; |
39 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class DocumentAuthorizerBase extends BusinessObjectAuthorizerBase |
46 | |
implements DocumentAuthorizer { |
47 | 0 | protected static Log LOG = LogFactory.getLog(DocumentAuthorizerBase.class); |
48 | |
public static final String PRE_ROUTING_ROUTE_NAME = "PreRoute"; |
49 | |
public static final String EDIT_MODE_DEFAULT_TRUE_VALUE = "TRUE"; |
50 | |
public static final String USER_SESSION_METHOD_TO_CALL_OBJECT_KEY = "METHOD_TO_CALL_KEYS_METHOD_OBJECT_KEY"; |
51 | |
public static final String USER_SESSION_METHOD_TO_CALL_COMPLETE_OBJECT_KEY = "METHOD_TO_CALL_KEYS_COMPLETE_OBJECT_KEY"; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public Set<String> getDocumentActions(Document document, Person user, |
62 | |
Set<String> documentActions) { |
63 | 0 | if (LOG.isDebugEnabled()) { |
64 | 0 | LOG |
65 | |
.debug("calling DocumentAuthorizerBase.getDocumentActionFlags for document '" |
66 | |
+ document.getDocumentNumber() |
67 | |
+ "'. user '" |
68 | |
+ user.getPrincipalName() + "'"); |
69 | |
} |
70 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_EDIT) |
71 | |
&& !isAuthorizedByTemplate(document, |
72 | |
KNSConstants.KNS_NAMESPACE, |
73 | |
KimConstants.PermissionTemplateNames.EDIT_DOCUMENT, |
74 | |
user.getPrincipalId())) { |
75 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_EDIT); |
76 | |
} |
77 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_COPY) |
78 | |
&& !isAuthorizedByTemplate(document, |
79 | |
KNSConstants.KNS_NAMESPACE, |
80 | |
KimConstants.PermissionTemplateNames.COPY_DOCUMENT, |
81 | |
user.getPrincipalId())) { |
82 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_COPY); |
83 | |
} |
84 | 0 | if (documentActions |
85 | |
.contains(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE) |
86 | |
&& !isAuthorizedByTemplate( |
87 | |
document, |
88 | |
KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE, |
89 | |
KimConstants.PermissionTemplateNames.BLANKET_APPROVE_DOCUMENT, |
90 | |
user.getPrincipalId())) { |
91 | 0 | documentActions |
92 | |
.remove(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE); |
93 | |
} |
94 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_CANCEL) |
95 | |
&& !isAuthorizedByTemplate(document, |
96 | |
KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE, |
97 | |
KimConstants.PermissionTemplateNames.CANCEL_DOCUMENT, |
98 | |
user.getPrincipalId())) { |
99 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_CANCEL); |
100 | |
} |
101 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_SAVE) |
102 | |
&& !isAuthorizedByTemplate(document, |
103 | |
KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE, |
104 | |
KimConstants.PermissionTemplateNames.SAVE_DOCUMENT, |
105 | |
user.getPrincipalId())) { |
106 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_SAVE); |
107 | |
} |
108 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_ROUTE) |
109 | |
&& !isAuthorizedByTemplate(document, |
110 | |
KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE, |
111 | |
KimConstants.PermissionTemplateNames.ROUTE_DOCUMENT, |
112 | |
user.getPrincipalId())) { |
113 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_ROUTE); |
114 | |
} |
115 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_ACKNOWLEDGE) |
116 | |
&& !canTakeRequestedAction(document, |
117 | |
KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, user)) { |
118 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_ACKNOWLEDGE); |
119 | |
} |
120 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_FYI) && |
121 | |
!canTakeRequestedAction(document, KEWConstants.ACTION_REQUEST_FYI_REQ, user)) { |
122 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_FYI); |
123 | |
} |
124 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_APPROVE) |
125 | |
|| documentActions |
126 | |
.contains(KNSConstants.KUALI_ACTION_CAN_DISAPPROVE)) { |
127 | 0 | if (!canTakeRequestedAction(document, |
128 | |
KEWConstants.ACTION_REQUEST_APPROVE_REQ, user)) { |
129 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_APPROVE); |
130 | 0 | documentActions |
131 | |
.remove(KNSConstants.KUALI_ACTION_CAN_DISAPPROVE); |
132 | |
} |
133 | |
} |
134 | |
|
135 | 0 | if ( !canSendAnyTypeAdHocRequests(document, user) ) { |
136 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS); |
137 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS); |
138 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI); |
139 | |
} |
140 | |
|
141 | 0 | if(documentActions |
142 | |
.contains(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI) |
143 | |
&& !canSendAdHocRequests(document, KEWConstants.ACTION_REQUEST_FYI_REQ, user)){ |
144 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI); |
145 | |
} |
146 | |
|
147 | 0 | if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_ANNOTATE) |
148 | |
&& !documentActions |
149 | |
.contains(KNSConstants.KUALI_ACTION_CAN_EDIT)) { |
150 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_ANNOTATE); |
151 | |
} |
152 | 0 | if(documentActions.contains(KNSConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW) |
153 | |
&&!canEditDocumentOverview(document, user)){ |
154 | 0 | documentActions.remove(KNSConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW); |
155 | |
} |
156 | 0 | return documentActions; |
157 | |
} |
158 | |
|
159 | |
public final boolean canInitiate(String documentTypeName, Person user) { |
160 | 0 | String nameSpaceCode = KNSConstants.KUALI_RICE_SYSTEM_NAMESPACE; |
161 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
162 | 0 | permissionDetails.put(KimAttributes.DOCUMENT_TYPE_NAME, |
163 | |
documentTypeName); |
164 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName( |
165 | |
user.getPrincipalId(), nameSpaceCode, |
166 | |
KimConstants.PermissionTemplateNames.INITIATE_DOCUMENT, |
167 | |
permissionDetails, null); |
168 | |
} |
169 | |
|
170 | |
public final boolean canReceiveAdHoc(Document document, Person user, |
171 | |
String actionRequestCode) { |
172 | 0 | Map<String,String> additionalPermissionDetails = new HashMap<String, String>(); |
173 | 0 | additionalPermissionDetails.put(KimAttributes.ACTION_REQUEST_CD, actionRequestCode); |
174 | 0 | return isAuthorizedByTemplate(document, |
175 | |
KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE, |
176 | |
KimConstants.PermissionTemplateNames.AD_HOC_REVIEW_DOCUMENT, |
177 | |
user.getPrincipalId(), additionalPermissionDetails, null ); |
178 | |
} |
179 | |
|
180 | |
public final boolean canOpen(Document document, Person user) { |
181 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
182 | |
KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, user |
183 | |
.getPrincipalId()); |
184 | |
} |
185 | |
|
186 | |
public final boolean canAddNoteAttachment(Document document, |
187 | |
String attachmentTypeCode, Person user) { |
188 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
189 | 0 | if (attachmentTypeCode != null) { |
190 | 0 | additionalPermissionDetails.put(KimAttributes.ATTACHMENT_TYPE_CODE, |
191 | |
attachmentTypeCode); |
192 | |
} |
193 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
194 | |
KimConstants.PermissionTemplateNames.ADD_NOTE_ATTACHMENT, user |
195 | |
.getPrincipalId(), additionalPermissionDetails, null); |
196 | |
} |
197 | |
|
198 | |
public final boolean canDeleteNoteAttachment(Document document, |
199 | |
String attachmentTypeCode, String createdBySelfOnly, Person user) { |
200 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
201 | 0 | if (attachmentTypeCode != null) { |
202 | 0 | additionalPermissionDetails.put(KimAttributes.ATTACHMENT_TYPE_CODE, |
203 | |
attachmentTypeCode); |
204 | |
} |
205 | 0 | additionalPermissionDetails.put(KimAttributes.CREATED_BY_SELF, |
206 | |
createdBySelfOnly); |
207 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
208 | |
KimConstants.PermissionTemplateNames.DELETE_NOTE_ATTACHMENT, |
209 | |
user.getPrincipalId(), additionalPermissionDetails, null); |
210 | |
} |
211 | |
|
212 | |
public final boolean canViewNoteAttachment(Document document, |
213 | |
String attachmentTypeCode, Person user) { |
214 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
215 | 0 | if (attachmentTypeCode != null) { |
216 | 0 | additionalPermissionDetails.put(KimAttributes.ATTACHMENT_TYPE_CODE, |
217 | |
attachmentTypeCode); |
218 | |
} |
219 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
220 | |
KimConstants.PermissionTemplateNames.VIEW_NOTE_ATTACHMENT, user |
221 | |
.getPrincipalId(), additionalPermissionDetails, null); |
222 | |
} |
223 | |
|
224 | |
public final boolean canSendAdHocRequests(Document document, |
225 | |
String actionRequestCd, Person user) { |
226 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
227 | 0 | if (actionRequestCd != null) { |
228 | 0 | additionalPermissionDetails.put(KimAttributes.ACTION_REQUEST_CD, |
229 | |
actionRequestCd); |
230 | |
} |
231 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
232 | |
KimConstants.PermissionTemplateNames.SEND_AD_HOC_REQUEST, user |
233 | |
.getPrincipalId(), additionalPermissionDetails, null); |
234 | |
} |
235 | |
|
236 | |
public boolean canEditDocumentOverview(Document document, Person user){ |
237 | 0 | return isAuthorizedByTemplate(document, |
238 | |
KNSConstants.KNS_NAMESPACE, |
239 | |
KimConstants.PermissionTemplateNames.EDIT_DOCUMENT, |
240 | |
user.getPrincipalId()) && this.isDocumentInitiator(document, user); |
241 | |
} |
242 | |
|
243 | |
protected final boolean canSendAnyTypeAdHocRequests(Document document, Person user) { |
244 | 0 | if(canSendAdHocRequests(document, KEWConstants.ACTION_REQUEST_FYI_REQ, user)) { |
245 | |
try { |
246 | 0 | DocumentTypeDTO docType = KNSServiceLocator.getWorkflowInfoService().getDocType(document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
247 | 0 | ProcessDTO process = docType.getRoutePath().getPrimaryProcess(); |
248 | 0 | if (process != null) { |
249 | 0 | if (process.getInitialRouteNode() == null) { |
250 | 0 | return false; |
251 | |
} |
252 | |
} else { |
253 | 0 | return false; |
254 | |
} |
255 | 0 | } catch (WorkflowException e) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | return true; |
259 | 0 | }else if(canSendAdHocRequests(document, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, user)){ |
260 | 0 | return true; |
261 | |
} |
262 | 0 | return canSendAdHocRequests(document, KEWConstants.ACTION_REQUEST_APPROVE_REQ, user); |
263 | |
} |
264 | |
|
265 | |
protected boolean canTakeRequestedAction(Document document, |
266 | |
String actionRequestCode, Person user) { |
267 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
268 | 0 | additionalPermissionDetails.put(KimAttributes.ACTION_REQUEST_CD, |
269 | |
actionRequestCode); |
270 | 0 | return isAuthorizedByTemplate(document, KNSConstants.KNS_NAMESPACE, |
271 | |
KimConstants.PermissionTemplateNames.TAKE_REQUESTED_ACTION, |
272 | |
user.getPrincipalId(), additionalPermissionDetails, null); |
273 | |
} |
274 | |
|
275 | |
@Override |
276 | |
protected void addPermissionDetails(BusinessObject businessObject, |
277 | |
Map<String, String> attributes) { |
278 | 0 | super.addPermissionDetails(businessObject, attributes); |
279 | 0 | if (businessObject instanceof Document) { |
280 | 0 | addStandardAttributes((Document) businessObject, attributes); |
281 | |
} |
282 | 0 | } |
283 | |
|
284 | |
@Override |
285 | |
protected void addRoleQualification(BusinessObject businessObject, |
286 | |
Map<String, String> attributes) { |
287 | 0 | super.addRoleQualification(businessObject, attributes); |
288 | 0 | if (businessObject instanceof Document) { |
289 | 0 | addStandardAttributes((Document) businessObject, attributes); |
290 | |
} |
291 | 0 | } |
292 | |
|
293 | |
protected void addStandardAttributes(Document document, |
294 | |
Map<String, String> attributes) { |
295 | 0 | KualiWorkflowDocument wd = document.getDocumentHeader() |
296 | |
.getWorkflowDocument(); |
297 | 0 | attributes.put(KimAttributes.DOCUMENT_NUMBER, document |
298 | |
.getDocumentNumber()); |
299 | 0 | attributes.put(KimAttributes.DOCUMENT_TYPE_NAME, wd.getDocumentType()); |
300 | 0 | if (wd.stateIsInitiated() || wd.stateIsSaved()) { |
301 | 0 | attributes.put(KimAttributes.ROUTE_NODE_NAME, |
302 | |
PRE_ROUTING_ROUTE_NAME); |
303 | |
} else { |
304 | 0 | attributes.put(KimAttributes.ROUTE_NODE_NAME, wd |
305 | |
.getCurrentRouteNodeNames()); |
306 | |
} |
307 | 0 | attributes.put(KimAttributes.ROUTE_STATUS_CODE, wd.getRouteHeader() |
308 | |
.getDocRouteStatus()); |
309 | 0 | } |
310 | |
|
311 | |
protected boolean isDocumentInitiator(Document document, Person user) { |
312 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
313 | 0 | return workflowDocument.getInitiatorPrincipalId().equalsIgnoreCase(user.getPrincipalId()); |
314 | |
} |
315 | |
|
316 | |
protected RouteHeaderService getRouteHeaderService() { |
317 | 0 | return (RouteHeaderService) KEWServiceLocator.getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV); |
318 | |
} |
319 | |
|
320 | |
} |