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.xml.dto.AttributeSet; |
24 | |
import org.kuali.rice.kim.bo.Person; |
25 | |
import org.kuali.rice.kim.service.IdentityManagementService; |
26 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
27 | |
import org.kuali.rice.kim.service.PersonService; |
28 | |
import org.kuali.rice.kim.util.KimConstants; |
29 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
30 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
31 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
32 | |
import org.kuali.rice.kns.service.KualiModuleService; |
33 | |
import org.kuali.rice.kns.util.GlobalVariables; |
34 | |
import org.kuali.rice.kns.util.KNSUtils; |
35 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class AuthorizerBase implements Authorizer { |
41 | |
|
42 | |
private static IdentityManagementService identityManagementService; |
43 | |
private static PersonService personService; |
44 | |
private static KualiModuleService kualiModuleService; |
45 | |
private static DataDictionaryService dataDictionaryService; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public Set<String> getActionFlags(UifFormBase model, Person user, Set<String> documentActions) { |
52 | 0 | return documentActions; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public Set<String> getEditModes(UifFormBase model, Person user, Set<String> editModes) { |
60 | 0 | return editModes; |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public Set<String> getSecurePotentiallyHiddenGroupIds() { |
67 | 0 | return new HashSet<String>(); |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public Set<String> getSecurePotentiallyReadOnlyGroupIds() { |
74 | 0 | return new HashSet<String>(); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
protected void addRoleQualification(Object primaryDataObjectOrDocument, Map<String, String> attributes) { |
89 | 0 | addStandardAttributes(primaryDataObjectOrDocument, attributes); |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
protected void addPermissionDetails(Object primaryDataObjectOrDocument, Map<String, String> attributes) { |
103 | 0 | addStandardAttributes(primaryDataObjectOrDocument, attributes); |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
private void addStandardAttributes(Object primaryDataObjectOrDocument, Map<String, String> attributes) { |
115 | 0 | attributes.putAll(KNSUtils.getNamespaceAndComponentSimpleName(primaryDataObjectOrDocument.getClass())); |
116 | 0 | } |
117 | |
|
118 | |
protected final boolean permissionExistsByTemplate(Object dataObject, String namespaceCode, |
119 | |
String permissionTemplateName) { |
120 | 0 | return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName, |
121 | |
new AttributeSet(getPermissionDetailValues(dataObject))); |
122 | |
} |
123 | |
|
124 | |
protected final boolean permissionExistsByTemplate(String namespaceCode, String permissionTemplateName, |
125 | |
Map<String, String> permissionDetails) { |
126 | 0 | return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName, |
127 | |
new AttributeSet(permissionDetails)); |
128 | |
} |
129 | |
|
130 | |
protected final boolean permissionExistsByTemplate(Object dataObject, String namespaceCode, |
131 | |
String permissionTemplateName, Map<String, String> permissionDetails) { |
132 | 0 | AttributeSet combinedPermissionDetails = new AttributeSet(getPermissionDetailValues(dataObject)); |
133 | 0 | combinedPermissionDetails.putAll(permissionDetails); |
134 | |
|
135 | 0 | return getIdentityManagementService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName, |
136 | |
combinedPermissionDetails); |
137 | |
} |
138 | |
|
139 | |
public final boolean isAuthorized(Object dataObject, String namespaceCode, String permissionName, String principalId) { |
140 | 0 | return getIdentityManagementService().isAuthorized(principalId, namespaceCode, permissionName, |
141 | |
new AttributeSet(getPermissionDetailValues(dataObject)), |
142 | |
new AttributeSet(getRoleQualification(dataObject, principalId))); |
143 | |
} |
144 | |
|
145 | |
public final boolean isAuthorizedByTemplate(Object dataObject, String namespaceCode, String permissionTemplateName, |
146 | |
String principalId) { |
147 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName(principalId, namespaceCode, |
148 | |
permissionTemplateName, new AttributeSet(getPermissionDetailValues(dataObject)), |
149 | |
new AttributeSet(getRoleQualification(dataObject, principalId))); |
150 | |
} |
151 | |
|
152 | |
public final boolean isAuthorized(Object dataObject, String namespaceCode, String permissionName, |
153 | |
String principalId, Map<String, String> collectionOrFieldLevelPermissionDetails, |
154 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
155 | 0 | AttributeSet roleQualifiers = null; |
156 | 0 | AttributeSet permissionDetails = null; |
157 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
158 | 0 | roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId)); |
159 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
160 | |
} |
161 | |
else { |
162 | 0 | roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId)); |
163 | |
} |
164 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
165 | 0 | permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject)); |
166 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
167 | |
} |
168 | |
else { |
169 | 0 | permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject)); |
170 | |
} |
171 | |
|
172 | 0 | return getIdentityManagementService().isAuthorized(principalId, namespaceCode, permissionName, |
173 | |
permissionDetails, roleQualifiers); |
174 | |
} |
175 | |
|
176 | |
public final boolean isAuthorizedByTemplate(Object dataObject, String namespaceCode, String permissionTemplateName, |
177 | |
String principalId, Map<String, String> collectionOrFieldLevelPermissionDetails, |
178 | |
Map<String, String> collectionOrFieldLevelRoleQualification) { |
179 | 0 | AttributeSet roleQualifiers = new AttributeSet(getRoleQualification(dataObject, principalId)); |
180 | 0 | AttributeSet permissionDetails = new AttributeSet(getPermissionDetailValues(dataObject)); |
181 | |
|
182 | 0 | if (collectionOrFieldLevelRoleQualification != null) { |
183 | 0 | roleQualifiers.putAll(collectionOrFieldLevelRoleQualification); |
184 | |
} |
185 | 0 | if (collectionOrFieldLevelPermissionDetails != null) { |
186 | 0 | permissionDetails.putAll(collectionOrFieldLevelPermissionDetails); |
187 | |
} |
188 | |
|
189 | 0 | return getIdentityManagementService().isAuthorizedByTemplateName(principalId, namespaceCode, |
190 | |
permissionTemplateName, permissionDetails, roleQualifiers); |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
protected final Map<String, String> getRoleQualification(Object primaryDataObjectOrDocument) { |
203 | 0 | return getRoleQualification(primaryDataObjectOrDocument, GlobalVariables.getUserSession().getPerson() |
204 | |
.getPrincipalId()); |
205 | |
} |
206 | |
|
207 | |
protected final Map<String, String> getRoleQualification(Object primaryDataObjectOrDocument, String principalId) { |
208 | 0 | Map<String, String> roleQualification = new HashMap<String, String>(); |
209 | 0 | addRoleQualification(primaryDataObjectOrDocument, roleQualification); |
210 | 0 | roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, principalId); |
211 | |
|
212 | 0 | return roleQualification; |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
protected final Map<String, String> getPermissionDetailValues(Object primaryDataObjectOrDocument) { |
225 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
226 | 0 | addPermissionDetails(primaryDataObjectOrDocument, permissionDetails); |
227 | |
|
228 | 0 | return permissionDetails; |
229 | |
} |
230 | |
|
231 | |
protected static final IdentityManagementService getIdentityManagementService() { |
232 | 0 | if (identityManagementService == null) { |
233 | 0 | identityManagementService = KIMServiceLocator.getIdentityManagementService(); |
234 | |
} |
235 | 0 | return identityManagementService; |
236 | |
} |
237 | |
|
238 | |
protected static final PersonService getPersonService() { |
239 | 0 | if (personService == null) { |
240 | 0 | personService = KIMServiceLocator.getPersonService(); |
241 | |
} |
242 | 0 | return personService; |
243 | |
} |
244 | |
|
245 | |
protected static final KualiModuleService getKualiModuleService() { |
246 | 0 | if (kualiModuleService == null) { |
247 | 0 | kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
248 | |
} |
249 | 0 | return kualiModuleService; |
250 | |
} |
251 | |
|
252 | |
protected static final DataDictionaryService getDataDictionaryService() { |
253 | 0 | if (dataDictionaryService == null) { |
254 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
255 | |
} |
256 | 0 | return dataDictionaryService; |
257 | |
} |
258 | |
|
259 | |
} |