1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.exception.ExceptionUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
21 | |
import org.kuali.rice.kim.api.group.Group; |
22 | |
import org.kuali.rice.kim.api.group.GroupService; |
23 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
24 | |
import org.kuali.rice.kim.api.identity.Type; |
25 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationType; |
26 | |
import org.kuali.rice.kim.api.identity.entity.Entity; |
27 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault; |
28 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults; |
29 | |
import org.kuali.rice.kim.api.identity.entity.EntityQueryResults; |
30 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierType; |
31 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
32 | |
import org.kuali.rice.kim.api.permission.Permission; |
33 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
34 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityAction; |
35 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityService; |
36 | |
import org.kuali.rice.kim.api.services.IdentityManagementService; |
37 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
38 | |
import org.kuali.rice.kim.bo.role.dto.PermissionAssigneeInfo; |
39 | |
import org.kuali.rice.kim.service.PermissionService; |
40 | |
|
41 | |
import java.util.HashMap; |
42 | |
import java.util.List; |
43 | |
import java.util.Map; |
44 | |
|
45 | 0 | public class IdentityManagementServiceImpl implements IdentityManagementService { |
46 | 0 | private static final Logger LOG = Logger.getLogger( IdentityManagementServiceImpl.class ); |
47 | |
|
48 | |
private PermissionService permissionService; |
49 | |
private ResponsibilityService responsibilityService; |
50 | |
private IdentityService identityService; |
51 | |
private GroupService groupService; |
52 | |
|
53 | |
@Override |
54 | |
public void flushAllCaches() { |
55 | 0 | } |
56 | |
|
57 | |
@Override |
58 | |
public void flushEntityPrincipalCaches() { |
59 | 0 | } |
60 | |
|
61 | |
@Override |
62 | |
public void flushGroupCaches() { |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public void flushPermissionCaches() { |
67 | 0 | } |
68 | |
|
69 | |
@Override |
70 | |
public void flushResponsibilityCaches() { |
71 | |
|
72 | 0 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public boolean hasPermission(String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails) { |
78 | 0 | if ( LOG.isDebugEnabled() ) { |
79 | 0 | logHasPermissionCheck("Permission", principalId, namespaceCode, permissionName, permissionDetails); |
80 | |
} |
81 | 0 | boolean hasPerm = getPermissionService().hasPermission(principalId, namespaceCode, permissionName, permissionDetails); |
82 | 0 | if ( LOG.isDebugEnabled() ) { |
83 | 0 | LOG.debug( "Result: " + hasPerm ); |
84 | |
} |
85 | 0 | return hasPerm; |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public boolean isAuthorized(String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
90 | 0 | if ( qualification == null || qualification.isEmpty() ) { |
91 | 0 | return hasPermission( principalId, namespaceCode, permissionName, permissionDetails ); |
92 | |
} |
93 | 0 | if ( LOG.isDebugEnabled() ) { |
94 | 0 | logAuthorizationCheck("Permission", principalId, namespaceCode, permissionName, permissionDetails, qualification); |
95 | |
} |
96 | 0 | boolean isAuthorized = getPermissionService().isAuthorized(principalId, namespaceCode, permissionName, permissionDetails, qualification); |
97 | 0 | if ( LOG.isDebugEnabled() ) { |
98 | 0 | LOG.debug( "Result: " + isAuthorized ); |
99 | |
} |
100 | 0 | return isAuthorized; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public boolean hasPermissionByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails) { |
105 | 0 | if ( LOG.isDebugEnabled() ) { |
106 | 0 | logHasPermissionCheck("Perm Templ", principalId, namespaceCode, permissionTemplateName, permissionDetails); |
107 | |
} |
108 | |
|
109 | 0 | boolean hasPerm = getPermissionService().hasPermissionByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails); |
110 | |
|
111 | 0 | if ( LOG.isDebugEnabled() ) { |
112 | 0 | LOG.debug( "Result: " + hasPerm ); |
113 | |
} |
114 | 0 | return hasPerm; |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public boolean isAuthorizedByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
119 | 0 | if ( qualification == null || qualification.isEmpty() ) { |
120 | 0 | return hasPermissionByTemplateName( principalId, namespaceCode, permissionTemplateName, new HashMap<String, String>(permissionDetails) ); |
121 | |
} |
122 | 0 | if ( LOG.isDebugEnabled() ) { |
123 | 0 | logAuthorizationCheck("Perm Templ", principalId, namespaceCode, permissionTemplateName, new HashMap<String, String>(permissionDetails), new HashMap<String, String>(qualification)); |
124 | |
} |
125 | 0 | boolean isAuthorized = getPermissionService().isAuthorizedByTemplateName( principalId, namespaceCode, permissionTemplateName, new HashMap<String, String>(permissionDetails), new HashMap<String, String>(qualification) ); |
126 | 0 | if ( LOG.isDebugEnabled() ) { |
127 | 0 | LOG.debug( "Result: " + isAuthorized ); |
128 | |
} |
129 | 0 | return isAuthorized; |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public List<Permission> getAuthorizedPermissions(String principalId, |
134 | |
String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification) { |
135 | 0 | return getPermissionService().getAuthorizedPermissions(principalId, namespaceCode, permissionName, permissionDetails, qualification); |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public List<Permission> getAuthorizedPermissionsByTemplateName(String principalId, |
140 | |
String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails, Map<String, String> qualification) { |
141 | 0 | return getPermissionService().getAuthorizedPermissionsByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification); |
142 | |
} |
143 | |
|
144 | |
@Override |
145 | |
public boolean isPermissionDefinedForTemplateName(String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails) { |
146 | 0 | return getPermissionService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName, permissionDetails); |
147 | |
} |
148 | |
|
149 | |
@Override |
150 | |
public List<PermissionAssigneeInfo> getPermissionAssignees(String namespaceCode, |
151 | |
String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification) { |
152 | 0 | return this.permissionService.getPermissionAssignees(namespaceCode, permissionName, |
153 | |
permissionDetails, qualification); |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public List<PermissionAssigneeInfo> getPermissionAssigneesForTemplateName(String namespaceCode, |
158 | |
String permissionTemplateName, Map<String, String> permissionDetails, |
159 | |
Map<String, String> qualification) { |
160 | 0 | return this.permissionService.getPermissionAssigneesForTemplateName( namespaceCode, |
161 | |
permissionTemplateName, new HashMap<String, String>(permissionDetails), new HashMap<String, String>(qualification) ); |
162 | |
} |
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
public boolean isMemberOfGroup(String principalId, String groupId) { |
167 | 0 | return getGroupService().isMemberOfGroup(principalId, groupId); |
168 | |
} |
169 | |
@Override |
170 | |
public boolean isMemberOfGroup(String principalId, String namespaceCode, String groupName) { |
171 | 0 | Group group = getGroupByName(namespaceCode, groupName); |
172 | 0 | return group == null ? false : isMemberOfGroup(principalId, group.getId()); |
173 | |
} |
174 | |
@Override |
175 | |
public boolean isGroupMemberOfGroup(String potentialMemberId, String potentialParentId) |
176 | |
{ |
177 | 0 | return getGroupService() |
178 | |
.isGroupMemberOfGroup(potentialMemberId, potentialParentId); |
179 | |
} |
180 | |
@Override |
181 | |
public List<String> getGroupMemberPrincipalIds(String groupId) { |
182 | 0 | return getGroupService().getMemberPrincipalIds(groupId); |
183 | |
} |
184 | |
@Override |
185 | |
public List<String> getDirectGroupMemberPrincipalIds(String groupId) { |
186 | 0 | return getGroupService().getDirectMemberPrincipalIds(groupId); |
187 | |
} |
188 | |
@Override |
189 | |
public List<String> getGroupIdsForPrincipal(String principalId) { |
190 | 0 | return getGroupService().getGroupIdsForPrincipal(principalId); |
191 | |
} |
192 | |
@Override |
193 | |
public List<String> getGroupIdsForPrincipal(String principalId, String namespaceCode ) { |
194 | 0 | return getGroupService().getGroupIdsForPrincipalByNamespace(principalId, namespaceCode ); |
195 | |
} |
196 | |
@Override |
197 | |
public List<Group> getGroupsForPrincipal(String principalId) { |
198 | 0 | return getGroupService().getGroupsForPrincipal(principalId); |
199 | |
} |
200 | |
@Override |
201 | |
public List<Group> getGroupsForPrincipal(String principalId, String namespaceCode ) { |
202 | 0 | return getGroupService().getGroupsForPrincipalByNamespace(principalId, namespaceCode ); |
203 | |
} |
204 | |
@Override |
205 | |
public List<String> getMemberGroupIds(String groupId) { |
206 | 0 | return getGroupService().getMemberGroupIds(groupId); |
207 | |
} |
208 | |
@Override |
209 | |
public List<String> getDirectMemberGroupIds(String groupId) { |
210 | 0 | return getGroupService().getDirectMemberGroupIds(groupId); |
211 | |
} |
212 | |
@Override |
213 | |
public Group getGroup(String groupId) { |
214 | 0 | return getGroupService().getGroup(groupId); |
215 | |
} |
216 | |
@Override |
217 | |
public Group getGroupByName(String namespaceCode, String groupName) { |
218 | 0 | return getGroupService().getGroupByName( namespaceCode, groupName ); |
219 | |
} |
220 | |
@Override |
221 | |
public List<String> getParentGroupIds(String groupId) { |
222 | 0 | return getGroupService().getParentGroupIds(groupId); |
223 | |
} |
224 | |
@Override |
225 | |
public List<String> getDirectParentGroupIds(String groupId) { |
226 | 0 | return getGroupService().getDirectParentGroupIds( groupId ); |
227 | |
} |
228 | |
|
229 | |
@Override |
230 | |
public boolean addGroupToGroup(String childId, String parentId) { |
231 | 0 | return getGroupService().addGroupToGroup(childId, parentId); |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public boolean addPrincipalToGroup(String principalId, String groupId) { |
236 | 0 | return getGroupService().addPrincipalToGroup(principalId, groupId); |
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
public boolean removeGroupFromGroup(String childId, String parentId) { |
241 | 0 | return getGroupService().removeGroupFromGroup(childId, parentId); |
242 | |
} |
243 | |
|
244 | |
@Override |
245 | |
public boolean removePrincipalFromGroup(String principalId, String groupId) { |
246 | 0 | return getGroupService().removePrincipalFromGroup(principalId, groupId); |
247 | |
} |
248 | |
|
249 | |
@Override |
250 | |
public Group createGroup(Group group) { |
251 | 0 | return getGroupService().createGroup(group); |
252 | |
} |
253 | |
|
254 | |
@Override |
255 | |
public void removeAllMembers(String groupId) { |
256 | 0 | getGroupService().removeAllMembers(groupId); |
257 | 0 | } |
258 | |
|
259 | |
@Override |
260 | |
public Group updateGroup(String groupId, Group group) { |
261 | 0 | return getGroupService().updateGroup(groupId, group); |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
@Override |
267 | |
public Principal getPrincipal(String principalId) { |
268 | 0 | return getIdentityService().getPrincipal(principalId); |
269 | |
} |
270 | |
|
271 | |
@Override |
272 | |
public Principal getPrincipalByPrincipalName(String principalName) { |
273 | 0 | return getIdentityService().getPrincipalByPrincipalName(principalName); |
274 | |
} |
275 | |
|
276 | |
@Override |
277 | |
public Principal getPrincipalByPrincipalNameAndPassword(String principalName, String password) { |
278 | 0 | return getIdentityService().getPrincipalByPrincipalNameAndPassword(principalName, password); |
279 | |
} |
280 | |
|
281 | |
@Override |
282 | |
public EntityDefault getEntityDefaultInfo(String entityId) { |
283 | 0 | return getIdentityService().getEntityDefault(entityId); |
284 | |
} |
285 | |
|
286 | |
@Override |
287 | |
public EntityDefault getEntityDefaultInfoByPrincipalId( |
288 | |
String principalId) { |
289 | 0 | return getIdentityService().getEntityDefaultByPrincipalId(principalId); |
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public EntityDefault getEntityDefaultInfoByPrincipalName( |
294 | |
String principalName) { |
295 | 0 | return getIdentityService().getEntityDefaultByPrincipalName(principalName); |
296 | |
} |
297 | |
|
298 | |
@Override |
299 | |
public EntityDefaultQueryResults findEntityDefaults(QueryByCriteria queryByCriteria) { |
300 | 0 | return getIdentityService().findEntityDefaults(queryByCriteria); |
301 | |
} |
302 | |
|
303 | |
@Override |
304 | |
public Entity getEntity(String entityId) { |
305 | 0 | return getIdentityService().getEntity(entityId); |
306 | |
} |
307 | |
|
308 | |
@Override |
309 | |
public Entity getEntityByPrincipalId(String principalId) { |
310 | 0 | return getIdentityService().getEntityByPrincipalId(principalId); |
311 | |
} |
312 | |
|
313 | |
@Override |
314 | |
public Entity getEntityByPrincipalName(String principalName) { |
315 | 0 | return getIdentityService().getEntityByPrincipalName(principalName); |
316 | |
} |
317 | |
|
318 | |
@Override |
319 | |
public EntityQueryResults findEntities(QueryByCriteria queryByCriteria) { |
320 | 0 | return getIdentityService().findEntities(queryByCriteria); |
321 | |
} |
322 | |
|
323 | |
@Override |
324 | |
public Type getAddressType( String code ) { |
325 | 0 | return getIdentityService().getAddressType(code); |
326 | |
} |
327 | |
|
328 | |
@Override |
329 | |
public Type getEmailType( String code ) { |
330 | 0 | return getIdentityService().getEmailType(code); |
331 | |
} |
332 | |
|
333 | |
@Override |
334 | |
public EntityAffiliationType getAffiliationType( String code ) { |
335 | 0 | return getIdentityService().getAffiliationType(code); |
336 | |
} |
337 | |
|
338 | |
@Override |
339 | |
public Type getCitizenshipStatus( String code ) { |
340 | 0 | return Type.Builder.create(getIdentityService().getCitizenshipStatus(code)).build(); |
341 | |
} |
342 | |
@Override |
343 | |
public Type getEmploymentStatus( String code ) { |
344 | 0 | return getIdentityService().getEmploymentStatus(code); |
345 | |
} |
346 | |
@Override |
347 | |
public Type getEmploymentType( String code ) { |
348 | 0 | return getIdentityService().getEmploymentType(code); |
349 | |
} |
350 | |
@Override |
351 | |
public Type getEntityNameType( String code ) { |
352 | 0 | return getIdentityService().getNameType(code); |
353 | |
} |
354 | |
@Override |
355 | |
public Type getEntityType( String code ) { |
356 | 0 | return getIdentityService().getEntityType(code); |
357 | |
} |
358 | |
@Override |
359 | |
public EntityExternalIdentifierType getExternalIdentifierType( String code ) { |
360 | 0 | return getIdentityService().getExternalIdentifierType(code); |
361 | |
} |
362 | |
@Override |
363 | |
public Type getPhoneType( String code ) { |
364 | 0 | return getIdentityService().getPhoneType(code); |
365 | |
} |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
@Override |
372 | |
public Responsibility getResponsibility(String responsibilityId) { |
373 | 0 | return getResponsibilityService().getResponsibility( responsibilityId ); |
374 | |
} |
375 | |
|
376 | |
@Override |
377 | |
public boolean hasResponsibility(String principalId, String namespaceCode, |
378 | |
String responsibilityName, Map<String, String> qualification, |
379 | |
Map<String, String> responsibilityDetails) { |
380 | 0 | return getResponsibilityService().hasResponsibility( principalId, namespaceCode, responsibilityName, |
381 | |
qualification, responsibilityDetails ); |
382 | |
} |
383 | |
|
384 | |
@Override |
385 | |
public Responsibility getResponsibilityByName( String namespaceCode, String responsibilityName) { |
386 | 0 | return getResponsibilityService().findRespByNamespaceCodeAndName(namespaceCode, responsibilityName); |
387 | |
} |
388 | |
|
389 | |
@Override |
390 | |
public List<ResponsibilityAction> getResponsibilityActions( String namespaceCode, String responsibilityName, |
391 | |
Map<String, String> qualification, Map<String, String> responsibilityDetails) { |
392 | 0 | return getResponsibilityService().getResponsibilityActions( namespaceCode, responsibilityName, qualification, |
393 | |
responsibilityDetails ); |
394 | |
} |
395 | |
|
396 | |
@Override |
397 | |
public List<ResponsibilityAction> getResponsibilityActionsByTemplateName( |
398 | |
String namespaceCode, String responsibilityTemplateName, |
399 | |
Map<String, String> qualification, Map<String, String> responsibilityDetails) { |
400 | 0 | return getResponsibilityService().getResponsibilityActionsByTemplateName(namespaceCode, responsibilityTemplateName, |
401 | |
qualification, responsibilityDetails); |
402 | |
} |
403 | |
|
404 | |
@Override |
405 | |
public boolean hasResponsibilityByTemplateName(String principalId, |
406 | |
String namespaceCode, String responsibilityTemplateName, |
407 | |
Map<String, String> qualification, Map<String, String> responsibilityDetails) { |
408 | 0 | return getResponsibilityService().hasResponsibilityByTemplateName(principalId, namespaceCode, responsibilityTemplateName, |
409 | |
qualification, responsibilityDetails); |
410 | |
} |
411 | |
|
412 | |
protected void logAuthorizationCheck(String checkType, String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
413 | 0 | StringBuilder sb = new StringBuilder(); |
414 | 0 | sb.append( '\n' ); |
415 | 0 | sb.append( "Is AuthZ for " ).append( checkType ).append( ": " ).append( namespaceCode ).append( "/" ).append( permissionName ).append( '\n' ); |
416 | 0 | sb.append( " Principal: " ).append( principalId ); |
417 | 0 | if ( principalId != null ) { |
418 | 0 | Principal principal = getPrincipal( principalId ); |
419 | 0 | if ( principal != null ) { |
420 | 0 | sb.append( " (" ).append( principal.getPrincipalName() ).append( ')' ); |
421 | |
} |
422 | |
} |
423 | 0 | sb.append( '\n' ); |
424 | 0 | sb.append( " Details:\n" ); |
425 | 0 | if ( permissionDetails != null ) { |
426 | 0 | sb.append( permissionDetails); |
427 | |
} else { |
428 | 0 | sb.append( " [null]\n" ); |
429 | |
} |
430 | 0 | sb.append( " Qualifiers:\n" ); |
431 | 0 | if ( qualification != null && !qualification.isEmpty() ) { |
432 | 0 | sb.append( qualification); |
433 | |
} else { |
434 | 0 | sb.append( " [null]\n" ); |
435 | |
} |
436 | 0 | if (LOG.isTraceEnabled()) { |
437 | 0 | LOG.trace( sb.append(ExceptionUtils.getStackTrace(new Throwable()))); |
438 | |
} else { |
439 | 0 | LOG.debug(sb.toString()); |
440 | |
} |
441 | 0 | } |
442 | |
|
443 | |
protected void logHasPermissionCheck(String checkType, String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails ) { |
444 | 0 | StringBuilder sb = new StringBuilder(); |
445 | 0 | sb.append( '\n' ); |
446 | 0 | sb.append( "Has Perm for " ).append( checkType ).append( ": " ).append( namespaceCode ).append( "/" ).append( permissionName ).append( '\n' ); |
447 | 0 | sb.append( " Principal: " ).append( principalId ); |
448 | 0 | if ( principalId != null ) { |
449 | 0 | Principal principal = getPrincipal( principalId ); |
450 | 0 | if ( principal != null ) { |
451 | 0 | sb.append( " (" ).append( principal.getPrincipalName() ).append( ')' ); |
452 | |
} |
453 | |
} |
454 | 0 | sb.append( '\n' ); |
455 | 0 | sb.append( " Details:\n" ); |
456 | 0 | if ( permissionDetails != null ) { |
457 | 0 | sb.append( permissionDetails); |
458 | |
} else { |
459 | 0 | sb.append( " [null]\n" ); |
460 | |
} |
461 | 0 | if (LOG.isTraceEnabled()) { |
462 | 0 | LOG.trace( sb.append( ExceptionUtils.getStackTrace(new Throwable())) ); |
463 | |
} else { |
464 | 0 | LOG.debug(sb.toString()); |
465 | |
} |
466 | 0 | } |
467 | |
|
468 | |
|
469 | |
|
470 | |
public IdentityService getIdentityService() { |
471 | 0 | if ( identityService == null ) { |
472 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
473 | |
} |
474 | 0 | return identityService; |
475 | |
} |
476 | |
|
477 | |
public GroupService getGroupService() { |
478 | 0 | if ( groupService == null ) { |
479 | 0 | groupService = KimApiServiceLocator.getGroupService(); |
480 | |
} |
481 | 0 | return groupService; |
482 | |
} |
483 | |
|
484 | |
public PermissionService getPermissionService() { |
485 | 0 | if ( permissionService == null ) { |
486 | 0 | permissionService = KimApiServiceLocator.getPermissionService(); |
487 | |
} |
488 | 0 | return permissionService; |
489 | |
} |
490 | |
|
491 | |
public ResponsibilityService getResponsibilityService() { |
492 | 0 | if ( responsibilityService == null ) { |
493 | 0 | responsibilityService = KimApiServiceLocator.getResponsibilityService(); |
494 | |
} |
495 | 0 | return responsibilityService; |
496 | |
} |
497 | |
} |