1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.support.impl; |
17 | |
|
18 | |
|
19 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault; |
20 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
21 | |
import org.kuali.rice.kim.api.role.Role; |
22 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
23 | |
import org.kuali.rice.kim.api.services.IdentityService; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.kim.util.KimConstants; |
26 | |
|
27 | |
import java.util.ArrayList; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class PrincipalDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase { |
38 | |
|
39 | |
private IdentityService identityService; |
40 | |
|
41 | |
{ |
42 | 0 | requiredAttributes.add( KimConstants.AttributeConstants.PRINCIPAL_ID ); |
43 | 0 | checkRequiredAttributes = false; |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public boolean performMatch(Map<String, String> inputAttributes, Map<String, String> storedAttributes) { |
48 | 0 | return true; |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@Override |
55 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
56 | 0 | ArrayList<RoleMembership> tempIdList = new ArrayList<RoleMembership>(); |
57 | 0 | if ( qualification == null || qualification.isEmpty() ) { |
58 | 0 | return tempIdList; |
59 | |
} |
60 | 0 | qualification = translateInputAttributes(qualification); |
61 | |
|
62 | 0 | String principalId = qualification.get( KimConstants.AttributeConstants.PRINCIPAL_ID ); |
63 | 0 | if ( hasApplicationRole(principalId, null, namespaceCode, roleName, qualification)) { |
64 | 0 | tempIdList.add( RoleMembership.Builder.create(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null).build()); |
65 | |
} |
66 | 0 | return tempIdList; |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) { |
71 | |
|
72 | 0 | Principal principal = getIdentityService().getPrincipal( principalId ); |
73 | 0 | if ( principal == null || !principal.isActive() ) { |
74 | 0 | return false; |
75 | |
} |
76 | |
|
77 | 0 | EntityDefault entity = getIdentityService().getEntityDefault( principal.getEntityId() ); |
78 | 0 | return entity != null && entity.isActive(); |
79 | |
} |
80 | |
|
81 | |
protected IdentityService getIdentityService() { |
82 | 0 | if ( identityService == null ) { |
83 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
84 | |
} |
85 | 0 | return identityService; |
86 | |
} |
87 | |
} |