1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.bo.authorization;
17
18 import org.kuali.rice.kns.authorization.BusinessObjectAuthorizer;
19 import org.kuali.rice.krad.bo.BusinessObject;
20 import org.kuali.rice.krad.bo.DataObjectAuthorizerBase;
21 import org.kuali.rice.krad.service.DataDictionaryService;
22 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23 import org.kuali.rice.krad.service.KualiModuleService;
24 import org.kuali.rice.krad.service.PersistenceStructureService;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 public class BusinessObjectAuthorizerBase extends DataObjectAuthorizerBase implements BusinessObjectAuthorizer {
31 private static final long serialVersionUID = -6315759348728853851L;
32
33 private static KualiModuleService kualiModuleService;
34 private static DataDictionaryService dataDictionaryService;
35 private static PersistenceStructureService persistenceStructureService;
36
37 protected final boolean permissionExistsByTemplate(
38 BusinessObject businessObject, String namespaceCode,
39 String permissionTemplateName) {
40 return getPermissionService()
41 .isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, new HashMap<String, String>(
42 getPermissionDetailValues(businessObject)));
43 }
44
45 protected final boolean permissionExistsByTemplate(
46 BusinessObject businessObject, String namespaceCode,
47 String permissionTemplateName, Map<String, String> permissionDetails) {
48 Map<String, String> combinedPermissionDetails = new HashMap<String, String>(
49 getPermissionDetailValues(businessObject));
50 combinedPermissionDetails.putAll(permissionDetails);
51 return getPermissionService()
52 .isPermissionDefinedByTemplate(namespaceCode, permissionTemplateName, combinedPermissionDetails);
53 }
54
55 public final boolean isAuthorized(BusinessObject businessObject,
56 String namespaceCode, String permissionName, String principalId) {
57 return getPermissionService().isAuthorized(principalId,
58 namespaceCode, permissionName,
59 new HashMap<String, String>(getRoleQualification(businessObject, principalId)));
60 }
61
62 public final boolean isAuthorizedByTemplate(BusinessObject dataObject,
63 String namespaceCode, String permissionTemplateName,
64 String principalId) {
65 return getPermissionService().isAuthorizedByTemplate(principalId, namespaceCode, permissionTemplateName,
66 new HashMap<String, String>(getPermissionDetailValues(dataObject)), new HashMap<String, String>(
67 getRoleQualification(dataObject, principalId)));
68 }
69
70 public final boolean isAuthorized(BusinessObject businessObject,
71 String namespaceCode, String permissionName, String principalId,
72 Map<String, String> collectionOrFieldLevelPermissionDetails,
73 Map<String, String> collectionOrFieldLevelRoleQualification) {
74 Map<String, String> roleQualifiers = null;
75 Map<String, String> permissionDetails = null;
76 if (collectionOrFieldLevelRoleQualification != null) {
77 roleQualifiers = new HashMap<String, String>(
78 getRoleQualification(businessObject, principalId));
79 roleQualifiers.putAll(collectionOrFieldLevelRoleQualification);
80 } else {
81 roleQualifiers = new HashMap<String, String>(
82 getRoleQualification(businessObject, principalId));
83 }
84
85
86
87
88
89
90
91
92
93 return getPermissionService().isAuthorized(principalId,
94 namespaceCode, permissionName,
95 roleQualifiers);
96 }
97
98
99
100
101
102
103
104
105
106
107
108 protected final Map<String, String> getRoleQualification(
109 BusinessObject primaryBusinessObjectOrDocument) {
110 return getRoleQualification(primaryBusinessObjectOrDocument, GlobalVariables
111 .getUserSession().getPerson().getPrincipalId());
112 }
113
114
115
116
117 @Override
118 public Map<String, String> getCollectionItemPermissionDetails(
119 BusinessObject collectionItemBusinessObject) {
120 return new HashMap<String, String>();
121 }
122
123
124
125
126 @Override
127 public Map<String, String> getCollectionItemRoleQualifications(
128 BusinessObject collectionItemBusinessObject) {
129 return new HashMap<String, String>();
130 }
131
132 protected static KualiModuleService getKualiModuleService() {
133 if (kualiModuleService == null) {
134 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
135 }
136 return kualiModuleService;
137 }
138
139 protected static DataDictionaryService getDataDictionaryService() {
140 if (dataDictionaryService == null) {
141 dataDictionaryService = KRADServiceLocatorWeb
142 .getDataDictionaryService();
143 }
144 return dataDictionaryService;
145 }
146 }