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