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