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