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