1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.maintenance;
17
18 import org.kuali.rice.kim.api.KimConstants;
19 import org.kuali.rice.kim.api.identity.Person;
20 import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.util.KRADConstants;
23 import org.kuali.rice.krad.util.KRADUtils;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28
29
30
31
32
33
34 public class MaintenanceViewAuthorizerBase extends DocumentViewAuthorizerBase {
35 private static final long serialVersionUID = 8688732738163609576L;
36
37 public final boolean canCreate(Class<?> boClass, Person user) {
38 Map<String, String> permissionDetails = new HashMap<String, String>();
39
40 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
41 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass));
42 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_NEW_ACTION);
43
44 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
45 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
46 || getPermissionService().isAuthorizedByTemplate(user.getPrincipalId(), KRADConstants.KNS_NAMESPACE,
47 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails,
48 new HashMap<String, String>());
49 }
50
51 public final boolean canMaintain(Object dataObject, Person user) {
52 Map<String, String> permissionDetails = new HashMap<String, String>(2);
53
54 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
55 KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
56 dataObject.getClass()));
57 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION);
58
59 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
60 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
61 || isAuthorizedByTemplate(dataObject, KRADConstants.KNS_NAMESPACE,
62 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(), permissionDetails,
63 null);
64 }
65
66 public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) {
67 return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KNS_NAMESPACE,
68 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) || isAuthorizedByTemplate(
69 maintenanceDocument, KRADConstants.KNS_NAMESPACE,
70 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId());
71 }
72
73 @SuppressWarnings("unchecked")
74 @Override
75 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
76 super.addRoleQualification(dataObject, attributes);
77 if (dataObject instanceof MaintenanceDocument) {
78 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
79 if (maintDoc.getNewMaintainableObject() != null) {
80 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
81 maintDoc.getNewMaintainableObject().getDataObjectClass()));
82 }
83 }
84 }
85
86 @SuppressWarnings("unchecked")
87 @Override
88 protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
89 super.addPermissionDetails(dataObject, attributes);
90 if (dataObject instanceof MaintenanceDocument) {
91 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
92 if (maintDoc.getNewMaintainableObject() != null) {
93 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
94 maintDoc.getNewMaintainableObject().getDataObjectClass()));
95 attributes.put(KRADConstants.MAINTENANCE_ACTN,
96 maintDoc.getNewMaintainableObject().getMaintenanceAction());
97 }
98 }
99 }
100 }