1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.kim.permission.mock; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
24 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
25 | |
import org.kuali.rice.core.api.exception.RiceIllegalStateException; |
26 | |
import org.kuali.rice.kim.api.common.assignee.Assignee; |
27 | |
import org.kuali.rice.kim.api.common.template.Template; |
28 | |
import org.kuali.rice.kim.api.common.template.TemplateQueryResults; |
29 | |
import org.kuali.rice.kim.api.permission.Permission; |
30 | |
import org.kuali.rice.kim.api.permission.PermissionQueryResults; |
31 | |
import org.kuali.rice.kim.api.permission.PermissionService; |
32 | |
import org.kuali.rice.kim.api.role.Role; |
33 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
34 | |
|
35 | |
import javax.jws.WebParam; |
36 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class PermissionServiceMockImpl implements PermissionService { |
42 | |
|
43 | 0 | private transient Map<String, Template> permissionTemplateCache = new HashMap<String, Template>(); |
44 | 0 | private transient Map<String, Permission> permissionCache = new HashMap<String, Permission>(); |
45 | 0 | private transient Map<String, Role> roleCache = new HashMap<String, Role>(); |
46 | 0 | private transient Map<String, RoleMembership> roleMembershipCache = new HashMap<String, RoleMembership>(); |
47 | |
|
48 | |
@Override |
49 | |
public List<Template> getAllTemplates() { |
50 | 0 | return new ArrayList(this.permissionTemplateCache.values()); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public List<Permission> getAuthorizedPermissions(String principalId, |
55 | |
String namespaceCode, |
56 | |
String permissionName, |
57 | |
Map<String,String> qualification) { |
58 | 0 | List<Permission> list = new ArrayList<Permission>(); |
59 | 0 | for (Permission permission : this.permissionCache.values()) { |
60 | 0 | if (namespaceCode.equals(permission.getNamespaceCode())) { |
61 | 0 | if (permissionName.equals(permission.getName())) { |
62 | 0 | if (matchesQualification(permission, qualification)) { |
63 | 0 | if (matchesPrincipalId(permission, principalId)) { |
64 | 0 | list.add(permission); |
65 | |
} |
66 | |
} |
67 | |
} |
68 | |
} |
69 | |
} |
70 | 0 | return list; |
71 | |
} |
72 | |
|
73 | |
private boolean matchesPermissionDetails(Permission permission, Map<String,String> permissionDetails) { |
74 | |
|
75 | 0 | return true; |
76 | |
} |
77 | |
|
78 | |
private boolean matchesQualification(Permission permission, Map<String,String> qualification) { |
79 | |
|
80 | 0 | return true; |
81 | |
} |
82 | |
|
83 | |
private boolean matchesPrincipalId(Permission permission, String principalId) { |
84 | |
|
85 | 0 | return true; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public List<Permission> getAuthorizedPermissionsByTemplate(String principalId, |
90 | |
String namespaceCode, |
91 | |
String permissionTemplateName, |
92 | |
Map<String,String> permissionDetails, |
93 | |
Map<String,String> qualification) { |
94 | 0 | List<Permission> list = new ArrayList<Permission>(); |
95 | 0 | for (Permission permission : this.permissionCache.values()) { |
96 | 0 | if (permission.getTemplate() != null) { |
97 | 0 | if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) { |
98 | 0 | if (permissionTemplateName.equals(permission.getTemplate().getName())) { |
99 | 0 | if (matchesPermissionDetails(permission, permissionDetails)) { |
100 | 0 | if (matchesQualification(permission, qualification)) { |
101 | 0 | if (matchesPrincipalId(permission, principalId)) { |
102 | 0 | list.add(permission); |
103 | |
} |
104 | |
} |
105 | |
} |
106 | |
} |
107 | |
} |
108 | |
} |
109 | |
} |
110 | 0 | return list; |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public Permission getPermission(String permissionId) { |
115 | 0 | return this.permissionCache.get(permissionId); |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public List<Assignee> getPermissionAssignees(String namespaceCode, |
120 | |
String permissionName, |
121 | |
Map<String,String> qualification) { |
122 | 0 | List<Assignee> list = new ArrayList<Assignee>(); |
123 | 0 | for (Permission permission : this.permissionCache.values()) { |
124 | 0 | if (namespaceCode.equals(permission.getNamespaceCode())) { |
125 | 0 | if (permissionName.equals(permission.getName())) { |
126 | 0 | if (matchesQualification(permission, qualification)) { |
127 | 0 | list.addAll(getPermissionAssignees(permission)); |
128 | |
} |
129 | |
} |
130 | |
} |
131 | |
} |
132 | 0 | return list; |
133 | |
} |
134 | |
|
135 | |
private List<Assignee> getPermissionAssignees(Permission permission) { |
136 | 0 | List<Assignee> list = new ArrayList<Assignee>(); |
137 | |
|
138 | 0 | return list; |
139 | |
} |
140 | |
|
141 | |
@Override |
142 | |
public List<Assignee> getPermissionAssigneesByTemplate(String namespaceCode, |
143 | |
String permissionTemplateName, |
144 | |
Map<String,String> permissionDetails, |
145 | |
Map<String,String> qualification) { |
146 | 0 | List<Assignee> list = new ArrayList<Assignee>(); |
147 | 0 | for (Permission permission : this.permissionCache.values()) { |
148 | 0 | if (permission.getTemplate() != null) { |
149 | 0 | if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) { |
150 | 0 | if (permissionTemplateName.equals(permission.getTemplate().getName())) { |
151 | 0 | if (matchesPermissionDetails(permission, permissionDetails)) { |
152 | 0 | if (matchesQualification(permission, qualification)) { |
153 | 0 | list.addAll(getPermissionAssignees(permission)); |
154 | |
} |
155 | |
} |
156 | |
} |
157 | |
} |
158 | |
} |
159 | |
} |
160 | 0 | return list; |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public Template getPermissionTemplate(String permissionTemplateId) { |
165 | 0 | return this.permissionTemplateCache.get(permissionTemplateId); |
166 | |
} |
167 | |
|
168 | |
@Override |
169 | |
public Template findPermTemplateByNamespaceCodeAndName(String namespaceCode, |
170 | |
String permissionTemplateName) { |
171 | 0 | for (Template template : this.permissionTemplateCache.values()) { |
172 | 0 | if (template.getNamespaceCode().equals(namespaceCode)) { |
173 | 0 | if (template.getName().equals(permissionTemplateName)) { |
174 | 0 | return template; |
175 | |
} |
176 | |
} |
177 | |
} |
178 | 0 | return null; |
179 | |
} |
180 | |
|
181 | |
@Override |
182 | |
public Permission findPermByNamespaceCodeAndName(String namespaceCode, String permissionName) { |
183 | 0 | List<Permission> list = new ArrayList<Permission>(); |
184 | 0 | for (Permission permission : this.permissionCache.values()) { |
185 | 0 | if (namespaceCode.equals(permission.getNamespaceCode())) { |
186 | 0 | if (permissionName.equals(permission.getName())) { |
187 | 0 | if (permission.isActive()) { |
188 | 0 | list.add(permission); |
189 | |
} |
190 | |
} |
191 | |
} |
192 | |
} |
193 | 0 | if (list.isEmpty()) { |
194 | 0 | return null; |
195 | |
} |
196 | 0 | return list.get(0); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
@Override |
222 | |
public List<Permission> findPermissionsByTemplate(String namespaceCode, |
223 | |
String permissionTemplateName) { |
224 | 0 | List<Permission> list = new ArrayList<Permission>(); |
225 | 0 | for (Permission permission : this.permissionCache.values()) { |
226 | 0 | if (permission.getTemplate() != null) { |
227 | 0 | if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) { |
228 | 0 | if (permissionTemplateName.equals(permission.getTemplate().getName())) { |
229 | 0 | list.add(permission); |
230 | |
} |
231 | |
} |
232 | |
} |
233 | |
} |
234 | 0 | return list; |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public List<String> getRoleIdsForPermission(String namespaceCode, |
239 | |
String permissionName) { |
240 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
241 | |
} |
242 | |
|
243 | |
@Override |
244 | |
public boolean hasPermission(String principalId, String namespaceCode, |
245 | |
String permissionName) { |
246 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
247 | |
} |
248 | |
|
249 | |
@Override |
250 | |
public boolean hasPermissionByTemplate(String principalId, |
251 | |
String namespaceCode, |
252 | |
String permissionTemplateName, |
253 | |
Map<String,String> permissionDetails) { |
254 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
255 | |
} |
256 | |
|
257 | |
@Override |
258 | |
public boolean isAuthorized(String principalId, String namespaceCode, |
259 | |
String permissionName, |
260 | |
Map<String,String> qualification) { |
261 | 0 | if(principalId != null){ |
262 | 0 | if(principalId.equals("123")) |
263 | 0 | return true; |
264 | |
else |
265 | 0 | return false; |
266 | |
} |
267 | |
else |
268 | 0 | return false; |
269 | |
} |
270 | |
|
271 | |
@Override |
272 | |
public boolean isAuthorizedByTemplate(String principalId, |
273 | |
String namespaceCode, |
274 | |
String permissionTemplateName, |
275 | |
Map<String,String> permissionDetails, |
276 | |
Map<String,String> qualification) { |
277 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
278 | |
} |
279 | |
|
280 | |
@Override |
281 | |
public boolean isPermissionDefined(String namespaceCode, String permissionName) { |
282 | 0 | for (Permission permission : this.permissionCache.values()) { |
283 | 0 | if (namespaceCode.equals(permission.getNamespaceCode())) { |
284 | 0 | if (permissionName.equals(permission.getName())) { |
285 | 0 | return true; |
286 | |
} |
287 | |
} |
288 | |
} |
289 | |
|
290 | 0 | return false; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
public boolean isPermissionDefinedByTemplate(String namespaceCode, |
295 | |
String permissionTemplateName, |
296 | |
Map<String,String> permissionDetails) { |
297 | 0 | for (Permission permission : this.permissionCache.values()) { |
298 | 0 | if (permission.getTemplate() != null) { |
299 | 0 | if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) { |
300 | 0 | if (permissionTemplateName.equals(permission.getTemplate().getName())) { |
301 | 0 | if (matchesPermissionDetails(permission, permissionDetails)) { |
302 | 0 | return true; |
303 | |
} |
304 | |
} |
305 | |
} |
306 | |
} |
307 | |
} |
308 | 0 | return false; |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
public PermissionQueryResults findPermissions(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { |
313 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
public Permission createPermission(@WebParam(name = "permission") Permission permission) throws RiceIllegalArgumentException, RiceIllegalStateException { |
318 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
public Permission updatePermission(@WebParam(name = "permission") Permission permission) throws RiceIllegalArgumentException, RiceIllegalStateException { |
323 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
324 | |
} |
325 | |
|
326 | |
@Override |
327 | |
public TemplateQueryResults findPermissionTemplates(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { |
328 | 0 | throw new UnsupportedOperationException("Not supported yet."); |
329 | |
} |
330 | |
} |
331 | |
|