1 | |
package org.kuali.rice.kim.impl.role; |
2 | |
|
3 | |
import org.apache.commons.collections.CollectionUtils; |
4 | |
import org.apache.commons.lang.StringUtils; |
5 | |
import org.kuali.rice.kew.api.action.DelegationType; |
6 | |
import org.kuali.rice.kim.api.common.delegate.DelegateMember; |
7 | |
import org.kuali.rice.kim.api.group.Group; |
8 | |
import org.kuali.rice.kim.api.group.GroupService; |
9 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
10 | |
import org.kuali.rice.kim.api.role.Role; |
11 | |
import org.kuali.rice.kim.api.role.RoleMember; |
12 | |
import org.kuali.rice.kim.api.role.RoleResponsibilityAction; |
13 | |
import org.kuali.rice.kim.api.services.IdentityService; |
14 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
15 | |
import org.kuali.rice.kim.framework.type.KimDelegationTypeService; |
16 | |
import org.kuali.rice.kim.framework.type.KimRoleTypeService; |
17 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeBo; |
18 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateBo; |
19 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateMemberBo; |
20 | |
import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService; |
21 | |
import org.kuali.rice.kim.impl.services.KIMServiceLocatorInternal; |
22 | |
import org.kuali.rice.kim.service.IdentityManagementNotificationService; |
23 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
24 | |
import org.kuali.rice.kim.util.KimConstants; |
25 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
26 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
27 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
28 | |
import org.kuali.rice.krad.service.LookupService; |
29 | |
import org.kuali.rice.krad.service.SequenceAccessorService; |
30 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
31 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
32 | |
import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator; |
33 | |
|
34 | |
import javax.xml.namespace.QName; |
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collection; |
37 | |
import java.util.Collections; |
38 | |
import java.util.HashMap; |
39 | |
import java.util.HashSet; |
40 | |
import java.util.List; |
41 | |
import java.util.Map; |
42 | |
import java.util.Set; |
43 | |
|
44 | 0 | public class RoleServiceBase { |
45 | |
protected static final String ROLE_IMPL_CACHE_PREFIX = "RoleImpl-ID-"; |
46 | |
protected static final String ROLE_IMPL_BY_NAME_CACHE_PREFIX = "RoleImpl-Name-"; |
47 | |
protected static final String ROLE_IMPL_CACHE_GROUP = "RoleImpl"; |
48 | |
|
49 | |
protected static final String ROLE_MEMBER_IMPL_CACHE_PREFIX = "RoleMemberBo-ID-"; |
50 | |
protected static final String ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX = "RoleMemberBo-List-"; |
51 | |
protected static final String ROLE_MEMBER_IMPL_CACHE_GROUP = "RoleMemberBo"; |
52 | |
|
53 | |
protected static final String DELEGATION_IMPL_CACHE_PREFIX = "DelegateBo-ID-"; |
54 | |
protected static final String DELEGATION_IMPL_LIST_CACHE_PREFIX = "DelegateBo-List-"; |
55 | |
protected static final String DELEGATION_IMPL_CACHE_GROUP = "DelegateBo"; |
56 | |
|
57 | |
protected static final String DELEGATION_MEMBER_IMPL_CACHE_PREFIX = "DelegateMemberBo-ID-"; |
58 | |
protected static final String DELEGATION_MEMBER_IMPL_BY_DLGN_AND_ID_CACHE_PREFIX = "DelegateMemberBo-DelegationAndId-"; |
59 | |
protected static final String DELEGATION_MEMBER_IMPL_LIST_CACHE_PREFIX = "DelegateMemberBo-List-"; |
60 | |
protected static final String DELEGATION_MEMBER_IMPL_LIST_BY_MBR_DLGN_CACHE_PREFIX = "DelegateMemberBo-List-MemberAndDelegationId-"; |
61 | |
protected static final String DELEGATION_MEMBER_IMPL_CACHE_GROUP = "DelegateMemberBo"; |
62 | |
|
63 | |
private BusinessObjectService businessObjectService; |
64 | |
private LookupService lookupService; |
65 | |
private RiceCacheAdministrator cacheAdministrator; |
66 | |
private SequenceAccessorService sequenceAccessorService; |
67 | |
private IdentityService identityService; |
68 | |
private GroupService groupService; |
69 | |
private ResponsibilityInternalService responsibilityInternalService; |
70 | |
|
71 | 0 | private Map<String, KimRoleTypeService> roleTypeServiceCache = Collections.synchronizedMap(new HashMap<String, KimRoleTypeService>()); |
72 | 0 | private Map<String, KimDelegationTypeService> delegationTypeServiceCache = Collections.synchronizedMap(new HashMap<String, KimDelegationTypeService>()); |
73 | |
|
74 | 0 | private Map<String, Boolean> applicationRoleTypeCache = Collections.synchronizedMap(new HashMap<String, Boolean>()); |
75 | |
private RoleDao roleDao; |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | 0 | public static enum RoleDaoAction { |
83 | 0 | ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS("principalMembers-"), |
84 | 0 | ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS("groupMembers-"), |
85 | 0 | ROLE_MEMBERS_FOR_ROLE_IDS("membersOfRole-"), |
86 | 0 | ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS("rolesAsMembers-"), |
87 | 0 | ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS("roleIdsWithFilters-"), |
88 | 0 | DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS("delegationPrincipals-"), |
89 | 0 | DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS("delegationGroups-"), |
90 | 0 | DELEGATION_MEMBERS_FOR_DELEGATION_IDS("delegationMembers-"); |
91 | |
|
92 | |
public final String DAO_ACTION_CACHE_PREFIX; |
93 | |
|
94 | 0 | private RoleDaoAction(String daoActionCachePrefix) { |
95 | 0 | this.DAO_ACTION_CACHE_PREFIX = daoActionCachePrefix; |
96 | 0 | } |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
protected String getRoleMemberCacheKey(String roleMemberId) { |
110 | 0 | return ROLE_MEMBER_IMPL_CACHE_PREFIX + roleMemberId; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
protected String getRoleMemberListCacheKey(RoleDaoAction roleDaoAction, String roleId, String principalId, String groupId, String memberTypeCode) { |
129 | 0 | switch (roleDaoAction) { |
130 | |
case ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS: |
131 | 0 | return new StringBuilder(ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX).append(roleDaoAction.DAO_ACTION_CACHE_PREFIX).append( |
132 | |
StringUtils.isBlank(roleId) ? "" : roleId).append('-').append(StringUtils.isBlank(principalId) ? "" : principalId).toString(); |
133 | |
case ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS: |
134 | 0 | return new StringBuilder(ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX).append(roleDaoAction.DAO_ACTION_CACHE_PREFIX).append( |
135 | |
StringUtils.isBlank(roleId) ? "" : roleId).append('-').append(StringUtils.isBlank(groupId) ? "" : groupId).toString(); |
136 | |
case ROLE_MEMBERS_FOR_ROLE_IDS: |
137 | 0 | return new StringBuilder(ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX).append(roleDaoAction.DAO_ACTION_CACHE_PREFIX).append( |
138 | |
StringUtils.isBlank(roleId) ? "" : roleId).append('-').append(StringUtils.isBlank(memberTypeCode) ? "" : memberTypeCode).toString(); |
139 | |
case ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS: |
140 | 0 | return new StringBuilder(ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX).append(roleDaoAction.DAO_ACTION_CACHE_PREFIX).append( |
141 | |
StringUtils.isBlank(roleId) ? "" : roleId).toString(); |
142 | |
case ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS: |
143 | 0 | return new StringBuilder(ROLE_MEMBER_IMPL_LIST_CACHE_PREFIX).append(roleDaoAction.DAO_ACTION_CACHE_PREFIX).append( |
144 | |
StringUtils.isBlank(roleId) ? "" : roleId).append('-').append(StringUtils.isBlank(principalId) ? "" : principalId).append( |
145 | |
'-').append(StringUtils.isBlank(groupId) ? "" : groupId).append('-').append( |
146 | |
StringUtils.isBlank(memberTypeCode) ? "" : memberTypeCode).toString(); |
147 | |
default: |
148 | 0 | throw new IllegalArgumentException("The 'roleDaoAction' parameter cannot refer to a non-role-member-related value!"); |
149 | |
} |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
private Map<String, String> convertQualifierKeys(Map<String, String> qualification) { |
159 | 0 | Map<String, String> convertedQualification = new HashMap<String, String>(); |
160 | 0 | if (qualification != null && CollectionUtils.isNotEmpty(qualification.keySet())) { |
161 | 0 | for (String attributeName : qualification.keySet()) { |
162 | 0 | if (StringUtils.isNotEmpty(getKimAttributeId(attributeName))) { |
163 | 0 | convertedQualification.put(getKimAttributeId(attributeName), qualification.get(attributeName)); |
164 | |
} |
165 | |
} |
166 | |
} |
167 | 0 | return convertedQualification; |
168 | |
} |
169 | |
|
170 | |
public Set<String> getRoleTypeRoleMemberIds(String roleId) { |
171 | 0 | Set<String> results = new HashSet(); |
172 | 0 | getNestedRoleTypeMemberIds(roleId, results); |
173 | 0 | return results; |
174 | |
} |
175 | |
|
176 | |
protected void getNestedRoleTypeMemberIds(String roleId, Set members) throws RuntimeException { |
177 | 0 | ArrayList<String> roleList = new ArrayList<String>(1); |
178 | 0 | roleList.add(roleId); |
179 | 0 | List<RoleMemberBo> firstLevelMembers = getStoredRoleMembersForRoleIds(roleList, KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE, null); |
180 | 0 | for (RoleMemberBo member : firstLevelMembers) { |
181 | 0 | if (KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(member.getMemberTypeCode())) { |
182 | 0 | if (!members.contains(member.getMemberId())) { |
183 | 0 | members.add(member.getMemberId()); |
184 | 0 | getNestedRoleTypeMemberIds(member.getMemberId(), members); |
185 | |
} |
186 | |
} |
187 | |
} |
188 | 0 | } |
189 | |
|
190 | |
public List<String> getMemberParentRoleIds(String memberType, String memberId) { |
191 | 0 | List<RoleMemberBo> parentRoleMembers = roleDao.getRoleMembershipsForMemberId(memberType, memberId, null); |
192 | |
|
193 | 0 | List<String> parentRoleIds = new ArrayList<String>(parentRoleMembers.size()); |
194 | 0 | for (RoleMemberBo parentRoleMember : parentRoleMembers) { |
195 | 0 | parentRoleIds.add(parentRoleMember.getRoleId()); |
196 | |
} |
197 | |
|
198 | 0 | return parentRoleIds; |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
protected List<RoleMemberBo> getRoleMemberBoList(RoleDaoAction daoActionToTake, Collection<String> roleIds, String principalId, |
214 | |
Collection<String> groupIds, String memberTypeCode, Map<String, String> qualification) { |
215 | 0 | List<RoleMemberBo> finalResults = new ArrayList<RoleMemberBo>(); |
216 | 0 | List<RoleMemberCacheKeyHelper> searchKeys = new ArrayList<RoleMemberCacheKeyHelper>(); |
217 | 0 | List<RoleMemberCacheKeyHelper> uncachedKeys = new ArrayList<RoleMemberCacheKeyHelper>(); |
218 | 0 | Set<String> usedKeys = new HashSet<String>(); |
219 | 0 | Map<String, String> convertedQualification = convertQualifierKeys(qualification); |
220 | |
|
221 | 0 | if (roleIds == null || roleIds.isEmpty()) { |
222 | 0 | roleIds = Collections.singletonList(null); |
223 | |
} |
224 | 0 | if (groupIds == null || groupIds.isEmpty()) { |
225 | 0 | groupIds = Collections.singletonList(null); |
226 | |
} |
227 | |
|
228 | |
|
229 | 0 | switch (daoActionToTake) { |
230 | |
case ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS: |
231 | 0 | for (String roleId : roleIds) { |
232 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, principalId, null, Role.PRINCIPAL_MEMBER_TYPE)); |
233 | |
} |
234 | 0 | break; |
235 | |
case ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS: |
236 | 0 | for (String roleId : roleIds) { |
237 | 0 | for (String groupId : groupIds) { |
238 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, null, groupId, Role.GROUP_MEMBER_TYPE)); |
239 | |
} |
240 | |
} |
241 | 0 | break; |
242 | |
case ROLE_MEMBERS_FOR_ROLE_IDS: |
243 | 0 | for (String roleId : roleIds) { |
244 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, null, null, memberTypeCode)); |
245 | |
} |
246 | 0 | break; |
247 | |
case ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS: |
248 | 0 | for (String roleId : roleIds) { |
249 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, null, null, Role.ROLE_MEMBER_TYPE)); |
250 | |
} |
251 | 0 | break; |
252 | |
case ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS: |
253 | 0 | for (String roleId : roleIds) { |
254 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, null, null, Role.ROLE_MEMBER_TYPE)); |
255 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, principalId, null, Role.PRINCIPAL_MEMBER_TYPE)); |
256 | 0 | for (String groupId : groupIds) { |
257 | 0 | searchKeys.add(new RoleMemberCacheKeyHelper(daoActionToTake, roleId, null, groupId, Role.GROUP_MEMBER_TYPE)); |
258 | |
} |
259 | |
} |
260 | 0 | break; |
261 | |
default: |
262 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-role-member-related value!"); |
263 | |
} |
264 | |
|
265 | |
|
266 | 0 | for (RoleMemberCacheKeyHelper searchKey : searchKeys) { |
267 | 0 | if (!usedKeys.contains(searchKey.getCacheKey())) { |
268 | 0 | List<RoleMemberBo> tempMembers = (List<RoleMemberBo>) getCacheAdministrator().getFromCache(searchKey.getCacheKey()); |
269 | 0 | if (tempMembers != null) { |
270 | 0 | finalResults.addAll(tempMembers); |
271 | |
} else { |
272 | 0 | uncachedKeys.add(searchKey); |
273 | |
} |
274 | 0 | usedKeys.add(searchKey.getCacheKey()); |
275 | 0 | } |
276 | |
} |
277 | |
|
278 | |
|
279 | 0 | if (!uncachedKeys.isEmpty()) { |
280 | 0 | Set<String> uncachedRoleSet = new HashSet<String>(); |
281 | 0 | Set<String> uncachedGroupSet = new HashSet<String>(); |
282 | 0 | for (RoleMemberCacheKeyHelper uncachedKey : uncachedKeys) { |
283 | 0 | if (uncachedKey.ROLE_ID != null) { |
284 | 0 | uncachedRoleSet.add(uncachedKey.ROLE_ID); |
285 | |
} |
286 | 0 | if (uncachedKey.GROUP_ID != null) { |
287 | 0 | uncachedGroupSet.add(uncachedKey.GROUP_ID); |
288 | |
} |
289 | |
} |
290 | |
|
291 | 0 | List<String> uncachedRoles = (uncachedRoleSet.isEmpty()) ? null : new ArrayList<String>(uncachedRoleSet); |
292 | 0 | List<String> uncachedGroups = (uncachedGroupSet.isEmpty()) ? null : new ArrayList<String>(uncachedGroupSet); |
293 | |
List<RoleMemberBo> uncachedResults; |
294 | |
|
295 | |
|
296 | 0 | switch (daoActionToTake) { |
297 | |
case ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS: |
298 | 0 | uncachedResults = roleDao.getRolePrincipalsForPrincipalIdAndRoleIds(uncachedRoles, principalId, convertedQualification); |
299 | 0 | break; |
300 | |
case ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS: |
301 | 0 | uncachedResults = roleDao.getRoleGroupsForGroupIdsAndRoleIds(uncachedRoles, uncachedGroups, convertedQualification); |
302 | 0 | break; |
303 | |
case ROLE_MEMBERS_FOR_ROLE_IDS: |
304 | 0 | uncachedResults = roleDao.getRoleMembersForRoleIds(uncachedRoles, memberTypeCode, convertedQualification); |
305 | 0 | break; |
306 | |
case ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS: |
307 | 0 | uncachedResults = roleDao.getRoleMembershipsForRoleIdsAsMembers(uncachedRoles, convertedQualification); |
308 | 0 | break; |
309 | |
case ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS: |
310 | 0 | uncachedResults = roleDao.getRoleMembersForRoleIdsWithFilters(uncachedRoles, principalId, uncachedGroups, convertedQualification); |
311 | 0 | break; |
312 | |
default: |
313 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-role-member-related value!"); |
314 | |
} |
315 | |
|
316 | 0 | cacheRoleMemberLists(uncachedKeys, uncachedResults); |
317 | 0 | for (RoleMemberBo uncachedMember : uncachedResults) { |
318 | 0 | addRoleMemberBoToCache(uncachedMember); |
319 | |
} |
320 | 0 | finalResults.addAll(uncachedResults); |
321 | |
} |
322 | 0 | return finalResults; |
323 | |
} |
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
private void cacheRoleMemberLists(List<RoleMemberCacheKeyHelper> keysToCache, List<RoleMemberBo> membersToCache) { |
333 | 0 | if (membersToCache == null) { |
334 | 0 | membersToCache = new ArrayList<RoleMemberBo>(); |
335 | |
} |
336 | 0 | for (RoleMemberCacheKeyHelper keyToCache : keysToCache) { |
337 | 0 | List<RoleMemberBo> roleMembers = new ArrayList<RoleMemberBo>(); |
338 | |
|
339 | |
|
340 | 0 | if (RoleDaoAction.ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS.equals(keyToCache.ROLE_DAO_ACTION)) { |
341 | 0 | boolean safeToCacheList = true; |
342 | 0 | for (RoleMemberBo memberToCache : membersToCache) { |
343 | 0 | if ((keyToCache.ROLE_ID == null || keyToCache.ROLE_ID.equals(memberToCache.getMemberId())) && |
344 | |
(keyToCache.MEMBER_TYPE_CODE == null || keyToCache.MEMBER_TYPE_CODE.equals(memberToCache.getMemberTypeCode()))) { |
345 | 0 | if (shouldCacheMembersOfRole(memberToCache.getRoleId())) { |
346 | 0 | roleMembers.add(memberToCache); |
347 | |
} else { |
348 | 0 | safeToCacheList = false; |
349 | 0 | break; |
350 | |
} |
351 | |
} |
352 | |
} |
353 | 0 | if (safeToCacheList) { |
354 | 0 | getCacheAdministrator().putInCache(keyToCache.getCacheKey(), roleMembers, ROLE_MEMBER_IMPL_CACHE_GROUP); |
355 | |
} |
356 | 0 | } else if (keyToCache.ROLE_ID == null || shouldCacheMembersOfRole(keyToCache.ROLE_ID)) { |
357 | 0 | for (RoleMemberBo memberToCache : membersToCache) { |
358 | 0 | if ((keyToCache.ROLE_ID == null || keyToCache.ROLE_ID.equals(memberToCache.getRoleId())) && |
359 | |
(keyToCache.PRINCIPAL_ID == null || keyToCache.PRINCIPAL_ID.equals(memberToCache.getMemberId())) && |
360 | |
(keyToCache.GROUP_ID == null || keyToCache.GROUP_ID.equals(memberToCache.getMemberId())) && |
361 | |
(keyToCache.MEMBER_TYPE_CODE == null || keyToCache.MEMBER_TYPE_CODE.equals(memberToCache.getMemberTypeCode()))) { |
362 | 0 | roleMembers.add(memberToCache); |
363 | |
} |
364 | |
} |
365 | 0 | getCacheAdministrator().putInCache(keyToCache.getCacheKey(), roleMembers, ROLE_MEMBER_IMPL_CACHE_GROUP); |
366 | |
} |
367 | 0 | } |
368 | 0 | } |
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
protected List<RoleMemberBo> getStoredRolePrincipalsForPrincipalIdAndRoleIds(Collection<String> roleIds, String principalId, Map<String, String> qualification) { |
374 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_PRINCIPALS_FOR_PRINCIPAL_ID_AND_ROLE_IDS, roleIds, principalId, null, null, qualification); |
375 | |
} |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
protected List<RoleMemberBo> getStoredRoleGroupsForGroupIdsAndRoleIds(Collection<String> roleIds, Collection<String> groupIds, Map<String, String> qualification) { |
381 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_GROUPS_FOR_GROUP_IDS_AND_ROLE_IDS, roleIds, null, groupIds, null, qualification); |
382 | |
} |
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
protected List<RoleMemberBo> getStoredRoleMembersForRoleIds(Collection<String> roleIds, String memberTypeCode, Map<String, String> qualification) { |
388 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERS_FOR_ROLE_IDS, roleIds, null, null, memberTypeCode, qualification); |
389 | |
} |
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
protected List<RoleMemberBo> getStoredRoleMembershipsForRoleIdsAsMembers(Collection<String> roleIds, Map<String, String> qualification) { |
395 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERSHIPS_FOR_ROLE_IDS_AS_MEMBERS, roleIds, null, null, null, qualification); |
396 | |
} |
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
protected List<RoleMemberBo> getStoredRoleMembersForRoleIdsWithFilters(Collection<String> roleIds, String principalId, List<String> groupIds, Map<String, String> qualification) { |
402 | 0 | return getRoleMemberBoList(RoleDaoAction.ROLE_MEMBERS_FOR_ROLE_IDS_WITH_FILTERS, roleIds, principalId, groupIds, null, qualification); |
403 | |
} |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
protected boolean shouldCacheMembersOfRole(String roleId) { |
413 | 0 | return true; |
414 | |
} |
415 | |
|
416 | |
protected void addRoleMemberBoToCache(RoleMemberBo roleMember) { |
417 | 0 | if (roleMember != null && shouldCacheMembersOfRole(roleMember.getRoleId())) { |
418 | 0 | getCacheAdministrator().putInCache(getRoleMemberCacheKey(roleMember.getRoleMemberId()), roleMember, ROLE_MEMBER_IMPL_CACHE_GROUP); |
419 | |
} |
420 | 0 | } |
421 | |
|
422 | |
protected RoleMemberBo getRoleMemberFromCache(String roleMemberId) { |
423 | 0 | return (RoleMemberBo) getCacheAdministrator().getFromCache(getRoleMemberCacheKey(roleMemberId)); |
424 | |
} |
425 | |
|
426 | |
public void flushInternalRoleMemberCache() { |
427 | 0 | getCacheAdministrator().flushGroup(ROLE_MEMBER_IMPL_CACHE_GROUP); |
428 | 0 | } |
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
protected RoleMemberBo getRoleMemberBo(String roleMemberId) { |
436 | 0 | if (StringUtils.isBlank(roleMemberId)) { |
437 | 0 | return null; |
438 | |
} |
439 | |
|
440 | |
|
441 | 0 | RoleMemberBo tempRoleMemberBo = getRoleMemberFromCache(roleMemberId); |
442 | 0 | if (tempRoleMemberBo != null) { |
443 | 0 | return tempRoleMemberBo; |
444 | |
} |
445 | |
|
446 | 0 | tempRoleMemberBo = getBusinessObjectService().findByPrimaryKey(RoleMemberBo.class, |
447 | |
Collections.singletonMap(KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId)); |
448 | 0 | addRoleMemberBoToCache(tempRoleMemberBo); |
449 | 0 | return tempRoleMemberBo; |
450 | |
} |
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
protected String getDelegationCacheKey(String delegationId) { |
463 | 0 | return DELEGATION_IMPL_CACHE_PREFIX + delegationId; |
464 | |
} |
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
protected String getDelegationListCacheKey(String roleId) { |
473 | 0 | return DELEGATION_IMPL_LIST_CACHE_PREFIX + (StringUtils.isBlank(roleId) ? "" : roleId); |
474 | |
} |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
protected Map<String, DelegateBo> getStoredDelegationImplMapFromRoleIds(Collection<String> roleIds) { |
480 | 0 | Map<String, DelegateBo> finalResults = Collections.emptyMap(); |
481 | |
|
482 | 0 | if (roleIds != null && !roleIds.isEmpty()) { |
483 | 0 | Map<String, List<DelegateBo>> uncachedLists = new HashMap<String, List<DelegateBo>>(); |
484 | |
|
485 | 0 | finalResults = getDelegationBoMap(uncachedLists, roleIds); |
486 | |
|
487 | |
|
488 | 0 | if (!uncachedLists.isEmpty()) { |
489 | 0 | Map<String, DelegateBo> uncachedResults = roleDao.getDelegationImplMapFromRoleIds( |
490 | |
uncachedLists.keySet()); |
491 | |
|
492 | 0 | for (Map.Entry<String, DelegateBo> uncachedResult : uncachedResults.entrySet()) { |
493 | 0 | finalResults.put(uncachedResult.getKey(), uncachedResult.getValue()); |
494 | 0 | addDelegationBoToCache(uncachedResult.getValue()); |
495 | 0 | uncachedLists.get(uncachedResult.getValue().getRoleId()).add(uncachedResult.getValue()); |
496 | |
} |
497 | 0 | for (Map.Entry<String, List<DelegateBo>> uncachedList : uncachedLists.entrySet()) { |
498 | 0 | getCacheAdministrator().putInCache(getDelegationListCacheKey(uncachedList.getKey()), |
499 | |
uncachedList.getValue(), DELEGATION_IMPL_CACHE_GROUP); |
500 | |
} |
501 | |
} |
502 | |
} |
503 | |
|
504 | 0 | return finalResults; |
505 | |
} |
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
protected List<DelegateBo> getStoredDelegationImplsForRoleIds(Collection<String> roleIds) { |
511 | 0 | List<DelegateBo> finalResults = new ArrayList<DelegateBo>(); |
512 | |
|
513 | 0 | if (roleIds != null && !roleIds.isEmpty()) { |
514 | 0 | Map<String, List<DelegateBo>> uncachedLists = new HashMap<String, List<DelegateBo>>(); |
515 | |
|
516 | 0 | Map<String, DelegateBo> tempDelegations = getDelegationBoMap(uncachedLists, roleIds); |
517 | 0 | finalResults.addAll(tempDelegations.values()); |
518 | |
|
519 | |
|
520 | 0 | if (!uncachedLists.isEmpty()) { |
521 | 0 | List<DelegateBo> uncachedResults = roleDao.getDelegationBosForRoleIds(uncachedLists.keySet()); |
522 | |
|
523 | 0 | for (DelegateBo uncachedResult : uncachedResults) { |
524 | 0 | addDelegationBoToCache(uncachedResult); |
525 | 0 | uncachedLists.get(uncachedResult.getRoleId()).add(uncachedResult); |
526 | |
} |
527 | 0 | for (Map.Entry<String, List<DelegateBo>> uncachedList : uncachedLists.entrySet()) { |
528 | 0 | getCacheAdministrator().putInCache(getDelegationListCacheKey(uncachedList.getKey()), |
529 | |
uncachedList.getValue(), DELEGATION_IMPL_CACHE_GROUP); |
530 | |
} |
531 | 0 | finalResults.addAll(uncachedResults); |
532 | |
} |
533 | |
} |
534 | |
|
535 | 0 | return finalResults; |
536 | |
} |
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
|
547 | |
protected Map<String, DelegateBo> getDelegationBoMap(Map<String, List<DelegateBo>> uncachedLists, Collection<String> roleIds) { |
548 | 0 | if (uncachedLists == null) { |
549 | 0 | throw new IllegalArgumentException("'uncachedLists' parameter cannot be null!"); |
550 | |
} |
551 | 0 | Map<String, DelegateBo> delegationMap = new HashMap<String, DelegateBo>(); |
552 | |
|
553 | |
|
554 | 0 | if (roleIds != null && !roleIds.isEmpty()) { |
555 | 0 | for (String roleId : roleIds) { |
556 | 0 | List<DelegateBo> tempDelegates = (List<DelegateBo>) getCacheAdministrator().getFromCache(getDelegationListCacheKey(roleId)); |
557 | 0 | if (tempDelegates != null) { |
558 | 0 | for (DelegateBo tempDelegate : tempDelegates) { |
559 | 0 | delegationMap.put(tempDelegate.getDelegationId(), tempDelegate); |
560 | |
} |
561 | |
} else { |
562 | 0 | uncachedLists.put(roleId, new ArrayList<DelegateBo>()); |
563 | |
} |
564 | 0 | } |
565 | |
} |
566 | |
|
567 | 0 | return delegationMap; |
568 | |
} |
569 | |
|
570 | |
protected void addDelegationBoToCache(DelegateBo delegate) { |
571 | 0 | if (delegate != null) { |
572 | 0 | getCacheAdministrator().putInCache(getDelegationCacheKey(delegate.getDelegationId()), |
573 | |
delegate, DELEGATION_IMPL_CACHE_GROUP); |
574 | |
} |
575 | 0 | } |
576 | |
|
577 | |
protected DelegateBo getDelegationFromCache(String delegationId) { |
578 | 0 | return (DelegateBo) getCacheAdministrator().getFromCache(getDelegationCacheKey(delegationId)); |
579 | |
} |
580 | |
|
581 | |
public void flushInternalDelegationCache() { |
582 | 0 | getCacheAdministrator().flushGroup(DELEGATION_IMPL_CACHE_GROUP); |
583 | 0 | } |
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
protected DelegateBo getDelegationBo(String delegationId) { |
590 | 0 | if (StringUtils.isBlank(delegationId)) { |
591 | 0 | return null; |
592 | |
} |
593 | |
|
594 | |
|
595 | 0 | DelegateBo tempDelegate = getDelegationFromCache(delegationId); |
596 | 0 | if (tempDelegate != null) { |
597 | 0 | return tempDelegate; |
598 | |
} |
599 | |
|
600 | 0 | tempDelegate = (DelegateBo) getBusinessObjectService().findByPrimaryKey(DelegateBo.class, |
601 | |
Collections.singletonMap(KimConstants.PrimaryKeyConstants.DELEGATION_ID, delegationId)); |
602 | 0 | addDelegationBoToCache(tempDelegate); |
603 | 0 | return tempDelegate; |
604 | |
} |
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
protected String getDelegationMemberCacheKey(String delegationMemberId) { |
617 | 0 | return DELEGATION_MEMBER_IMPL_CACHE_PREFIX + delegationMemberId; |
618 | |
} |
619 | |
|
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
protected String getDelegationMemberByDelegationAndIdCacheKey(String delegationId, String delegationMemberId) { |
628 | 0 | return new StringBuilder(DELEGATION_MEMBER_IMPL_BY_DLGN_AND_ID_CACHE_PREFIX).append(delegationId).append('-').append(delegationMemberId).toString(); |
629 | |
} |
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
protected String getDelegationMemberListByMemberAndDelegationIdCacheKey(String memberId, String delegationId) { |
639 | 0 | return new StringBuilder(DELEGATION_MEMBER_IMPL_LIST_BY_MBR_DLGN_CACHE_PREFIX).append(StringUtils.isBlank(memberId) ? "" : memberId).append( |
640 | |
'-').append(StringUtils.isBlank(delegationId) ? "" : delegationId).toString(); |
641 | |
} |
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
protected String getDelegationMemberListCacheKey(RoleDaoAction daoAction, String delegationId, String principalId, String groupId) { |
655 | 0 | switch (daoAction) { |
656 | |
case DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS: |
657 | 0 | return new StringBuilder(DELEGATION_MEMBER_IMPL_LIST_CACHE_PREFIX).append(daoAction.DAO_ACTION_CACHE_PREFIX).append( |
658 | |
StringUtils.isBlank(delegationId) ? "" : delegationId).append('-').append( |
659 | |
StringUtils.isBlank(principalId) ? "" : principalId).toString(); |
660 | |
case DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS: |
661 | 0 | return new StringBuilder(DELEGATION_MEMBER_IMPL_LIST_CACHE_PREFIX).append(daoAction.DAO_ACTION_CACHE_PREFIX).append( |
662 | |
StringUtils.isBlank(delegationId) ? "" : delegationId).append('-').append(StringUtils.isBlank(groupId) ? "" : groupId).toString(); |
663 | |
case DELEGATION_MEMBERS_FOR_DELEGATION_IDS: |
664 | 0 | return new StringBuilder(DELEGATION_MEMBER_IMPL_LIST_CACHE_PREFIX).append(daoAction.DAO_ACTION_CACHE_PREFIX).append( |
665 | |
StringUtils.isBlank(delegationId) ? "" : delegationId).toString(); |
666 | |
default: |
667 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-delegation-member-related value!"); |
668 | |
} |
669 | |
} |
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
protected List<DelegateMemberBo> getDelegationMemberBoList(RoleDaoAction daoActionToTake, Collection<String> delegationIds, |
682 | |
String principalId, List<String> groupIds) { |
683 | 0 | List<DelegateMemberBo> finalResults = new ArrayList<DelegateMemberBo>(); |
684 | 0 | List<String[]> uncachedKeys = new ArrayList<String[]>(); |
685 | 0 | Set<String> usedKeys = new HashSet<String>(); |
686 | 0 | if (delegationIds == null || delegationIds.isEmpty()) { |
687 | 0 | delegationIds = Collections.singletonList(null); |
688 | |
} |
689 | 0 | if (groupIds == null || groupIds.isEmpty()) { |
690 | 0 | groupIds = Collections.singletonList(null); |
691 | |
} |
692 | |
|
693 | |
|
694 | 0 | switch (daoActionToTake) { |
695 | |
case DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS: |
696 | 0 | for (String delegationId : delegationIds) { |
697 | 0 | String tempKey = getDelegationMemberListCacheKey(daoActionToTake, delegationId, principalId, null); |
698 | 0 | if (!usedKeys.contains(tempKey)) { |
699 | 0 | List<DelegateMemberBo> tempMembers = (List<DelegateMemberBo>) getCacheAdministrator().getFromCache(tempKey); |
700 | 0 | if (tempMembers != null) { |
701 | 0 | finalResults.addAll(tempMembers); |
702 | |
} else { |
703 | 0 | uncachedKeys.add(new String[]{delegationId, principalId, null}); |
704 | |
} |
705 | 0 | usedKeys.add(tempKey); |
706 | |
} |
707 | 0 | } |
708 | 0 | break; |
709 | |
case DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS: |
710 | 0 | for (String delegationId : delegationIds) { |
711 | 0 | for (String groupId : groupIds) { |
712 | 0 | String tempKey = getDelegationMemberListCacheKey(daoActionToTake, delegationId, null, groupId); |
713 | 0 | if (!usedKeys.contains(tempKey)) { |
714 | 0 | List<DelegateMemberBo> tempMembers = (List<DelegateMemberBo>) getCacheAdministrator().getFromCache(tempKey); |
715 | 0 | if (tempMembers != null) { |
716 | 0 | finalResults.addAll(tempMembers); |
717 | |
} else { |
718 | 0 | uncachedKeys.add(new String[]{delegationId, null, groupId}); |
719 | |
} |
720 | |
} |
721 | 0 | } |
722 | |
} |
723 | 0 | break; |
724 | |
default: |
725 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-delegation-member-list-related value!"); |
726 | |
} |
727 | |
|
728 | |
|
729 | 0 | if (!uncachedKeys.isEmpty()) { |
730 | 0 | List<DelegateMemberBo> uncachedResults = new ArrayList<DelegateMemberBo>(); |
731 | 0 | Set<String> uncachedDelegationSet = new HashSet<String>(); |
732 | 0 | Set<String> uncachedGroupSet = new HashSet<String>(); |
733 | 0 | for (String[] uncachedKey : uncachedKeys) { |
734 | 0 | if (uncachedKey[0] != null) { |
735 | 0 | uncachedDelegationSet.add(uncachedKey[0]); |
736 | |
} |
737 | 0 | if (uncachedKey[2] != null) { |
738 | 0 | uncachedGroupSet.add(uncachedKey[2]); |
739 | |
} |
740 | |
} |
741 | 0 | List<String> uncachedDelegations = (uncachedDelegationSet.isEmpty()) ? null : new ArrayList<String>(uncachedDelegationSet); |
742 | 0 | List<String> uncachedGroups = (uncachedGroupSet.isEmpty()) ? null : new ArrayList<String>(uncachedGroupSet); |
743 | 0 | String memberTypeCode = null; |
744 | |
|
745 | |
|
746 | 0 | switch (daoActionToTake) { |
747 | |
case DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS: |
748 | 0 | uncachedResults = roleDao.getDelegationPrincipalsForPrincipalIdAndDelegationIds(uncachedDelegations, principalId); |
749 | 0 | memberTypeCode = Role.PRINCIPAL_MEMBER_TYPE; |
750 | 0 | break; |
751 | |
case DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS: |
752 | 0 | uncachedResults = roleDao.getDelegationGroupsForGroupIdsAndDelegationIds(uncachedDelegations, uncachedGroups); |
753 | 0 | memberTypeCode = Role.GROUP_MEMBER_TYPE; |
754 | 0 | break; |
755 | |
default: |
756 | 0 | throw new IllegalArgumentException("The 'daoActionToTake' parameter cannot refer to a non-delegation-member-list-related value!"); |
757 | |
} |
758 | |
|
759 | |
|
760 | 0 | cacheDelegationMemberLists(daoActionToTake, uncachedKeys, memberTypeCode, uncachedResults); |
761 | 0 | for (DelegateMemberBo uncachedResult : uncachedResults) { |
762 | 0 | addDelegateMemberBoToCache(uncachedResult); |
763 | |
} |
764 | 0 | finalResults.addAll(uncachedResults); |
765 | |
} |
766 | |
|
767 | 0 | return finalResults; |
768 | |
} |
769 | |
|
770 | |
|
771 | |
|
772 | |
|
773 | |
|
774 | |
|
775 | |
|
776 | |
|
777 | |
|
778 | |
private void cacheDelegationMemberLists(RoleDaoAction daoActionToTake, List<String[]> uncachedKeys, |
779 | |
String memberTypeCode, List<DelegateMemberBo> uncachedMembers) { |
780 | |
|
781 | 0 | for (String[] uncachedKey : uncachedKeys) { |
782 | 0 | List<DelegateMemberBo> tempMembers = new ArrayList<DelegateMemberBo>(); |
783 | 0 | for (DelegateMemberBo uncachedMember : uncachedMembers) { |
784 | 0 | if ((memberTypeCode == null || memberTypeCode.equals(uncachedMember.getTypeCode())) && |
785 | |
(uncachedKey[0] == null || uncachedKey[0].equals(uncachedMember.getDelegationId())) && |
786 | |
(uncachedKey[1] == null || uncachedKey[1].equals(uncachedMember.getMemberId())) && |
787 | |
(uncachedKey[2] == null || uncachedKey[2].equals(uncachedMember.getMemberId()))) { |
788 | 0 | tempMembers.add(uncachedMember); |
789 | |
} |
790 | |
} |
791 | 0 | getCacheAdministrator().putInCache(getDelegationMemberListCacheKey(daoActionToTake, uncachedKey[0], uncachedKey[1], uncachedKey[2]), |
792 | |
tempMembers, DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
793 | 0 | } |
794 | 0 | } |
795 | |
|
796 | |
|
797 | |
|
798 | |
|
799 | |
protected List<DelegateMemberBo> getStoredDelegationPrincipalsForPrincipalIdAndDelegationIds(Collection<String> delegationIds, String principalId) { |
800 | 0 | return getDelegationMemberBoList(RoleDaoAction.DELEGATION_PRINCIPALS_FOR_PRINCIPAL_ID_AND_DELEGATION_IDS, delegationIds, principalId, null); |
801 | |
} |
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
protected List<DelegateMemberBo> getStoredDelegationGroupsForGroupIdsAndDelegationIds(Collection<String> delegationIds, List<String> groupIds) { |
807 | 0 | return getDelegationMemberBoList(RoleDaoAction.DELEGATION_GROUPS_FOR_GROUP_IDS_AND_DELEGATION_IDS, delegationIds, null, groupIds); |
808 | |
} |
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
protected Map<String, List<DelegateMemberBo>> getStoredDelegationMembersForDelegationIds(List<String> delegationIds) { |
814 | 0 | Map<String, List<DelegateMemberBo>> finalResults = new HashMap<String, List<DelegateMemberBo>>(); |
815 | 0 | Set<String> uncachedDelegationIds = new HashSet<String>(); |
816 | 0 | boolean idListWasNullOrEmpty = (delegationIds == null || delegationIds.isEmpty()); |
817 | 0 | if (idListWasNullOrEmpty) { |
818 | 0 | delegationIds = Collections.singletonList(null); |
819 | |
} |
820 | |
|
821 | |
|
822 | 0 | for (String delegationId : delegationIds) { |
823 | 0 | List<DelegateMemberBo> tempMembers = (List<DelegateMemberBo>) getCacheAdministrator().getFromCache( |
824 | |
getDelegationMemberListCacheKey(RoleDaoAction.DELEGATION_MEMBERS_FOR_DELEGATION_IDS, delegationId, null, null)); |
825 | 0 | if (tempMembers != null) { |
826 | 0 | finalResults.put(delegationId, tempMembers); |
827 | |
} else { |
828 | 0 | uncachedDelegationIds.add(delegationId); |
829 | |
} |
830 | 0 | } |
831 | |
|
832 | |
|
833 | 0 | if (!uncachedDelegationIds.isEmpty()) { |
834 | 0 | List<String> uncachedIdsList = (idListWasNullOrEmpty) ? new ArrayList<String>() : new ArrayList<String>(uncachedDelegationIds); |
835 | |
|
836 | 0 | Map<String, List<DelegateMemberBo>> tempMemberMap = roleDao.getDelegationMembersForDelegationIds(uncachedIdsList); |
837 | 0 | List<DelegateMemberBo> allMembers = new ArrayList<DelegateMemberBo>(); |
838 | |
|
839 | 0 | for (Map.Entry<String, List<DelegateMemberBo>> tempMemberEntry : tempMemberMap.entrySet()) { |
840 | 0 | getCacheAdministrator().putInCache(getDelegationMemberListCacheKey(RoleDaoAction.DELEGATION_MEMBERS_FOR_DELEGATION_IDS, |
841 | |
tempMemberEntry.getKey(), null, null), tempMemberEntry.getValue(), DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
842 | 0 | for (DelegateMemberBo tempMember : tempMemberEntry.getValue()) { |
843 | 0 | addDelegateMemberBoToCache(tempMember); |
844 | |
} |
845 | 0 | if (idListWasNullOrEmpty) { |
846 | 0 | allMembers.addAll(tempMemberEntry.getValue()); |
847 | |
} |
848 | 0 | finalResults.put(tempMemberEntry.getKey(), tempMemberEntry.getValue()); |
849 | |
} |
850 | |
|
851 | 0 | if (idListWasNullOrEmpty) { |
852 | 0 | getCacheAdministrator().putInCache(getDelegationMemberListCacheKey(RoleDaoAction.DELEGATION_MEMBERS_FOR_DELEGATION_IDS, |
853 | |
null, null, null), allMembers, DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
854 | |
} |
855 | |
} |
856 | |
|
857 | 0 | return finalResults; |
858 | |
} |
859 | |
|
860 | |
protected void addDelegateMemberBoToCache(DelegateMemberBo delegateMember) { |
861 | 0 | if (delegateMember != null) { |
862 | 0 | getCacheAdministrator().putInCache(getDelegationMemberCacheKey(delegateMember.getDelegationMemberId()), |
863 | |
delegateMember, DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
864 | 0 | getCacheAdministrator().putInCache(getDelegationMemberByDelegationAndIdCacheKey( |
865 | |
delegateMember.getDelegationId(), delegateMember.getDelegationMemberId()), delegateMember, DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
866 | |
} |
867 | 0 | } |
868 | |
|
869 | |
protected void addDelegationMemberBoListByMemberAndDelegationIdToCache( |
870 | |
List<DelegateMemberBo> memberList, String memberId, String delegationId) { |
871 | 0 | if (memberList != null) { |
872 | 0 | getCacheAdministrator().putInCache(getDelegationMemberListByMemberAndDelegationIdCacheKey(memberId, delegationId), |
873 | |
memberList, DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
874 | |
} |
875 | 0 | } |
876 | |
|
877 | |
protected DelegateMemberBo getDelegationMemberFromCache(String delegationMemberId) { |
878 | 0 | return (DelegateMemberBo) getCacheAdministrator().getFromCache(getDelegationMemberCacheKey(delegationMemberId)); |
879 | |
} |
880 | |
|
881 | |
protected DelegateMemberBo getDelegationMemberByDelegationAndIdFromCache(String delegationId, String delegationMemberId) { |
882 | 0 | return (DelegateMemberBo) getCacheAdministrator().getFromCache(getDelegationMemberByDelegationAndIdCacheKey( |
883 | |
delegationId, delegationMemberId)); |
884 | |
} |
885 | |
|
886 | |
protected List<DelegateMemberBo> getDelegationMemberListByMemberAndDelegationIdFromCache(String memberId, String delegationId) { |
887 | 0 | return (List<DelegateMemberBo>) |
888 | |
getCacheAdministrator().getFromCache(getDelegationMemberListByMemberAndDelegationIdCacheKey(memberId, delegationId)); |
889 | |
} |
890 | |
|
891 | |
public void flushInternalDelegationMemberCache() { |
892 | 0 | getCacheAdministrator().flushGroup(DELEGATION_MEMBER_IMPL_CACHE_GROUP); |
893 | 0 | } |
894 | |
|
895 | |
|
896 | |
|
897 | |
|
898 | |
|
899 | |
protected DelegateMemberBo getDelegateMemberBo(String delegationMemberId) { |
900 | 0 | if (StringUtils.isBlank(delegationMemberId)) { |
901 | 0 | return null; |
902 | |
} |
903 | |
|
904 | |
|
905 | 0 | DelegateMemberBo tempDelegateMember = getDelegationMemberFromCache(delegationMemberId); |
906 | 0 | if (tempDelegateMember != null) { |
907 | 0 | return tempDelegateMember; |
908 | |
} |
909 | |
|
910 | 0 | tempDelegateMember = (DelegateMemberBo) getBusinessObjectService().findByPrimaryKey(DelegateMemberBo.class, |
911 | |
Collections.singletonMap(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMemberId)); |
912 | 0 | addDelegateMemberBoToCache(tempDelegateMember); |
913 | 0 | return tempDelegateMember; |
914 | |
} |
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | |
|
920 | |
protected DelegateMemberBo getDelegationMemberBoByDelegationAndId(String delegationId, String delegationMemberId) { |
921 | 0 | if (StringUtils.isBlank(delegationId) || StringUtils.isBlank(delegationMemberId)) { |
922 | 0 | return null; |
923 | |
} |
924 | |
|
925 | |
|
926 | 0 | DelegateMemberBo tempDelegateMember = getDelegationMemberByDelegationAndIdFromCache(delegationId, delegationMemberId); |
927 | 0 | if (tempDelegateMember != null) { |
928 | 0 | return tempDelegateMember; |
929 | |
} |
930 | |
|
931 | 0 | Map<String, String> searchCriteria = new HashMap<String, String>(); |
932 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_ID, delegationId); |
933 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMemberId); |
934 | 0 | List<DelegateMemberBo> memberList = |
935 | |
(List<DelegateMemberBo>) getBusinessObjectService().findMatching(DelegateMemberBo.class, searchCriteria); |
936 | 0 | if (memberList != null && !memberList.isEmpty()) { |
937 | 0 | tempDelegateMember = memberList.get(0); |
938 | 0 | addDelegateMemberBoToCache(tempDelegateMember); |
939 | |
} |
940 | 0 | return tempDelegateMember; |
941 | |
} |
942 | |
|
943 | |
|
944 | |
|
945 | |
|
946 | |
|
947 | |
protected List<DelegateMemberBo> getDelegationMemberBoListByMemberAndDelegationId(String memberId, String delegationId) { |
948 | |
|
949 | 0 | List<DelegateMemberBo> memberList = getDelegationMemberListByMemberAndDelegationIdFromCache(memberId, delegationId); |
950 | 0 | if (memberList != null) { |
951 | 0 | return memberList; |
952 | |
} |
953 | |
|
954 | |
|
955 | 0 | Map<String, String> searchCriteria = new HashMap<String, String>(); |
956 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.MEMBER_ID, memberId); |
957 | 0 | searchCriteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_ID, delegationId); |
958 | 0 | List<DelegateMemberBo> tempList = |
959 | |
(List<DelegateMemberBo>) getBusinessObjectService().findMatching(DelegateMemberBo.class, searchCriteria); |
960 | 0 | if (tempList != null && !tempList.isEmpty()) { |
961 | 0 | memberList = new ArrayList<DelegateMemberBo>(); |
962 | 0 | memberList.addAll(tempList); |
963 | 0 | addDelegationMemberBoListByMemberAndDelegationIdToCache(memberList, memberId, delegationId); |
964 | |
} |
965 | 0 | return memberList; |
966 | |
} |
967 | |
|
968 | |
public void flushInternalRoleCache() { |
969 | 0 | getCacheAdministrator().flushGroup(ROLE_IMPL_CACHE_GROUP); |
970 | 0 | } |
971 | |
|
972 | |
public RoleMember findRoleMember(String roleMemberId) { |
973 | 0 | Map<String, String> fieldValues = new HashMap<String, String>(); |
974 | 0 | fieldValues.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId); |
975 | 0 | List<RoleMember> roleMembers = findRoleMembers(fieldValues); |
976 | 0 | if (roleMembers != null && roleMembers.size() > 0) { |
977 | 0 | return roleMembers.get(0); |
978 | |
} |
979 | 0 | return null; |
980 | |
} |
981 | |
|
982 | |
public List<RoleMember> findRoleMembers(Map<String, String> fieldValues) { |
983 | 0 | List<RoleMember> roleMembers = new ArrayList<RoleMember>(); |
984 | 0 | List<RoleMemberBo> roleMemberBos = (List<RoleMemberBo>) getLookupService().findCollectionBySearchHelper( |
985 | |
RoleMemberBo.class, fieldValues, true); |
986 | |
|
987 | 0 | for (RoleMemberBo bo : roleMemberBos) { |
988 | 0 | RoleMember roleMember = RoleMemberBo.to(bo); |
989 | 0 | roleMembers.add(roleMember); |
990 | 0 | } |
991 | 0 | return roleMembers; |
992 | |
} |
993 | |
|
994 | |
public List<RoleResponsibilityAction> getRoleMemberResponsibilityActions(String roleMemberId) { |
995 | 0 | Map<String, String> criteria = new HashMap<String, String>(1); |
996 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId); |
997 | |
|
998 | 0 | List<RoleResponsibilityActionBo> responsibilityActionBoList = (List<RoleResponsibilityActionBo>) |
999 | |
getBusinessObjectService().findMatching(RoleResponsibilityActionBo.class, criteria); |
1000 | |
|
1001 | 0 | List<RoleResponsibilityAction> roleResponsibilityActionsList = new ArrayList<RoleResponsibilityAction>(); |
1002 | 0 | for (RoleResponsibilityActionBo roleResponsibilityActionBo : responsibilityActionBoList) { |
1003 | 0 | RoleResponsibilityAction roleResponsibility = RoleResponsibilityActionBo.to(roleResponsibilityActionBo); |
1004 | 0 | roleResponsibilityActionsList.add(roleResponsibility); |
1005 | 0 | } |
1006 | 0 | return roleResponsibilityActionsList; |
1007 | |
} |
1008 | |
|
1009 | |
public List<DelegateMember> findDelegateMembers(final Map<String, String> fieldValues) { |
1010 | 0 | List<DelegateMember> delegateMembers = new ArrayList<DelegateMember>(); |
1011 | 0 | List<DelegateBo> delegateBoList = (List<DelegateBo>) getLookupService().findCollectionBySearchHelper( |
1012 | |
DelegateBo.class, fieldValues, true); |
1013 | |
|
1014 | 0 | if (delegateBoList != null && !delegateBoList.isEmpty()) { |
1015 | 0 | Map<String, String> delegationMemberFieldValues = new HashMap<String, String>(); |
1016 | 0 | for (String key : fieldValues.keySet()) { |
1017 | 0 | if (key.startsWith(KimConstants.KimUIConstants.MEMBER_ID_PREFIX)) { |
1018 | 0 | delegationMemberFieldValues.put( |
1019 | |
key.substring(key.indexOf( |
1020 | |
KimConstants.KimUIConstants.MEMBER_ID_PREFIX) + KimConstants.KimUIConstants.MEMBER_ID_PREFIX.length()), |
1021 | |
fieldValues.get(key)); |
1022 | |
} |
1023 | |
} |
1024 | |
|
1025 | 0 | StringBuffer memberQueryString = new StringBuffer(); |
1026 | 0 | for (DelegateBo delegate : delegateBoList) { |
1027 | 0 | memberQueryString.append(delegate.getDelegationId() + KimConstants.KimUIConstants.OR_OPERATOR); |
1028 | |
} |
1029 | 0 | delegationMemberFieldValues.put(KimConstants.PrimaryKeyConstants.DELEGATION_ID, |
1030 | |
StringUtils.stripEnd(memberQueryString.toString(), KimConstants.KimUIConstants.OR_OPERATOR)); |
1031 | 0 | List<DelegateMemberBo> delegateMemberBoList = (List<DelegateMemberBo>) getLookupService().findCollectionBySearchHelper( |
1032 | |
DelegateMemberBo.class, delegationMemberFieldValues, true); |
1033 | |
|
1034 | |
|
1035 | 0 | for (DelegateMemberBo delegateMemberBo : delegateMemberBoList) { |
1036 | 0 | DelegateMember delegateMember = DelegateMemberBo.to(delegateMemberBo); |
1037 | 0 | delegateMembers.add(delegateMember); |
1038 | 0 | } |
1039 | |
} |
1040 | 0 | return delegateMembers; |
1041 | |
} |
1042 | |
|
1043 | |
protected DelegateBo getDelegationImpl(List<DelegateBo> delegates, String delegationId) { |
1044 | 0 | if (StringUtils.isEmpty(delegationId) || delegates == null) { |
1045 | 0 | return null; |
1046 | |
} |
1047 | 0 | for (DelegateBo delegate : delegates) { |
1048 | 0 | if (StringUtils.equals(delegate.getDelegationId(), delegationId)) { |
1049 | 0 | return delegate; |
1050 | |
} |
1051 | |
} |
1052 | 0 | return null; |
1053 | |
} |
1054 | |
|
1055 | |
protected Object getMember(String memberTypeCode, String memberId) { |
1056 | 0 | if (StringUtils.isBlank(memberId)) { |
1057 | 0 | return null; |
1058 | |
} |
1059 | 0 | if (KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(memberTypeCode)) { |
1060 | 0 | return getIdentityService().getPrincipal(memberId); |
1061 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)) { |
1062 | 0 | return getGroupService().getGroup(memberId); |
1063 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)) { |
1064 | 0 | return getRoleBo(memberId); |
1065 | |
} |
1066 | 0 | return null; |
1067 | |
} |
1068 | |
|
1069 | |
protected String getMemberName(Object member) { |
1070 | 0 | if (member == null) { |
1071 | 0 | return ""; |
1072 | |
} |
1073 | 0 | if (member instanceof Principal) { |
1074 | 0 | return ((Principal) member).getPrincipalName(); |
1075 | |
} |
1076 | 0 | if (member instanceof Group) { |
1077 | 0 | return ((Group) member).getName(); |
1078 | |
} |
1079 | 0 | if (member instanceof Role) { |
1080 | 0 | return ((Role) member).getName(); |
1081 | |
} |
1082 | 0 | return member.toString(); |
1083 | |
} |
1084 | |
|
1085 | |
protected String getMemberNamespaceCode(Object member) { |
1086 | 0 | if (member == null) { |
1087 | 0 | return ""; |
1088 | |
} |
1089 | 0 | if (member instanceof Principal) { |
1090 | 0 | return ""; |
1091 | |
} |
1092 | 0 | if (member instanceof Group) { |
1093 | 0 | return ((Group) member).getNamespaceCode(); |
1094 | |
} |
1095 | 0 | if (member instanceof Role) { |
1096 | 0 | return ((Role) member).getNamespaceCode(); |
1097 | |
} |
1098 | 0 | return ""; |
1099 | |
} |
1100 | |
|
1101 | |
protected RoleBo getRoleBo(String roleId) { |
1102 | 0 | if (StringUtils.isBlank(roleId)) { |
1103 | 0 | return null; |
1104 | |
} |
1105 | |
|
1106 | 0 | RoleBo cachedResult = getRoleFromCache(roleId); |
1107 | 0 | if (cachedResult != null) { |
1108 | 0 | return cachedResult; |
1109 | |
} |
1110 | |
|
1111 | 0 | RoleBo result = (RoleBo) getBusinessObjectService().findBySinglePrimaryKey(RoleBo.class, roleId); |
1112 | 0 | addRoleBoToCache(result); |
1113 | 0 | return result; |
1114 | |
} |
1115 | |
|
1116 | |
protected DelegateBo getDelegationOfType(String roleId, String delegationTypeCode) { |
1117 | 0 | List<DelegateBo> roleDelegates = getRoleDelegations(roleId); |
1118 | 0 | if (isDelegationPrimary(delegationTypeCode)) { |
1119 | 0 | return getPrimaryDelegation(roleId, roleDelegates); |
1120 | |
} else { |
1121 | 0 | return getSecondaryDelegation(roleId, roleDelegates); |
1122 | |
} |
1123 | |
} |
1124 | |
|
1125 | |
private DelegateBo getSecondaryDelegation(String roleId, List<DelegateBo> roleDelegates) { |
1126 | 0 | DelegateBo secondaryDelegate = null; |
1127 | 0 | RoleBo roleBo = getRoleBo(roleId); |
1128 | 0 | for (DelegateBo delegate : roleDelegates) { |
1129 | 0 | if (isDelegationSecondary(delegate.getDelegationTypeCode())) { |
1130 | 0 | secondaryDelegate = delegate; |
1131 | |
} |
1132 | |
} |
1133 | 0 | if (secondaryDelegate == null) { |
1134 | 0 | secondaryDelegate = new DelegateBo(); |
1135 | 0 | secondaryDelegate.setRoleId(roleId); |
1136 | 0 | secondaryDelegate.setDelegationId(getNewDelegationId()); |
1137 | 0 | secondaryDelegate.setDelegationTypeCode(DelegationType.PRIMARY.getCode()); |
1138 | 0 | secondaryDelegate.setKimTypeId(roleBo.getKimTypeId()); |
1139 | |
} |
1140 | 0 | return secondaryDelegate; |
1141 | |
} |
1142 | |
|
1143 | |
protected DelegateBo getPrimaryDelegation(String roleId, List<DelegateBo> roleDelegates) { |
1144 | 0 | DelegateBo primaryDelegate = null; |
1145 | 0 | RoleBo roleBo = getRoleBo(roleId); |
1146 | 0 | for (DelegateBo delegate : roleDelegates) { |
1147 | 0 | if (isDelegationPrimary(delegate.getDelegationTypeCode())) { |
1148 | 0 | primaryDelegate = delegate; |
1149 | |
} |
1150 | |
} |
1151 | 0 | if (primaryDelegate == null) { |
1152 | 0 | primaryDelegate = new DelegateBo(); |
1153 | 0 | primaryDelegate.setRoleId(roleId); |
1154 | 0 | primaryDelegate.setDelegationId(getNewDelegationId()); |
1155 | 0 | primaryDelegate.setDelegationTypeCode(DelegationType.PRIMARY.getCode()); |
1156 | 0 | primaryDelegate.setKimTypeId(roleBo.getKimTypeId()); |
1157 | |
} |
1158 | 0 | return primaryDelegate; |
1159 | |
} |
1160 | |
|
1161 | |
protected RoleMemberBo matchingMemberRecord(List<RoleMemberBo> roleMembers, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
1162 | 0 | for (RoleMemberBo rm : roleMembers) { |
1163 | 0 | if (doesMemberMatch(rm, memberId, memberTypeCode, qualifier)) { |
1164 | 0 | return rm; |
1165 | |
} |
1166 | |
} |
1167 | 0 | return null; |
1168 | |
} |
1169 | |
|
1170 | |
protected boolean isDelegationPrimary(String delegationTypeCode) { |
1171 | 0 | return DelegationType.PRIMARY.getCode().equals(delegationTypeCode); |
1172 | |
} |
1173 | |
|
1174 | |
protected boolean isDelegationSecondary(String delegationTypeCode) { |
1175 | 0 | return DelegationType.PRIMARY.getCode().equals(delegationTypeCode); |
1176 | |
} |
1177 | |
|
1178 | |
|
1179 | |
private List<DelegateBo> getRoleDelegations(String roleId) { |
1180 | 0 | if (roleId == null) { |
1181 | 0 | return new ArrayList<DelegateBo>(); |
1182 | |
} |
1183 | 0 | return getStoredDelegationImplsForRoleIds(Collections.singletonList(roleId)); |
1184 | |
|
1185 | |
} |
1186 | |
|
1187 | |
protected RoleBo getRoleBoByName(String namespaceCode, String roleName) { |
1188 | 0 | if (StringUtils.isBlank(namespaceCode) |
1189 | |
|| StringUtils.isBlank(roleName)) { |
1190 | 0 | return null; |
1191 | |
} |
1192 | |
|
1193 | 0 | RoleBo cachedResult = getRoleFromCache(namespaceCode, roleName); |
1194 | 0 | if (cachedResult != null) { |
1195 | 0 | return cachedResult; |
1196 | |
} |
1197 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
1198 | 0 | criteria.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode); |
1199 | 0 | criteria.put(KimConstants.UniqueKeyConstants.NAME, roleName); |
1200 | 0 | criteria.put(KRADPropertyConstants.ACTIVE, "Y"); |
1201 | |
|
1202 | 0 | RoleBo result = getBusinessObjectService().findByPrimaryKey(RoleBo.class, criteria); |
1203 | 0 | addRoleBoToCache(result); |
1204 | 0 | return result; |
1205 | |
} |
1206 | |
|
1207 | |
protected boolean doAnyMemberRecordsMatch(List<RoleMemberBo> roleMembers, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
1208 | 0 | for (RoleMemberBo rm : roleMembers) { |
1209 | 0 | if (doesMemberMatch(rm, memberId, memberTypeCode, qualifier)) { |
1210 | 0 | return true; |
1211 | |
} |
1212 | |
} |
1213 | 0 | return false; |
1214 | |
} |
1215 | |
|
1216 | |
protected boolean doesMemberMatch(RoleMemberBo roleMember, String memberId, String memberTypeCode, Map<String, String> qualifier) { |
1217 | 0 | if (roleMember.getMemberId().equals(memberId) && roleMember.getMemberTypeCode().equals(memberTypeCode)) { |
1218 | |
|
1219 | 0 | Map<String, String> roleQualifier = roleMember.getAttributes(); |
1220 | 0 | if ((qualifier == null || qualifier.isEmpty()) |
1221 | |
&& (roleQualifier == null || roleQualifier.isEmpty())) { |
1222 | 0 | return true; |
1223 | |
} else { |
1224 | 0 | if (qualifier != null && roleQualifier != null && qualifier.equals(roleQualifier)) { |
1225 | 0 | return true; |
1226 | |
} |
1227 | |
} |
1228 | |
} |
1229 | 0 | return false; |
1230 | |
} |
1231 | |
|
1232 | |
|
1233 | |
|
1234 | |
|
1235 | |
|
1236 | |
|
1237 | |
|
1238 | |
|
1239 | |
|
1240 | |
|
1241 | |
protected boolean checkForCircularRoleMembership(String newMemberId, RoleBo roleBo) { |
1242 | |
|
1243 | 0 | Set<String> newRoleMemberIds = getRoleTypeRoleMemberIds(newMemberId); |
1244 | 0 | if (newRoleMemberIds.contains(roleBo.getId())) { |
1245 | 0 | return false; |
1246 | |
} |
1247 | 0 | return true; |
1248 | |
} |
1249 | |
|
1250 | |
|
1251 | |
@SuppressWarnings("unchecked") |
1252 | |
protected String getKimAttributeId(String attributeName) { |
1253 | 0 | String result = null; |
1254 | 0 | Map<String, Object> critieria = new HashMap<String, Object>(1); |
1255 | 0 | critieria.put("attributeName", attributeName); |
1256 | 0 | Collection<KimAttributeBo> defs = getBusinessObjectService().findMatching(KimAttributeBo.class, critieria); |
1257 | 0 | if (CollectionUtils.isNotEmpty(defs)) { |
1258 | 0 | result = defs.iterator().next().getId(); |
1259 | |
} |
1260 | 0 | return result; |
1261 | |
} |
1262 | |
|
1263 | |
|
1264 | |
|
1265 | |
|
1266 | |
protected Map<String, Boolean> getApplicationRoleTypeCache() { |
1267 | 0 | return this.applicationRoleTypeCache; |
1268 | |
} |
1269 | |
|
1270 | |
|
1271 | |
|
1272 | |
|
1273 | |
protected Map<String, KimRoleTypeService> getRoleTypeServiceCache() { |
1274 | 0 | return this.roleTypeServiceCache; |
1275 | |
} |
1276 | |
|
1277 | |
|
1278 | |
|
1279 | |
|
1280 | |
protected Map<String, KimDelegationTypeService> getDelegationTypeServiceCache() { |
1281 | 0 | return this.delegationTypeServiceCache; |
1282 | |
} |
1283 | |
|
1284 | |
protected String getRoleCacheKey(String roleId) { |
1285 | 0 | return ROLE_IMPL_CACHE_PREFIX + roleId; |
1286 | |
} |
1287 | |
|
1288 | |
protected String getRoleByNameCacheKey(String namespaceCode, String roleName) { |
1289 | 0 | return ROLE_IMPL_BY_NAME_CACHE_PREFIX + namespaceCode + "-" + roleName; |
1290 | |
} |
1291 | |
|
1292 | |
protected void addRoleBoToCache(RoleBo roleBo) { |
1293 | 0 | if (roleBo != null) { |
1294 | 0 | getCacheAdministrator().putInCache(getRoleCacheKey(roleBo.getId()), roleBo, ROLE_IMPL_CACHE_GROUP); |
1295 | 0 | getCacheAdministrator().putInCache(getRoleByNameCacheKey(roleBo.getNamespaceCode(), roleBo.getName()), roleBo, ROLE_IMPL_CACHE_GROUP); |
1296 | |
} |
1297 | 0 | } |
1298 | |
|
1299 | |
protected RoleBo getRoleFromCache(String roleId) { |
1300 | 0 | return (RoleBo) getCacheAdministrator().getFromCache(getRoleCacheKey(roleId)); |
1301 | |
} |
1302 | |
|
1303 | |
protected RoleBo getRoleFromCache(String namespaceCode, String roleName) { |
1304 | 0 | return (RoleBo) getCacheAdministrator().getFromCache(getRoleByNameCacheKey(namespaceCode, roleName)); |
1305 | |
} |
1306 | |
|
1307 | |
protected String getNewDelegationId() { |
1308 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
1309 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
1310 | |
KimConstants.SequenceNames.KRIM_DLGN_ID_S, |
1311 | |
DelegateBo.class); |
1312 | 0 | return nextSeq.toString(); |
1313 | |
} |
1314 | |
|
1315 | |
protected String getNewAttributeDataId() { |
1316 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
1317 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
1318 | |
KimConstants.SequenceNames.KRIM_ATTR_DATA_ID_S, |
1319 | |
RoleMemberAttributeDataBo.class); |
1320 | 0 | return nextSeq.toString(); |
1321 | |
} |
1322 | |
|
1323 | |
protected String getNewDelegationMemberId() { |
1324 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
1325 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
1326 | |
KimConstants.SequenceNames.KRIM_DLGN_MBR_ID_S, |
1327 | |
DelegateBo.class); |
1328 | 0 | return nextSeq.toString(); |
1329 | |
} |
1330 | |
|
1331 | |
protected BusinessObjectService getBusinessObjectService() { |
1332 | 0 | if (businessObjectService == null) { |
1333 | 0 | businessObjectService = KRADServiceLocator.getBusinessObjectService(); |
1334 | |
} |
1335 | 0 | return businessObjectService; |
1336 | |
} |
1337 | |
|
1338 | |
|
1339 | |
|
1340 | |
|
1341 | |
protected LookupService getLookupService() { |
1342 | 0 | if (lookupService == null) { |
1343 | 0 | lookupService = KRADServiceLocatorWeb.getLookupService(); |
1344 | |
} |
1345 | 0 | return lookupService; |
1346 | |
} |
1347 | |
|
1348 | |
protected RiceCacheAdministrator getCacheAdministrator() { |
1349 | 0 | if (cacheAdministrator == null) { |
1350 | 0 | cacheAdministrator = KsbApiServiceLocator.getCacheAdministrator(); |
1351 | |
} |
1352 | 0 | return cacheAdministrator; |
1353 | |
} |
1354 | |
|
1355 | |
protected IdentityService getIdentityService() { |
1356 | 0 | if (identityService == null) { |
1357 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
1358 | |
} |
1359 | |
|
1360 | 0 | return identityService; |
1361 | |
} |
1362 | |
|
1363 | |
protected GroupService getGroupService() { |
1364 | 0 | if (groupService == null) { |
1365 | 0 | groupService = KimApiServiceLocator.getGroupService(); |
1366 | |
} |
1367 | |
|
1368 | 0 | return groupService; |
1369 | |
} |
1370 | |
|
1371 | |
protected SequenceAccessorService getSequenceAccessorService() { |
1372 | 0 | if (sequenceAccessorService == null) { |
1373 | 0 | sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService(); |
1374 | |
} |
1375 | 0 | return sequenceAccessorService; |
1376 | |
} |
1377 | |
|
1378 | |
protected ResponsibilityInternalService getResponsibilityInternalService() { |
1379 | 0 | if (responsibilityInternalService == null) { |
1380 | 0 | responsibilityInternalService = KIMServiceLocatorInternal.getResponsibilityInternalService(); |
1381 | |
} |
1382 | 0 | return responsibilityInternalService; |
1383 | |
} |
1384 | |
|
1385 | |
protected IdentityManagementNotificationService getIdentityManagementNotificationService() { |
1386 | 0 | return (IdentityManagementNotificationService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(new QName("KIM", "kimIdentityManagementNotificationService")); |
1387 | |
} |
1388 | |
|
1389 | |
|
1390 | |
|
1391 | |
|
1392 | |
|
1393 | |
|
1394 | 0 | private class RoleMemberCacheKeyHelper { |
1395 | |
private final RoleDaoAction ROLE_DAO_ACTION; |
1396 | |
private final String ROLE_ID; |
1397 | |
private final String PRINCIPAL_ID; |
1398 | |
private final String GROUP_ID; |
1399 | |
private final String MEMBER_TYPE_CODE; |
1400 | |
private String cacheKey; |
1401 | |
|
1402 | 0 | private RoleMemberCacheKeyHelper(RoleDaoAction roleDaoAction, String roleId, String principalId, String groupId, String memberTypeCode) { |
1403 | 0 | this.ROLE_DAO_ACTION = roleDaoAction; |
1404 | 0 | this.ROLE_ID = roleId; |
1405 | 0 | this.PRINCIPAL_ID = principalId; |
1406 | 0 | this.GROUP_ID = groupId; |
1407 | 0 | this.MEMBER_TYPE_CODE = memberTypeCode; |
1408 | 0 | } |
1409 | |
|
1410 | |
private String getCacheKey() { |
1411 | 0 | if (this.cacheKey == null) { |
1412 | 0 | this.cacheKey = getRoleMemberListCacheKey(ROLE_DAO_ACTION, ROLE_ID, PRINCIPAL_ID, GROUP_ID, MEMBER_TYPE_CODE); |
1413 | |
} |
1414 | 0 | return this.cacheKey; |
1415 | |
} |
1416 | |
} |
1417 | |
|
1418 | |
|
1419 | |
|
1420 | |
|
1421 | |
public RoleDao getRoleDao() { |
1422 | 0 | return this.roleDao; |
1423 | |
} |
1424 | |
|
1425 | |
|
1426 | |
|
1427 | |
|
1428 | |
public void setRoleDao(RoleDao roleDao) { |
1429 | 0 | this.roleDao = roleDao; |
1430 | 0 | } |
1431 | |
|
1432 | |
} |