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.*;
19
20 import org.joda.time.DateTime;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.core.api.delegation.DelegationType;
23 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
24 import org.kuali.rice.core.api.exception.RiceIllegalStateException;
25 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
26 import org.kuali.rice.kim.api.KimConstants;
27 import org.kuali.rice.kim.api.common.delegate.DelegateMember;
28 import org.kuali.rice.kim.api.common.delegate.DelegateType;
29
30 import org.kuali.rice.kim.api.group.GroupService;
31 import org.kuali.rice.kim.api.role.*;
32 import org.kuali.rice.core.api.membership.MemberType;
33 import org.kuali.rice.kim.framework.type.KimTypeService;
34 import org.kuali.student.common.mock.MockService;
35
36 import javax.jws.WebParam;
37 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
38
39
40
41
42 public class RoleServiceMockImpl implements RoleService, MockService {
43
44 private transient Map<String, Role> roleCache = new HashMap<String, Role>();
45 private transient Map<String, RoleMembership> roleMembershipCache = new HashMap<String, RoleMembership>();
46 private transient Map<String, RoleMember> roleMemberCompleteInfoCache = new HashMap<String, RoleMember>();
47 private GroupService groupService;
48 private KimTypeService kimTypeInfoService;
49
50
51 @Override
52 public void clear() {
53 this.roleCache.clear();
54 this.roleMemberCompleteInfoCache.clear();
55 this.roleMembershipCache.clear();
56
57 }
58
59 public GroupService getGroupService() {
60 return groupService;
61 }
62
63 public void setGroupService(GroupService groupService) {
64 this.groupService = groupService;
65 }
66
67 public KimTypeService getKimTypeService() {
68 return kimTypeInfoService;
69 }
70
71 public void setKimTypeService(KimTypeService kimTypeInfoService) {
72 this.kimTypeInfoService = kimTypeInfoService;
73 }
74
75
76
77
78
79
80
81 @Override
82 public Role getRole(String roleId) {
83 return roleCache.get(roleId);
84 }
85
86
87
88
89 @Override
90 public List<Role> getRoles(List<String> roleIds) {
91 List<Role> list = new ArrayList<Role>();
92 for (String roleId : roleIds) {
93 list.add(this.getRole(roleId));
94 }
95 return list;
96 }
97
98
99
100
101
102
103
104 @Override
105 public Role getRoleByNamespaceCodeAndName(String namespaceCode, String roleName) {
106 for (Role role : this.roleCache.values()) {
107 if (namespaceCode.equals(role.getNamespaceCode())) {
108 if (roleName.equals(role.getName())) {
109 return role;
110 }
111 }
112 }
113 return null;
114 }
115
116
117
118
119
120 @Override
121 public String getRoleIdByNamespaceCodeAndName(String namespaceCode, String roleName) {
122 for (Role role : this.roleCache.values()) {
123 if (namespaceCode.equals(role.getNamespaceCode())) {
124 if (roleName.equals(role.getName())) {
125 return role.getId();
126 }
127 }
128 }
129 return null;
130 }
131
132
133
134
135
136
137
138 @Override
139 public boolean isRoleActive(String roleId) {
140 return this.getRole(roleId).isActive();
141 }
142
143
144
145
146
147
148
149 public List<Map<String,String>> getRoleQualifiersForPrincipal(String principalId, List<String> roleIds, Map<String,String> qualification) {
150 throw new UnsupportedOperationException("Not supported Yet");
151 }
152
153
154
155
156
157
158
159 public List<Map<String,String>> getRoleQualifiersForPrincipal(String principalId, String namespaceCode, String roleName, Map<String,String> qualification) {
160 throw new UnsupportedOperationException("Not supported Yet");
161 }
162
163
164
165 public List<Map<String, String>> getNestedRoleQualifiersForPrincipal(String principalId, String namespaceCode, String roleName, Map<String, String> qualification) {
166 throw new UnsupportedOperationException("Not supported yet.");
167 }
168
169
170 public List<Map<String, String>> getNestedRoleQualifiersForPrincipal(String principalId, List<String> roleIds, Map<String, String> qualification) {
171 throw new UnsupportedOperationException("Not supported yet.");
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185 @Override
186 public List<RoleMembership> getRoleMembers(List<String> roleIds, Map<String,String> qualification) {
187 List<RoleMembership> list = new ArrayList<RoleMembership>();
188 for (RoleMembership info : this.roleMembershipCache.values()) {
189 if (roleIds.contains(info.getRoleId())) {
190 if (matchesQualifiers(info, qualification)) {
191 list.add(info);
192 }
193 }
194 }
195 return list;
196 }
197
198 private boolean matchesQualifiers(RoleMembership info, Map<String,String> qualification) {
199
200 return true;
201 }
202
203 private Collection<String> getAllRoleMemberPrincipalIds(String roleId, Map<String,String> qualification) {
204 Collection<String> principals = new ArrayList<String>();
205 for (RoleMembership info : this.roleMembershipCache.values()) {
206 if (roleId.equals(info.getRoleId())) {
207 if (matchesQualifiers(info, qualification)) {
208 if (info.getType().equals(KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) {
209 principals.add(info.getMemberId());
210 } else if (info.getType().equals(KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) {
211 principals.addAll(groupService.getMemberPrincipalIds(info.getMemberId()));
212
213
214 }
215 }
216 }
217 }
218 return principals;
219 }
220
221
222
223
224
225
226 @Override
227 public Collection<String> getRoleMemberPrincipalIds(String namespaceCode, String roleName, Map<String,String> qualification) {
228 Role roleInfo = this.getRoleByNamespaceCodeAndName(namespaceCode, roleName);
229 if (roleInfo == null) {
230 throw new IllegalArgumentException("role name not found");
231 }
232 return this.getAllRoleMemberPrincipalIds(roleName, qualification);
233 }
234
235 private boolean principalHasThisRole(String principalId, String roleId, Map<String,String> qualification) {
236 return (this.getAllRoleMemberPrincipalIds(roleId, qualification).contains(principalId));
237 }
238
239
240
241
242 @Override
243 public boolean principalHasRole(String principalId, List<String> roleIds, Map<String,String> qualification) {
244 for (String roleId : roleIds) {
245 if (this.principalHasThisRole(principalId, roleId, qualification)) {
246 return true;
247 }
248 }
249 return false;
250 }
251
252 @Override
253 public boolean principalHasRole(@WebParam(name = "principalId") String principalId, @WebParam(name = "roleIds") List<String> roleIds, @WebParam(name = "qualification") @XmlJavaTypeAdapter(value = MapStringStringAdapter.class) Map<String, String> qualification, boolean checkDelegations) throws RiceIllegalArgumentException {
254 throw new UnsupportedOperationException("Not supported Yet");
255 }
256
257
258
259
260
261 @Override
262 public List<String> getPrincipalIdSubListWithRole(List<String> principalIds,
263 String roleNamespaceCode, String roleName, Map<String,String> qualification) {
264 List<String> subList = new ArrayList<String>();
265 Role role = getRoleByNamespaceCodeAndName(roleNamespaceCode, roleName);
266 for (String principalId : principalIds) {
267 if (principalHasThisRole(principalId, role.getId(), qualification)) {
268 subList.add(principalId);
269 }
270 }
271 return subList;
272 }
273
274 @Override
275 public RoleQueryResults findRoles(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
276 throw new UnsupportedOperationException("Not supported Yet");
277 }
278
279
280
281
282
283
284
285
286
287
288 public void principalInactivated(String principalId) {
289 for (RoleMembership membership : this.roleMembershipCache.values()) {
290 if (membership.getType().equals(KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) {
291 if (principalId.equals(membership.getMemberId())) {
292 this.roleMembershipCache.remove(membership.getMemberId());
293 }
294 }
295 }
296 }
297
298
299
300
301
302
303
304
305
306 public void roleInactivated(String roleId) {
307 for (RoleMembership membership : this.roleMembershipCache.values()) {
308 if (membership.getType().getCode().equals(MemberType.ROLE.getCode())) {
309 if (roleId.equals(membership.getMemberId())) {
310 this.roleMembershipCache.remove(membership.getMemberId());
311 }
312 if (roleId.equals(membership.getRoleId())) {
313 this.roleMembershipCache.remove(membership.getMemberId());
314 }
315 }
316 }
317 this.roleCache.remove(roleId);
318 }
319
320
321
322
323
324
325
326
327
328 public void groupInactivated(String groupId) {
329 for (RoleMembership membership : this.roleMembershipCache.values()) {
330 if (membership.getType().equals(KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) {
331 if (groupId.equals(membership.getMemberId())) {
332 this.roleMembershipCache.remove(membership.getMemberId());
333 }
334 }
335 }
336 }
337
338
339
340
341
342
343
344
345
346
347
348
349 @Override
350 public List<RoleMembership> getFirstLevelRoleMembers(List<String> roleIds) {
351 List<RoleMembership> list = new ArrayList<RoleMembership>();
352 for (RoleMembership membership : this.roleMembershipCache.values()) {
353 if (roleIds.contains(membership.getRoleId())) {
354 this.roleMembershipCache.remove(membership.getMemberId());
355 }
356 }
357 return list;
358 }
359
360
361
362
363
364
365 @Override
366 public RoleMemberQueryResults findRoleMembers(QueryByCriteria queryByCriteria) {
367 throw new UnsupportedOperationException("Not supported yet.");
368 }
369
370 @Override
371 public Set<String> getRoleTypeRoleMemberIds(@WebParam(name = "roleId") String roleId) throws RiceIllegalArgumentException {
372 throw new UnsupportedOperationException("Not supported Yet");
373 }
374
375
376
377
378
379
380
381 @Override
382 public List<String> getMemberParentRoleIds(String memberType, String memberId) {
383 List<String> list = new ArrayList<String>();
384 for (RoleMembership membership : this.roleMembershipCache.values()) {
385 if (memberType.equals(membership.getType().getCode())) {
386 if (memberId.equals(membership.getMemberId())) {
387 list.add(membership.getRoleId());
388 }
389 }
390 }
391 return list;
392 }
393
394
395
396 @Override
397 public RoleMembershipQueryResults findRoleMemberships(QueryByCriteria queryByCriteria) {
398 throw new UnsupportedOperationException("Not supported yet.");
399 }
400
401 @Override
402 public DelegateMemberQueryResults findDelegateMembers(QueryByCriteria queryByCriteria) {
403 throw new UnsupportedOperationException("Not supported yet.");
404 }
405
406
407
408
409
410
411
412
413 @Override
414 public List<DelegateMember> getDelegationMembersByDelegationId(String delegationId) {
415 throw new UnsupportedOperationException("Not supported Yet");
416 }
417
418 @Override
419 public DelegateMember getDelegationMemberByDelegationAndMemberId(String delegationId, String memberId) {
420 throw new UnsupportedOperationException("Not supported Yet");
421 }
422
423 @Override
424 public DelegateMember getDelegationMemberById(String delegationMemberId) {
425 throw new UnsupportedOperationException("Not supported Yet");
426 }
427
428 @Override
429 public List<RoleResponsibility> getRoleResponsibilities(String roleId) {
430 throw new UnsupportedOperationException("Not supported Yet");
431 }
432
433 @Override
434 public List<RoleResponsibilityAction> getRoleMemberResponsibilityActions(String roleMemberId) {
435 throw new UnsupportedOperationException("Not supported yet.");
436 }
437
438 @Override
439 public DelegateType getDelegateTypeByRoleIdAndDelegateTypeCode(@WebParam(name = "roleId") String roleId,
440 @WebParam(name = "delegateType") DelegationType delegateType) throws RiceIllegalArgumentException{
441 throw new UnsupportedOperationException("Not supported Yet");
442 }
443
444 @Override
445 public DelegateType getDelegateTypeByDelegationId(@WebParam(name = "delegationId") String delegationId) throws RiceIllegalArgumentException {
446 throw new UnsupportedOperationException("Not supported Yet");
447 }
448
449 @Override
450 public DelegateType updateDelegateType(@WebParam(name="delegateType") DelegateType delegateType) throws RiceIllegalArgumentException, RiceIllegalStateException{
451 throw new UnsupportedOperationException("Not supported Yet");
452 }
453
454
455
456
457 public List<Role> lookupRoles(Map<String, String> searchCriteria) {
458 throw new UnsupportedOperationException("Not supported Yet");
459 }
460
461 @Override
462 public RoleMember assignGroupToRole(String groupId, String namespaceCode,
463 String roleName, Map<String,String> qualifications)
464 throws UnsupportedOperationException {
465 throw new UnsupportedOperationException("Not supported yet.");
466 }
467
468 @Override
469 public void assignPermissionToRole(String permissionId, String roleId) throws UnsupportedOperationException {
470 throw new UnsupportedOperationException("Not supported yet.");
471 }
472
473 @Override
474 public RoleMember assignPrincipalToRole(String principalId, String namespaceCode,
475 String roleName, Map<String,String> qualifications)
476 throws UnsupportedOperationException {
477 Role roleInfo = null;
478 for (Role role : this.roleCache.values()) {
479 if (namespaceCode.equals(role.getNamespaceCode())) {
480 roleInfo = role;
481 break;
482 }
483 if (null == roleInfo) {
484 String id = UUID.randomUUID().toString();
485 String description = roleName + " description";
486 String kimTypeId = null;
487 Role.Builder bldr = Role.Builder.create(id, roleName, namespaceCode, description, kimTypeId);
488 roleInfo = bldr.build();
489 this.roleCache.put(roleInfo.getId(), roleInfo);
490 }
491 RoleMembership roleMembershipInfo = null;
492 if (roleName.equals(roleInfo.getName())) {
493 for (RoleMembership rmInfo : roleMembershipCache.values()) {
494 if (rmInfo.getRoleId().equals(roleInfo.getId())) {
495 roleMembershipInfo = rmInfo;
496 }
497 }
498 }
499 if (null == roleMembershipInfo) {
500
501 }
502
503 }
504
505 throw new UnsupportedOperationException("Not supported yet.");
506 }
507
508 @Override
509 public RoleMember assignRoleToRole(String roleId, String namespaceCode,
510 String roleName, Map<String,String> qualifications)
511 throws UnsupportedOperationException {
512 throw new UnsupportedOperationException("Not supported yet.");
513 }
514
515 @Override
516 public void removeGroupFromRole(String groupId, String namespaceCode,
517 String roleName, Map<String,String> qualifications)
518 throws UnsupportedOperationException {
519 throw new UnsupportedOperationException("Not supported yet.");
520 }
521
522 @Override
523 public void removePrincipalFromRole(String principalId, String namespaceCode,
524 String roleName,
525 Map<String,String> qualifications) throws UnsupportedOperationException {
526 throw new UnsupportedOperationException("Not supported yet.");
527 }
528
529 @Override
530 public void removeRoleFromRole(String roleId, String namespaceCode,
531 String roleName, Map<String,String> qualifications)
532 throws UnsupportedOperationException {
533 throw new UnsupportedOperationException("Not supported yet.");
534 }
535
536 @Override
537 public RoleResponsibilityAction createRoleResponsibilityAction(@WebParam(name = "roleResponsibilityAction") RoleResponsibilityAction roleResponsibilityAction) throws RiceIllegalArgumentException {
538 throw new UnsupportedOperationException("Not supported yet.");
539 }
540
541
542 public void saveDelegationMemberForRole(String delegationMemberId,
543 String roleMemberId, String memberId,
544 String memberTypeCode,
545 String delegationTypeCode,
546 String roleId,
547 Map<String,String> qualifications,
548 DateTime activeFromDate, DateTime activeToDate)
549 throws UnsupportedOperationException {
550 throw new UnsupportedOperationException("Not supported yet.");
551 }
552
553
554 public void saveRole(String roleId, String roleName, String roleDescription,
555 boolean active, String kimTypeId, String namespaceCode)
556 throws UnsupportedOperationException {
557 throw new UnsupportedOperationException("Not supported yet.");
558 }
559
560
561
562 public RoleMember saveRoleMemberForRole(String roleMemberId,
563 String memberId,
564 String memberTypeCode,
565 String roleId,
566 Map<String, String> qualifications,
567 DateTime activeFromDate,
568 DateTime activeToDate) throws RiceIllegalArgumentException {
569 throw new UnsupportedOperationException("Not supported yet.");
570 }
571
572
573 public void saveRoleRspActions(String roleResponsibilityActionId,
574 String roleId, String roleResponsibilityId,
575 String roleMemberId, String actionTypeCode,
576 String actionPolicyCode, Integer priorityNumber,
577 Boolean forceAction) {
578 throw new UnsupportedOperationException("Not supported yet.");
579 }
580
581 @Override
582 public RoleMember createRoleMember(RoleMember roleMember) throws RiceIllegalArgumentException, RiceIllegalStateException {
583 throw new UnsupportedOperationException("Not supported yet.");
584 }
585
586 @Override
587 public RoleMember updateRoleMember(RoleMember roleMember) throws RiceIllegalArgumentException, RiceIllegalStateException{
588 throw new UnsupportedOperationException("Not supported yet.");
589 }
590
591 @Override
592 public DelegateMember updateDelegateMember(@WebParam(name = "delegateMember") DelegateMember delegateMember) throws RiceIllegalArgumentException, RiceIllegalStateException {
593 throw new UnsupportedOperationException("Not supported yet.");
594 }
595
596 @Override
597 public DelegateMember createDelegateMember(@WebParam(name = "delegateMember") DelegateMember delegateMember) throws RiceIllegalArgumentException, RiceIllegalStateException {
598 throw new UnsupportedOperationException("Not supported yet.");
599 }
600
601 @Override
602 public void removeDelegateMembers(@WebParam(name = "delegateMembers") List<DelegateMember> delegateMembers) throws RiceIllegalArgumentException, RiceIllegalStateException {
603 throw new UnsupportedOperationException("Not supported yet.");
604 }
605
606 @Override
607 public Role createRole(Role role) throws RiceIllegalArgumentException, RiceIllegalStateException {
608 throw new UnsupportedOperationException("Not supported yet.");
609 }
610
611 @Override
612 public Role updateRole(Role role) throws RiceIllegalArgumentException, RiceIllegalStateException {
613 throw new UnsupportedOperationException("Not supported yet.");
614 }
615
616 @Override
617 public List<Map<String, String>> getNestedRoleQualifiersForPrincipalByRoleIds(
618 String principalId, List<String> roleIds, Map<String, String> qualification)
619 throws RiceIllegalArgumentException{
620 throw new UnsupportedOperationException("Not supported yet.");
621 }
622
623 @Override
624 public List<Map<String, String>> getRoleQualifersForPrincipalByNamespaceAndRolename(
625 String principalId, String namespaceCode, String roleName, Map<String, String> qualification)
626 throws RiceIllegalArgumentException {
627 throw new UnsupportedOperationException("Not supported yet.");
628 }
629
630 @Override
631 public List<Map<String, String>> getRoleQualifersForPrincipalByRoleIds(String principalId,
632 List<String> roleIds, Map<String, String> qualification) throws RiceIllegalArgumentException {
633 throw new UnsupportedOperationException("Not supported yet.");
634 }
635
636 @Override
637 public List<Map<String, String>> getNestedRoleQualifersForPrincipalByNamespaceAndRolename(
638 String principalId, String namespaceCode,
639 String roleName, Map<String, String> qualification)
640 throws RiceIllegalArgumentException {
641 throw new UnsupportedOperationException("Not supported yet.");
642 }
643
644 @Override
645 public DelegateType createDelegateType(DelegateType delegateType) throws RiceIllegalArgumentException, RiceIllegalStateException {
646 throw new UnsupportedOperationException("Not supported yet.");
647 }
648
649 @Override
650 public void revokePermissionFromRole(String permissionId, String roleId) throws RiceIllegalArgumentException {
651 throw new UnsupportedOperationException("Not supported yet.");
652 }
653
654 @Override
655 public boolean isDerivedRole(@WebParam(name = "roleId") String s) throws RiceIllegalArgumentException {
656 return false;
657 }
658
659 @Override
660 public boolean isDynamicRoleMembership(@WebParam(name = "roleId") String s) throws RiceIllegalArgumentException {
661 return false;
662 }
663 }
664