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.DocumentAuthorizerBase;
21 import org.kuali.rice.krad.service.DocumentDictionaryService;
22 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23 import org.kuali.rice.krad.util.KRADConstants;
24 import org.kuali.rice.krad.util.KRADUtils;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29
30
31
32
33
34
35
36 public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase implements MaintenanceDocumentAuthorizer {
37 private static final long serialVersionUID = 6780013889553259327L;
38
39 private transient DocumentDictionaryService documentDictionaryService;
40
41
42
43
44 @Override
45 public final boolean canCreate(Class boClass, Person user) {
46 Map<String, String> permissionDetails = new HashMap<String, String>();
47 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
48 getDocumentDictionaryService().getMaintenanceDocumentTypeName(boClass));
49 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_NEW_ACTION);
50
51 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
52 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
53 || getPermissionService().isAuthorizedByTemplate(user.getPrincipalId(), KRADConstants.KNS_NAMESPACE,
54 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails,
55 new HashMap<String, String>());
56 }
57
58
59
60
61 @Override
62 public final boolean canMaintain(Object dataObject, Person user) {
63 Map<String, String> permissionDetails = new HashMap<String, String>(2);
64 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,
65 getDocumentDictionaryService().getMaintenanceDocumentTypeName(dataObject.getClass()));
66 permissionDetails.put(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_EDIT_ACTION);
67
68 return !permissionExistsByTemplate(KRADConstants.KNS_NAMESPACE,
69 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, permissionDetails)
70 || isAuthorizedByTemplate(dataObject, KRADConstants.KNS_NAMESPACE,
71 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId(), permissionDetails,
72 null);
73 }
74
75
76
77
78 @Override
79 public final boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, Person user) {
80 return !permissionExistsByTemplate(maintenanceDocument, KRADConstants.KNS_NAMESPACE,
81 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) || isAuthorizedByTemplate(
82 maintenanceDocument, KRADConstants.KNS_NAMESPACE,
83 KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, user.getPrincipalId());
84 }
85
86
87
88
89
90
91 @SuppressWarnings("unchecked")
92 @Override
93 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
94 super.addRoleQualification(dataObject, attributes);
95
96 if (dataObject instanceof MaintenanceDocument) {
97 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
98 if (maintDoc.getNewMaintainableObject() != null) {
99 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
100 maintDoc.getNewMaintainableObject().getDataObjectClass()));
101 }
102 }
103 }
104
105
106
107
108
109
110 @SuppressWarnings("unchecked")
111 @Override
112 protected void addPermissionDetails(Object dataObject, Map<String, String> attributes) {
113 super.addPermissionDetails(dataObject, attributes);
114
115 if (dataObject instanceof MaintenanceDocument) {
116 MaintenanceDocument maintDoc = (MaintenanceDocument) dataObject;
117 if (maintDoc.getNewMaintainableObject() != null) {
118 attributes.putAll(KRADUtils.getNamespaceAndComponentSimpleName(
119 maintDoc.getNewMaintainableObject().getDataObjectClass()));
120 attributes.put(KRADConstants.MAINTENANCE_ACTN,
121 maintDoc.getNewMaintainableObject().getMaintenanceAction());
122 }
123 }
124 }
125
126 protected DocumentDictionaryService getDocumentDictionaryService() {
127 if (documentDictionaryService == null) {
128 documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
129 }
130 return documentDictionaryService;
131 }
132
133 public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
134 this.documentDictionaryService = documentDictionaryService;
135 }
136 }