1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.kim.role; |
17 | |
|
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
21 | |
import org.kuali.rice.core.api.membership.MemberType; |
22 | |
import org.kuali.rice.kim.api.KimConstants; |
23 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
24 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault; |
25 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
26 | |
import org.kuali.rice.kim.api.role.Role; |
27 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
28 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
29 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.Collections; |
33 | |
import java.util.List; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Deprecated |
44 | 0 | public class PrincipalDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase { |
45 | |
|
46 | |
private IdentityService identityService; |
47 | |
|
48 | |
@Override |
49 | |
protected List<String> getRequiredAttributes() { |
50 | 0 | final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes()); |
51 | 0 | attrs.add(KimConstants.AttributeConstants.PRINCIPAL_ID); |
52 | 0 | return Collections.unmodifiableList(attrs); |
53 | |
} |
54 | |
|
55 | |
@Override |
56 | |
protected boolean isCheckRequiredAttributes() { |
57 | 0 | return false; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public boolean performMatch(Map<String, String> inputAttributes, Map<String, String> storedAttributes) { |
62 | 0 | if (inputAttributes == null) { |
63 | 0 | throw new RiceIllegalArgumentException("inputAttributes was null"); |
64 | |
} |
65 | |
|
66 | 0 | if (storedAttributes == null) { |
67 | 0 | throw new RiceIllegalArgumentException("storedAttributes was null"); |
68 | |
} |
69 | |
|
70 | 0 | return true; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
78 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
79 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
80 | |
} |
81 | |
|
82 | 0 | if (roleName == null) { |
83 | 0 | throw new RiceIllegalArgumentException("roleName was null"); |
84 | |
} |
85 | |
|
86 | 0 | if ( qualification == null || qualification.isEmpty() ) { |
87 | 0 | return Collections.emptyList(); |
88 | |
} |
89 | 0 | ArrayList<RoleMembership> tempIdList = new ArrayList<RoleMembership>(); |
90 | 0 | qualification = translateInputAttributes(qualification); |
91 | |
|
92 | 0 | String principalId = qualification.get( KimConstants.AttributeConstants.PRINCIPAL_ID ); |
93 | 0 | if ( hasApplicationRole(principalId, null, namespaceCode, roleName, qualification)) { |
94 | 0 | tempIdList.add( RoleMembership.Builder.create(null, null, principalId, MemberType.PRINCIPAL, null).build()); |
95 | |
} |
96 | 0 | return tempIdList; |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) { |
101 | 0 | if (StringUtils.isBlank(principalId)) { |
102 | 0 | throw new RiceIllegalArgumentException("principalId was null or blank"); |
103 | |
} |
104 | |
|
105 | 0 | if (groupIds == null) { |
106 | 0 | throw new RiceIllegalArgumentException("groupIds was null or blank"); |
107 | |
} |
108 | |
|
109 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
110 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
111 | |
} |
112 | |
|
113 | 0 | if (StringUtils.isBlank(roleName)) { |
114 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
115 | |
} |
116 | |
|
117 | 0 | if (qualification == null) { |
118 | 0 | throw new RiceIllegalArgumentException("qualification was null"); |
119 | |
} |
120 | |
|
121 | |
|
122 | 0 | Principal principal = getIdentityService().getPrincipal( principalId ); |
123 | 0 | if ( principal == null || !principal.isActive() ) { |
124 | 0 | return false; |
125 | |
} |
126 | |
|
127 | 0 | EntityDefault entity = getIdentityService().getEntityDefault( principal.getEntityId() ); |
128 | 0 | return entity != null && entity.isActive(); |
129 | |
} |
130 | |
|
131 | |
protected IdentityService getIdentityService() { |
132 | 0 | if ( identityService == null ) { |
133 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
134 | |
} |
135 | 0 | return identityService; |
136 | |
} |
137 | |
} |