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.HashSet; |
20 | |
import java.util.Map; |
21 | |
import java.util.Set; |
22 | |
|
23 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
24 | |
import org.kuali.rice.kim.bo.Person; |
25 | |
import org.kuali.rice.kim.util.KimConstants; |
26 | |
import org.kuali.rice.kns.bo.BusinessObject; |
27 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
28 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
29 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
30 | |
import org.kuali.rice.kns.util.KNSConstants; |
31 | |
import org.kuali.rice.kns.util.KNSUtils; |
32 | |
|
33 | 0 | public class MaintenanceDocumentAuthorizerBase extends DocumentAuthorizerBase |
34 | |
implements MaintenanceDocumentAuthorizer { |
35 | |
|
36 | |
|
37 | |
|
38 | |
transient protected static MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
39 | |
|
40 | |
@SuppressWarnings("unchecked") |
41 | |
public final boolean canCreate(Class boClass, Person user) { |
42 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
43 | 0 | permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, |
44 | |
getMaintenanceDocumentDictionaryService().getDocumentTypeName( |
45 | |
boClass)); |
46 | 0 | permissionDetails.put(KNSConstants.MAINTENANCE_ACTN, |
47 | |
KNSConstants.MAINTENANCE_NEW_ACTION); |
48 | 0 | return !permissionExistsByTemplate(KNSConstants.KNS_NAMESPACE, |
49 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, |
50 | |
permissionDetails) |
51 | |
|| getIdentityManagementService() |
52 | |
.isAuthorizedByTemplateName( |
53 | |
user.getPrincipalId(), |
54 | |
KNSConstants.KNS_NAMESPACE, |
55 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, |
56 | |
permissionDetails, new AttributeSet()); |
57 | |
} |
58 | |
|
59 | |
@SuppressWarnings("unchecked") |
60 | |
public final boolean canMaintain(BusinessObject businessObject, Person user) { |
61 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(2); |
62 | 0 | permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, |
63 | |
getMaintenanceDocumentDictionaryService().getDocumentTypeName( |
64 | |
businessObject.getClass())); |
65 | 0 | permissionDetails.put(KNSConstants.MAINTENANCE_ACTN, |
66 | |
KNSConstants.MAINTENANCE_EDIT_ACTION); |
67 | 0 | return !permissionExistsByTemplate(KNSConstants.KNS_NAMESPACE, |
68 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, |
69 | |
permissionDetails) |
70 | |
|| isAuthorizedByTemplate( |
71 | |
businessObject, |
72 | |
KNSConstants.KNS_NAMESPACE, |
73 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, |
74 | |
user.getPrincipalId(), permissionDetails, null); |
75 | |
} |
76 | |
|
77 | |
public final boolean canCreateOrMaintain( |
78 | |
MaintenanceDocument maintenanceDocument, Person user) { |
79 | 0 | return !permissionExistsByTemplate(maintenanceDocument, |
80 | |
KNSConstants.KNS_NAMESPACE, |
81 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS) |
82 | |
|| isAuthorizedByTemplate( |
83 | |
maintenanceDocument, |
84 | |
KNSConstants.KNS_NAMESPACE, |
85 | |
KimConstants.PermissionTemplateNames.CREATE_MAINTAIN_RECORDS, |
86 | |
user.getPrincipalId()); |
87 | |
} |
88 | |
|
89 | |
public Set<String> getSecurePotentiallyHiddenSectionIds() { |
90 | 0 | return new HashSet<String>(); |
91 | |
} |
92 | |
|
93 | |
public Set<String> getSecurePotentiallyReadOnlySectionIds() { |
94 | 0 | return new HashSet<String>(); |
95 | |
} |
96 | |
|
97 | |
@SuppressWarnings("unchecked") |
98 | |
@Override |
99 | |
protected void addRoleQualification(BusinessObject businessObject, Map<String, String> attributes) { |
100 | 0 | super.addRoleQualification(businessObject, attributes); |
101 | 0 | if (businessObject instanceof MaintenanceDocument) { |
102 | 0 | MaintenanceDocument maintDoc = (MaintenanceDocument)businessObject; |
103 | 0 | if ( maintDoc.getNewMaintainableObject() != null ) { |
104 | 0 | attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getBoClass())); |
105 | |
} |
106 | |
} |
107 | 0 | } |
108 | |
|
109 | |
@SuppressWarnings("unchecked") |
110 | |
@Override |
111 | |
protected void addPermissionDetails(BusinessObject businessObject, Map<String, String> attributes) { |
112 | 0 | super.addPermissionDetails(businessObject, attributes); |
113 | 0 | if (businessObject instanceof MaintenanceDocument) { |
114 | 0 | MaintenanceDocument maintDoc = (MaintenanceDocument)businessObject; |
115 | 0 | if ( maintDoc.getNewMaintainableObject() != null ) { |
116 | 0 | attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(maintDoc.getNewMaintainableObject().getBoClass())); |
117 | 0 | attributes.put(KNSConstants.MAINTENANCE_ACTN,maintDoc.getNewMaintainableObject().getMaintenanceAction()); |
118 | |
} |
119 | |
} |
120 | 0 | } |
121 | |
|
122 | |
protected final MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
123 | 0 | if (maintenanceDocumentDictionaryService == null) { |
124 | 0 | maintenanceDocumentDictionaryService = KNSServiceLocatorWeb |
125 | |
.getMaintenanceDocumentDictionaryService(); |
126 | |
} |
127 | 0 | return maintenanceDocumentDictionaryService; |
128 | |
} |
129 | |
|
130 | |
} |