1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.authorization;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.coa.businessobject.Organization;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase;
28 import org.kuali.ole.sys.identity.OleKimAttributes;
29 import org.kuali.rice.kim.api.KimConstants;
30 import org.kuali.rice.kim.api.identity.Person;
31 import org.kuali.rice.kim.api.services.IdentityManagementService;
32 import org.kuali.rice.kns.document.MaintenanceDocument;
33 import org.kuali.rice.krad.document.Document;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.KRADConstants;
36
37
38
39
40 public class OrganizationDocumentAuthorizer extends FinancialSystemMaintenanceDocumentAuthorizerBase {
41 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationDocumentAuthorizer.class);
42
43 @Override
44 public Set<String> getDocumentActions(Document document, Person user, Set<String> documentActions) {
45 Set<String> myDocumentActions = super.getDocumentActions(document, user, documentActions);
46
47 if (checkPlantAttributes(document)) {
48 myDocumentActions.remove(KRADConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
49 }
50
51 return myDocumentActions;
52 }
53
54
55
56
57
58
59
60
61 protected boolean checkPlantAttributes(Document document) {
62
63 Person user = GlobalVariables.getUserSession().getPerson();
64
65
66 if (isPlantAuthorized(user, document) == false) {
67 return true;
68 }
69
70 return false;
71 }
72
73
74
75
76
77
78
79 protected boolean isPlantAuthorized(Person user, Document document) {
80 String principalId = user.getPrincipalId();
81 String namespaceCode = OLEConstants.ParameterNamespaces.KNS;
82 String permissionTemplateName = KimConstants.PermissionTemplateNames.MODIFY_FIELD;
83
84 Map<String,String> roleQualifiers = new HashMap<String,String>();
85
86 Map<String,String> permissionDetails = new HashMap<String,String>();
87 permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, Organization.class.getSimpleName());
88 permissionDetails.put(KimConstants.AttributeConstants.PROPERTY_NAME, OLEPropertyConstants.ORGANIZATION_PLANT_ACCOUNT_NUMBER);
89
90 IdentityManagementService identityManagementService = SpringContext.getBean(IdentityManagementService.class);
91 Boolean isAuthorized = identityManagementService.isAuthorizedByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, roleQualifiers);
92 if (!isAuthorized) {
93 if (LOG.isDebugEnabled()) {
94 LOG.debug("User '" + user.getPrincipalName() + "' has no access to the Plant Chart.");
95 }
96 }
97 else {
98 if (LOG.isDebugEnabled()) {
99 LOG.debug("User '" + user.getPrincipalName() + "' has access to the Plant fields.");
100 }
101 }
102
103 return isAuthorized;
104 }
105
106 @SuppressWarnings("unchecked")
107 @Override
108 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
109 super.addRoleQualification(dataObject, attributes);
110
111 if (dataObject instanceof MaintenanceDocument) {
112 MaintenanceDocument maintDoc = (MaintenanceDocument)dataObject;
113 if ( maintDoc.getNewMaintainableObject() != null ) {
114 Organization newOrg = (Organization) maintDoc.getNewMaintainableObject().getBusinessObject();
115 if (!StringUtils.isBlank(newOrg.getChartOfAccountsCode())) {
116 attributes.put(OleKimAttributes.CHART_OF_ACCOUNTS_CODE, newOrg.getChartOfAccountsCode());
117 }
118 }
119 }
120 else if (dataObject instanceof Organization) {
121 Organization newOrg = (Organization) dataObject;
122 if (!StringUtils.isBlank(newOrg.getChartOfAccountsCode())) {
123 attributes.put(OleKimAttributes.CHART_OF_ACCOUNTS_CODE, newOrg.getChartOfAccountsCode());
124 }
125 }
126 }
127 }