1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.role; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.core.api.criteria.CriteriaLookupService; |
22 | |
import org.kuali.rice.core.api.membership.MemberType; |
23 | |
import org.kuali.rice.core.api.delegation.DelegationType; |
24 | |
import org.kuali.rice.kim.api.KimConstants; |
25 | |
import org.kuali.rice.kim.api.group.Group; |
26 | |
import org.kuali.rice.kim.api.group.GroupService; |
27 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
28 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
29 | |
import org.kuali.rice.kim.api.role.Role; |
30 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
31 | |
import org.kuali.rice.kim.api.type.KimType; |
32 | |
import org.kuali.rice.kim.framework.role.RoleTypeService; |
33 | |
import org.kuali.rice.kim.framework.type.KimTypeService; |
34 | |
import org.kuali.rice.kim.impl.KIMPropertyConstants; |
35 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeBo; |
36 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateTypeBo; |
37 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateMemberBo; |
38 | |
import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService; |
39 | |
import org.kuali.rice.kim.impl.services.KimImplServiceLocator; |
40 | |
import org.kuali.rice.kim.impl.type.KimTypeBo; |
41 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
42 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
43 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
44 | |
import org.kuali.rice.krad.service.LookupService; |
45 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
46 | |
|
47 | |
import java.util.ArrayList; |
48 | |
import java.util.Collection; |
49 | |
import java.util.Collections; |
50 | |
import java.util.HashMap; |
51 | |
import java.util.List; |
52 | |
import java.util.Map; |
53 | |
import java.util.Set; |
54 | |
|
55 | 0 | abstract class RoleServiceBase { |
56 | 0 | private static final Logger LOG = Logger.getLogger( RoleServiceBase.class ); |
57 | |
|
58 | |
private BusinessObjectService businessObjectService; |
59 | |
private LookupService lookupService; |
60 | |
private IdentityService identityService; |
61 | |
private GroupService groupService; |
62 | |
private ResponsibilityInternalService responsibilityInternalService; |
63 | |
private RoleDao roleDao; |
64 | |
private CriteriaLookupService criteriaLookupService; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | 0 | protected static enum RoleDaoAction { |
72 | 0 | ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS, |
73 | 0 | ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS, |
74 | 0 | ROLE_MEMBERS_FOR_ROLE_IDS, |
75 | 0 | ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS, |
76 | 0 | ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS, |
77 | 0 | DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS, |
78 | 0 | DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS, |
79 | 0 | DELEGATION_MEMBERS_FOR_DELEGATION_IDS |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
private Map<String, String> convertQualifierKeys(Map<String, String> qualification) { |
89 | 0 | Map<String, String> convertedQualification = new HashMap<String, String>(); |
90 | 0 | if (qualification != null && CollectionUtils.isNotEmpty(qualification.keySet())) { |
91 | 0 | for (Map.Entry<String, String> entry : qualification.entrySet()) { |
92 | 0 | if (StringUtils.isNotEmpty(getKimAttributeId(entry.getKey()))) { |
93 | 0 | convertedQualification.put(getKimAttributeId(entry.getKey()), entry.getValue()); |
94 | |
} |
95 | |
} |
96 | |
} |
97 | 0 | return convertedQualification; |
98 | |
} |
99 | |
|
100 | |
protected void getNestedRoleTypeMemberIds(String roleId, Set<String> members) { |
101 | 0 | ArrayList<String> roleList = new ArrayList<String>(1); |
102 | 0 | roleList.add(roleId); |
103 | 0 | List<RoleMemberBo> firstLevelMembers = getStoredRoleMembersForRoleIds(roleList, MemberType.ROLE.getCode(), Collections.<String, String>emptyMap()); |
104 | 0 | for (RoleMemberBo member : firstLevelMembers) { |
105 | 0 | if (MemberType.ROLE.equals(member.getMemberType())) { |
106 | 0 | if (!members.contains(member.getMemberId())) { |
107 | 0 | members.add(member.getMemberId()); |
108 | 0 | getNestedRoleTypeMemberIds(member.getMemberId(), members); |
109 | |
} |
110 | |
} |
111 | |
} |
112 | 0 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
protected List<RoleMemberBo> getRoleMemberBoList(RoleDaoAction daoActionToTake, Collection<String> roleIds, String principalId, |
127 | |
Collection<String> groupIds, String memberTypeCode, Map<String, String> qualification) { |
128 | 0 | Map<String, String> convertedQualification = convertQualifierKeys(qualification); |
129 | |
|
130 | 0 | if (roleIds == null || roleIds.isEmpty()) { |
131 | 0 | roleIds = Collections.emptyList(); |
132 | |
} |
133 | 0 | if (groupIds == null || groupIds.isEmpty()) { |
134 | 0 | groupIds = Collections.emptyList(); |
135 | |
} |
136 | |
|
137 | 0 | switch (daoActionToTake) { |
138 | |
case ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS: |
139 | 0 | return roleDao.getRolePrincipalsForPrincipalIdAndRoleIds(roleIds, principalId, convertedQualification); |
140 | |
case ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS: |
141 | 0 | return roleDao.getRoleGroupsForGroupIdsAndRoleIds(roleIds, groupIds, convertedQualification); |
142 | |
case ROLE_MEMBERS_FOR_ROLE_IDS: |
143 | 0 | return roleDao.getRoleMembersForRoleIds(roleIds, memberTypeCode, convertedQualification); |
144 | |
case ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS: |
145 | 0 | return roleDao.getRoleMembershipsForRoleIdsAsMembers(roleIds, convertedQualification); |
146 | |
case ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS: |
147 | 0 | return roleDao.getRoleMembersForRoleIdsWithFilters(roleIds, principalId, groupIds, convertedQualification); |
148 | |
default: |
149 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-role-member-related value!"); |
150 | |
} |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
protected List<RoleMemberBo> getStoredRolePrincipalsForPrincipalIdAndRoleIds(Collection<String> roleIds, String principalId, Map<String, String> qualification) { |
157 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS, roleIds, principalId, Collections.<String>emptyList(), null, qualification); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
protected List<RoleMemberBo> getStoredRoleGroupsForGroupIdsAndRoleIds(Collection<String> roleIds, Collection<String> groupIds, Map<String, String> qualification) { |
164 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS, roleIds, null, groupIds, null, qualification); |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
protected List<RoleMemberBo> getStoredRoleMembersForRoleIds(Collection<String> roleIds, String memberTypeCode, Map<String, String> qualification) { |
171 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERS_FOR_ROLE_IDS, roleIds, null, Collections.<String>emptyList(), memberTypeCode, qualification); |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
protected List<RoleMemberBo> getStoredRoleMembershipsForRoleIdsAsMembers(Collection<String> roleIds, Map<String, String> qualification) { |
178 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS, roleIds, null, Collections.<String>emptyList(), null, qualification); |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
protected List<RoleMemberBo> getStoredRoleMembersForRoleIdsWithFilters(Collection<String> roleIds, String principalId, List<String> groupIds, Map<String, String> qualification) { |
185 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS, roleIds, principalId, groupIds, null, qualification); |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
protected RoleMemberBo getRoleMemberBo(String roleMemberId) { |
194 | 0 | if (StringUtils.isBlank(roleMemberId)) { |
195 | 0 | return null; |
196 | |
} |
197 | |
|
198 | 0 | return getBusinessObjectService().findByPrimaryKey(RoleMemberBo.class, Collections.singletonMap( |
199 | |
KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId)); |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
protected Map<String, DelegateTypeBo> getStoredDelegationImplMapFromRoleIds(Collection<String> roleIds) { |
206 | 0 | if (roleIds != null && !roleIds.isEmpty()) { |
207 | 0 | return roleDao.getDelegationImplMapFromRoleIds(roleIds); |
208 | |
} |
209 | |
|
210 | 0 | return Collections.emptyMap(); |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
protected List<DelegateTypeBo> getStoredDelegationImplsForRoleIds(Collection<String> roleIds) { |
217 | 0 | if (roleIds != null && !roleIds.isEmpty()) { |
218 | 0 | return roleDao.getDelegationBosForRoleIds(roleIds); |
219 | |
} |
220 | 0 | return Collections.emptyList(); |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
protected List<DelegateMemberBo> getDelegationMemberBoList(RoleDaoAction daoActionToTake, Collection<String> delegationIds, |
234 | |
String principalId, List<String> groupIds) { |
235 | 0 | if (delegationIds == null || delegationIds.isEmpty()) { |
236 | 0 | delegationIds = Collections.emptyList(); |
237 | |
} |
238 | 0 | if (groupIds == null || groupIds.isEmpty()) { |
239 | 0 | groupIds = Collections.emptyList(); |
240 | |
} |
241 | |
|
242 | 0 | switch (daoActionToTake) { |
243 | |
case DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS: |
244 | 0 | return roleDao.getDelegationPrincipalsForPrincipalIdAndDelegationIds(delegationIds, principalId); |
245 | |
case DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS: |
246 | 0 | return roleDao.getDelegationGroupsForGroupIdsAndDelegationIds(delegationIds, groupIds); |
247 | |
default: |
248 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-delegation-member-list-related value!"); |
249 | |
} |
250 | |
} |
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
protected List<DelegateMemberBo> getStoredDelegationPrincipalsForPrincipalIdAndDelegationIds(Collection<String> delegationIds, String principalId) { |
256 | 0 | return getDelegationMemberBoList(RoleDaoAction.DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS, |
257 | |
delegationIds, principalId, null); |
258 | |
} |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
protected DelegateMemberBo getDelegateMemberBo(String delegationMemberId) { |
265 | 0 | if (StringUtils.isBlank(delegationMemberId)) { |
266 | 0 | return null; |
267 | |
} |
268 | |
|
269 | 0 | return getBusinessObjectService().findByPrimaryKey(DelegateMemberBo.class, |
270 | |
Collections.singletonMap(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMemberId)); |
271 | |
} |
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
protected List<DelegateMemberBo> getDelegationMemberBoListByMemberAndDelegationId(String memberId, String delegationId) { |
278 | |
|
279 | 0 | Map<String, String> searchCriteria = new HashMap<String, String>(); |
280 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.MEMBER_ID, memberId); |
281 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_ID, delegationId); |
282 | 0 | return new ArrayList<DelegateMemberBo>(getBusinessObjectService().findMatching(DelegateMemberBo.class, searchCriteria)); |
283 | |
} |
284 | |
|
285 | |
protected Object getMember(String memberTypeCode, String memberId) { |
286 | 0 | if (StringUtils.isBlank(memberId)) { |
287 | 0 | return null; |
288 | |
} |
289 | 0 | if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { |
290 | 0 | return getIdentityService().getPrincipal(memberId); |
291 | 0 | } else if (MemberType.GROUP.getCode().equals(memberTypeCode)) { |
292 | 0 | return getGroupService().getGroup(memberId); |
293 | 0 | } else if (MemberType.ROLE.getCode().equals(memberTypeCode)) { |
294 | 0 | return getRoleBo(memberId); |
295 | |
} |
296 | 0 | return null; |
297 | |
} |
298 | |
|
299 | |
protected String getMemberName(Object member) { |
300 | 0 | if (member == null) { |
301 | 0 | return ""; |
302 | |
} |
303 | 0 | if (member instanceof Principal) { |
304 | 0 | return ((Principal) member).getPrincipalName(); |
305 | |
} |
306 | 0 | if (member instanceof Group) { |
307 | 0 | return ((Group) member).getName(); |
308 | |
} |
309 | 0 | if (member instanceof Role) { |
310 | 0 | return ((Role) member).getName(); |
311 | |
} |
312 | 0 | return member.toString(); |
313 | |
} |
314 | |
|
315 | |
protected RoleBo getRoleBo(String roleId) { |
316 | 0 | if (StringUtils.isBlank(roleId)) { |
317 | 0 | return null; |
318 | |
} |
319 | 0 | return getBusinessObjectService().findBySinglePrimaryKey(RoleBo.class, roleId); |
320 | |
} |
321 | |
|
322 | |
protected DelegateTypeBo getDelegationOfType(String roleId, DelegationType delegationType) { |
323 | 0 | List<DelegateTypeBo> roleDelegates = getRoleDelegations(roleId); |
324 | 0 | if (isDelegationPrimary(delegationType)) { |
325 | 0 | return getPrimaryDelegation(roleId, roleDelegates); |
326 | |
} else { |
327 | 0 | return getSecondaryDelegation(roleId, roleDelegates); |
328 | |
} |
329 | |
} |
330 | |
|
331 | |
private DelegateTypeBo getSecondaryDelegation(String roleId, List<DelegateTypeBo> roleDelegates) { |
332 | 0 | DelegateTypeBo secondaryDelegate = null; |
333 | 0 | RoleBo roleBo = getRoleBo(roleId); |
334 | 0 | for (DelegateTypeBo delegate : roleDelegates) { |
335 | 0 | if (isDelegationSecondary(delegate.getDelegationType())) { |
336 | 0 | secondaryDelegate = delegate; |
337 | |
} |
338 | |
} |
339 | 0 | if (secondaryDelegate == null) { |
340 | 0 | secondaryDelegate = new DelegateTypeBo(); |
341 | 0 | secondaryDelegate.setRoleId(roleId); |
342 | 0 | secondaryDelegate.setDelegationType(DelegationType.PRIMARY); |
343 | 0 | secondaryDelegate.setKimTypeId(roleBo.getKimTypeId()); |
344 | |
} |
345 | 0 | return secondaryDelegate; |
346 | |
} |
347 | |
|
348 | |
protected DelegateTypeBo getPrimaryDelegation(String roleId, List<DelegateTypeBo> roleDelegates) { |
349 | 0 | DelegateTypeBo primaryDelegate = null; |
350 | 0 | RoleBo roleBo = getRoleBo(roleId); |
351 | 0 | for (DelegateTypeBo delegate : roleDelegates) { |
352 | 0 | if (isDelegationPrimary(delegate.getDelegationType())) { |
353 | 0 | primaryDelegate = delegate; |
354 | |
} |
355 | |
} |
356 | 0 | if (primaryDelegate == null) { |
357 | 0 | primaryDelegate = new DelegateTypeBo(); |
358 | 0 | primaryDelegate.setRoleId(roleId); |
359 | 0 | primaryDelegate.setDelegationType(DelegationType.PRIMARY); |
360 | 0 | primaryDelegate.setKimTypeId(roleBo.getKimTypeId()); |
361 | |
} |
362 | 0 | return primaryDelegate; |
363 | |
} |
364 | |
|
365 | |
protected RoleMemberBo matchingMemberRecord(List<RoleMemberBo> roleMembers, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
366 | 0 | for (RoleMemberBo rm : roleMembers) { |
367 | 0 | if (doesMemberMatch(rm, memberId, memberTypeCode, qualifier)) { |
368 | 0 | return rm; |
369 | |
} |
370 | |
} |
371 | 0 | return null; |
372 | |
} |
373 | |
|
374 | |
protected boolean isDelegationPrimary(DelegationType delegationType) { |
375 | 0 | return DelegationType.PRIMARY.equals(delegationType); |
376 | |
} |
377 | |
|
378 | |
protected boolean isDelegationSecondary(DelegationType delegationType) { |
379 | 0 | return DelegationType.SECONDARY.equals(delegationType); |
380 | |
} |
381 | |
|
382 | |
|
383 | |
private List<DelegateTypeBo> getRoleDelegations(String roleId) { |
384 | 0 | if (roleId == null) { |
385 | 0 | return new ArrayList<DelegateTypeBo>(); |
386 | |
} |
387 | 0 | return getStoredDelegationImplsForRoleIds(Collections.singletonList(roleId)); |
388 | |
|
389 | |
} |
390 | |
|
391 | |
protected RoleBo getRoleBoByName(String namespaceCode, String roleName) { |
392 | 0 | if (StringUtils.isBlank(namespaceCode) |
393 | |
|| StringUtils.isBlank(roleName)) { |
394 | 0 | return null; |
395 | |
} |
396 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
397 | 0 | criteria.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode); |
398 | 0 | criteria.put(KimConstants.UniqueKeyConstants.NAME, roleName); |
399 | 0 | criteria.put(KRADPropertyConstants.ACTIVE, "Y"); |
400 | |
|
401 | 0 | return getBusinessObjectService().findByPrimaryKey(RoleBo.class, criteria); |
402 | |
} |
403 | |
|
404 | |
protected boolean doAnyMemberRecordsMatchByExactQualifier( RoleBo role, String memberId, RoleDaoAction daoActionToTake, Map<String, String> qualifier ) { |
405 | 0 | if(CollectionUtils.isNotEmpty(getRoleMembersByExactQualifierMatch(role, memberId, daoActionToTake, qualifier))) { |
406 | 0 | return true; |
407 | |
} |
408 | |
|
409 | 0 | return false; |
410 | |
} |
411 | |
|
412 | |
protected List<RoleMemberBo> getRoleMembersByExactQualifierMatch(RoleBo role, String memberId, RoleDaoAction daoActionToTake, Map<String, String> qualifier) { |
413 | 0 | List<RoleMemberBo> rms = new ArrayList<RoleMemberBo>(); |
414 | 0 | RoleTypeService roleTypeService = getRoleTypeService( role.getId() ); |
415 | 0 | if(roleTypeService != null) { |
416 | 0 | List<String> attributesForExactMatch = roleTypeService.getQualifiersForExactMatch(); |
417 | 0 | if(CollectionUtils.isNotEmpty(attributesForExactMatch)) { |
418 | 0 | switch (daoActionToTake) { |
419 | |
case ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS : |
420 | 0 | rms = getStoredRoleGroupsForGroupIdsAndRoleIds(Collections.singletonList(role.getId()), Collections.singletonList(memberId), populateQualifiersForExactMatch(qualifier, attributesForExactMatch)); |
421 | 0 | break; |
422 | |
case ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS : |
423 | 0 | rms = getStoredRolePrincipalsForPrincipalIdAndRoleIds(Collections.singletonList(role.getId()), memberId, populateQualifiersForExactMatch(qualifier, attributesForExactMatch)); |
424 | 0 | break; |
425 | |
case ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS : |
426 | 0 | List<RoleMemberBo> allRoleMembers = getStoredRoleMembershipsForRoleIdsAsMembers(Collections.singletonList(role.getId()), populateQualifiersForExactMatch(qualifier, attributesForExactMatch)); |
427 | 0 | for(RoleMemberBo rm : allRoleMembers) { |
428 | 0 | if ( rm.getMemberId().equals(memberId) ) { |
429 | 0 | rms.add(rm); |
430 | |
} |
431 | |
} |
432 | 0 | break; |
433 | |
default : |
434 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-role-member-related value!"); |
435 | |
} |
436 | |
|
437 | |
} |
438 | |
} |
439 | 0 | return rms; |
440 | |
} |
441 | |
|
442 | |
protected boolean doAnyMemberRecordsMatch(List<RoleMemberBo> roleMembers, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
443 | 0 | for (RoleMemberBo rm : roleMembers) { |
444 | 0 | if (doesMemberMatch(rm, memberId, memberTypeCode, qualifier)) { |
445 | 0 | return true; |
446 | |
} |
447 | |
} |
448 | 0 | return false; |
449 | |
} |
450 | |
|
451 | |
protected boolean doesMemberMatch(RoleMemberBo roleMember, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
452 | 0 | if (roleMember.getMemberId().equals(memberId) && roleMember.getMemberType().getCode().equals(memberTypeCode)) { |
453 | |
|
454 | 0 | Map<String, String> roleQualifier = roleMember.getAttributes(); |
455 | 0 | if ((qualifier == null || qualifier.isEmpty()) |
456 | |
&& (roleQualifier == null || roleQualifier.isEmpty())) { |
457 | 0 | return true; |
458 | |
} else { |
459 | 0 | if (qualifier != null && roleQualifier != null && qualifier.equals(roleQualifier)) { |
460 | 0 | return true; |
461 | |
} |
462 | |
} |
463 | |
} |
464 | 0 | return false; |
465 | |
} |
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
|
473 | |
protected RoleTypeService getRoleTypeService(String roleId) { |
474 | 0 | RoleBo roleBo = getRoleBo(roleId); |
475 | 0 | KimType roleType = KimTypeBo.to(roleBo.getKimRoleType()); |
476 | 0 | if (roleType != null) { |
477 | 0 | return getRoleTypeService(roleType); |
478 | |
} |
479 | 0 | return null; |
480 | |
} |
481 | |
|
482 | |
protected RoleTypeService getRoleTypeService(KimType typeInfo) { |
483 | 0 | String serviceName = typeInfo.getServiceName(); |
484 | 0 | if (serviceName != null) { |
485 | |
try { |
486 | 0 | KimTypeService service = (KimTypeService) KimImplServiceLocator.getService(serviceName); |
487 | 0 | if (service != null && service instanceof RoleTypeService) { |
488 | 0 | return (RoleTypeService) service; |
489 | |
} |
490 | 0 | return (RoleTypeService) KimImplServiceLocator.getService("kimNoMembersRoleTypeService"); |
491 | 0 | } catch (Exception ex) { |
492 | 0 | LOG.error("Unable to find role type service with name: " + serviceName, ex); |
493 | 0 | return (RoleTypeService) KimImplServiceLocator.getService("kimNoMembersRoleTypeService"); |
494 | |
} |
495 | |
} |
496 | 0 | return null; |
497 | |
} |
498 | |
|
499 | |
protected Map<String, String> populateQualifiersForExactMatch(Map<String, String> defaultQualification, List<String> attributes) { |
500 | 0 | Map<String,String> qualifiersForExactMatch = new HashMap<String,String>(); |
501 | 0 | if (defaultQualification != null && CollectionUtils.isNotEmpty(defaultQualification.keySet())) { |
502 | 0 | for (String attributeName : attributes) { |
503 | 0 | if (StringUtils.isNotEmpty(defaultQualification.get(attributeName))) { |
504 | 0 | qualifiersForExactMatch.put(attributeName, defaultQualification.get(attributeName)); |
505 | |
} |
506 | |
} |
507 | |
} |
508 | 0 | return qualifiersForExactMatch; |
509 | |
} |
510 | |
|
511 | |
|
512 | |
protected String getKimAttributeId(String attributeName) { |
513 | |
|
514 | 0 | Map<String, Object> critieria = new HashMap<String, Object>(1); |
515 | 0 | critieria.put("attributeName", attributeName); |
516 | 0 | Collection<KimAttributeBo> defs = getBusinessObjectService().findMatching(KimAttributeBo.class, critieria); |
517 | 0 | String result = null; |
518 | 0 | if (CollectionUtils.isNotEmpty(defs)) { |
519 | 0 | result = defs.iterator().next().getId(); |
520 | |
} |
521 | 0 | return result; |
522 | |
} |
523 | |
|
524 | |
protected BusinessObjectService getBusinessObjectService() { |
525 | 0 | if (businessObjectService == null) { |
526 | 0 | businessObjectService = KRADServiceLocator.getBusinessObjectService(); |
527 | |
} |
528 | 0 | return businessObjectService; |
529 | |
} |
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
protected LookupService getLookupService() { |
535 | 0 | if (lookupService == null) { |
536 | 0 | lookupService = KRADServiceLocatorWeb.getLookupService(); |
537 | |
} |
538 | 0 | return lookupService; |
539 | |
} |
540 | |
|
541 | |
protected IdentityService getIdentityService() { |
542 | 0 | if (identityService == null) { |
543 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
544 | |
} |
545 | |
|
546 | 0 | return identityService; |
547 | |
} |
548 | |
|
549 | |
protected GroupService getGroupService() { |
550 | 0 | if (groupService == null) { |
551 | 0 | groupService = KimApiServiceLocator.getGroupService(); |
552 | |
} |
553 | |
|
554 | 0 | return groupService; |
555 | |
} |
556 | |
|
557 | |
protected ResponsibilityInternalService getResponsibilityInternalService() { |
558 | 0 | if (responsibilityInternalService == null) { |
559 | 0 | responsibilityInternalService = KimImplServiceLocator.getResponsibilityInternalService(); |
560 | |
} |
561 | 0 | return responsibilityInternalService; |
562 | |
} |
563 | |
|
564 | |
|
565 | |
|
566 | |
|
567 | |
protected RoleDao getRoleDao() { |
568 | 0 | return this.roleDao; |
569 | |
} |
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
public void setRoleDao(RoleDao roleDao) { |
575 | 0 | this.roleDao = roleDao; |
576 | 0 | } |
577 | |
|
578 | |
public void setCriteriaLookupService(final CriteriaLookupService criteriaLookupService) { |
579 | 0 | this.criteriaLookupService = criteriaLookupService; |
580 | 0 | } |
581 | |
|
582 | |
public CriteriaLookupService getCriteriaLookupService() { |
583 | 0 | return criteriaLookupService; |
584 | |
} |
585 | |
|
586 | |
} |