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 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.core.api.membership.MemberType; |
21 | |
import org.kuali.rice.kim.api.role.Role; |
22 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
23 | |
import org.kuali.rice.kim.framework.common.delegate.DelegationTypeService; |
24 | |
import org.kuali.rice.kim.framework.role.RoleTypeService; |
25 | |
import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase; |
26 | |
|
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Collections; |
29 | |
import java.util.HashMap; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
@Deprecated |
37 | 0 | public class RoleTypeServiceBase extends DataDictionaryTypeServiceBase implements RoleTypeService, DelegationTypeService { |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Override |
44 | |
public boolean doesRoleQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) { |
45 | 0 | if (qualification == null) { |
46 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
47 | |
} |
48 | |
|
49 | 0 | if (roleQualifier == null) { |
50 | 0 | throw new RiceIllegalArgumentException("roleQualifier was null or blank"); |
51 | |
} |
52 | |
|
53 | 0 | Map<String, String> translatedQualification = translateInputAttributes(qualification); |
54 | 0 | validateRequiredAttributesAgainstReceived(translatedQualification); |
55 | 0 | return performMatch(translatedQualification, roleQualifier); |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public List<RoleMembership> getMatchingRoleMemberships(Map<String, String> qualification, |
60 | |
List<RoleMembership> roleMemberList) { |
61 | 0 | if (qualification == null) { |
62 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
63 | |
} |
64 | |
|
65 | 0 | if (roleMemberList == null) { |
66 | 0 | throw new RiceIllegalArgumentException("roleMemberList was null or blank"); |
67 | |
} |
68 | |
|
69 | 0 | Map<String, String> translatedQualification = translateInputAttributes(qualification); |
70 | 0 | validateRequiredAttributesAgainstReceived(translatedQualification); |
71 | 0 | List<RoleMembership> matchingMemberships = new ArrayList<RoleMembership>(); |
72 | 0 | for ( RoleMembership roleMembership : roleMemberList ) { |
73 | 0 | if ( performMatch( translatedQualification, roleMembership.getQualifier() ) ) { |
74 | 0 | matchingMemberships.add( roleMembership ); |
75 | |
} |
76 | |
} |
77 | 0 | return Collections.unmodifiableList(matchingMemberships); |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
@Override |
86 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
87 | |
|
88 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
89 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
90 | |
} |
91 | |
|
92 | 0 | if (StringUtils.isBlank(roleName)) { |
93 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
94 | |
} |
95 | |
|
96 | 0 | if (qualification == null) { |
97 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
98 | |
} |
99 | |
|
100 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
101 | 0 | if ( !isApplicationRoleType() ) { |
102 | 0 | throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." ); |
103 | |
} else { |
104 | 0 | throw new UnsupportedOperationException( this.getClass().getName() + " is an application role type but has not overridden this method." ); |
105 | |
} |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
@Override |
114 | |
public boolean hasApplicationRole(String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification) { |
115 | 0 | if (StringUtils.isBlank(principalId)) { |
116 | 0 | throw new RiceIllegalArgumentException("principalId was null or blank"); |
117 | |
} |
118 | |
|
119 | 0 | if (groupIds == null) { |
120 | 0 | throw new RiceIllegalArgumentException("groupIds was null or blank"); |
121 | |
} |
122 | |
|
123 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
124 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
125 | |
} |
126 | |
|
127 | 0 | if (StringUtils.isBlank(roleName)) { |
128 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
129 | |
} |
130 | |
|
131 | 0 | if (qualification == null) { |
132 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
133 | |
} |
134 | |
|
135 | 0 | if ( !isApplicationRoleType() ) { |
136 | 0 | throw new UnsupportedOperationException( this.getClass().getName() + " is not an application role." ); |
137 | |
} |
138 | |
|
139 | 0 | if ( StringUtils.isNotBlank( principalId ) ) { |
140 | 0 | List<RoleMembership> members = getRoleMembersFromApplicationRole(namespaceCode, roleName, qualification); |
141 | 0 | for ( RoleMembership rm : members ) { |
142 | 0 | if ( StringUtils.isBlank( rm.getRoleMemberId() ) ) { |
143 | 0 | continue; |
144 | |
} |
145 | 0 | if ( MemberType.PRINCIPAL.equals(rm.getMemberType()) ) { |
146 | 0 | if ( rm.getMemberId().equals( principalId ) ) { |
147 | 0 | return true; |
148 | |
} |
149 | |
} else { |
150 | 0 | if ( groupIds != null |
151 | |
&& groupIds.contains(rm.getMemberId())) { |
152 | 0 | return true; |
153 | |
} |
154 | |
} |
155 | |
} |
156 | |
} |
157 | 0 | return false; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
public boolean isApplicationRoleType() { |
167 | 0 | return false; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
@Override |
176 | |
public Map<String, String> convertQualificationForMemberRoles(String namespaceCode, String roleName, String memberRoleNamespaceCode, String memberRoleName, Map<String, String> qualification) { |
177 | |
|
178 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
179 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
180 | |
} |
181 | |
|
182 | 0 | if (StringUtils.isBlank(roleName)) { |
183 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
184 | |
} |
185 | |
|
186 | 0 | if (StringUtils.isBlank(memberRoleNamespaceCode)) { |
187 | 0 | throw new RiceIllegalArgumentException("memberRoleNamespaceCode was null or blank"); |
188 | |
} |
189 | |
|
190 | 0 | if (StringUtils.isBlank(memberRoleName)) { |
191 | 0 | throw new RiceIllegalArgumentException("memberRoleName was null or blank"); |
192 | |
} |
193 | |
|
194 | 0 | if (qualification == null) { |
195 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
196 | |
} |
197 | |
|
198 | 0 | return Collections.unmodifiableMap(new HashMap<String, String>(qualification)); |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
@Override |
207 | |
public boolean doesDelegationQualifierMatchQualification(Map<String, String> qualification, Map<String, String> roleQualifier) { |
208 | 0 | if (qualification == null) { |
209 | 0 | throw new RiceIllegalArgumentException("qualification was null or blank"); |
210 | |
} |
211 | |
|
212 | 0 | if (roleQualifier == null) { |
213 | 0 | throw new RiceIllegalArgumentException("roleQualifier was null or blank"); |
214 | |
} |
215 | |
|
216 | 0 | Map<String, String> translatedQualification = translateInputAttributes(qualification); |
217 | 0 | validateRequiredAttributesAgainstReceived(translatedQualification); |
218 | 0 | return performMatch(translatedQualification, roleQualifier); |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
@Override |
227 | |
public boolean dynamicRoleMembership(String namespaceCode, String roleName) { |
228 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
229 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
230 | |
} |
231 | |
|
232 | 0 | if (StringUtils.isBlank(roleName)) { |
233 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
234 | |
} |
235 | |
|
236 | 0 | return true; |
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
public List<String> getQualifiersForExactMatch() { |
241 | 0 | return Collections.emptyList(); |
242 | |
} |
243 | |
|
244 | |
} |