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 java.sql.Date; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.jws.WebService; |
25 | |
|
26 | |
import org.apache.commons.collections.CollectionUtils; |
27 | |
import org.apache.commons.lang.StringUtils; |
28 | |
import org.apache.log4j.Logger; |
29 | |
import org.kuali.rice.kim.bo.Role; |
30 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
31 | |
import org.kuali.rice.kim.bo.role.dto.RoleMemberCompleteInfo; |
32 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationImpl; |
33 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberAttributeDataImpl; |
34 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberImpl; |
35 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl; |
36 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl; |
37 | |
import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl; |
38 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl; |
39 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
40 | |
import org.kuali.rice.kim.service.RoleUpdateService; |
41 | |
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
42 | |
import org.kuali.rice.kim.util.KimConstants; |
43 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
44 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@WebService(endpointInterface = KIMWebServiceConstants.RoleUpdateService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
52 | 0 | public class RoleUpdateServiceImpl extends RoleServiceBase implements RoleUpdateService { |
53 | 0 | private static final Logger LOG = Logger.getLogger( RoleUpdateServiceImpl.class ); |
54 | |
|
55 | |
public void assignGroupToRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) { |
56 | |
|
57 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
58 | |
|
59 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) { |
60 | 0 | return; |
61 | |
} |
62 | |
|
63 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
64 | |
|
65 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
66 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
67 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
68 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
69 | |
|
70 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
71 | 0 | newRoleMember.setMemberId( groupId ); |
72 | 0 | newRoleMember.setMemberTypeCode( Role.GROUP_MEMBER_TYPE ); |
73 | |
|
74 | |
|
75 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
76 | |
|
77 | |
|
78 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
79 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
80 | 0 | } |
81 | |
|
82 | |
public void assignPrincipalToRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier) { |
83 | |
|
84 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
85 | 0 | role.refreshReferenceObject("members"); |
86 | |
|
87 | |
|
88 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) { |
89 | 0 | return; |
90 | |
} |
91 | |
|
92 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
93 | |
|
94 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
95 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
96 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class ); |
97 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
98 | |
|
99 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
100 | 0 | newRoleMember.setMemberId( principalId ); |
101 | 0 | newRoleMember.setMemberTypeCode( Role.PRINCIPAL_MEMBER_TYPE ); |
102 | |
|
103 | |
|
104 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
105 | |
|
106 | |
|
107 | |
|
108 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
109 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
110 | 0 | } |
111 | |
|
112 | |
public void assignRoleToRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) { |
113 | |
|
114 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
115 | |
|
116 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) { |
117 | 0 | return; |
118 | |
} |
119 | |
|
120 | 0 | if ( !checkForCircularRoleMembership( roleId, role) ){ |
121 | 0 | throw new IllegalArgumentException("Circular role reference."); |
122 | |
} |
123 | |
|
124 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
125 | |
|
126 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
127 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
128 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
129 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
130 | |
|
131 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
132 | 0 | newRoleMember.setMemberId( roleId ); |
133 | 0 | newRoleMember.setMemberTypeCode( Role.ROLE_MEMBER_TYPE ); |
134 | |
|
135 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
136 | |
|
137 | |
|
138 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
139 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
140 | 0 | } |
141 | |
|
142 | |
public void removeGroupFromRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) { |
143 | |
|
144 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
145 | |
|
146 | |
|
147 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
148 | 0 | if ( doesMemberMatch( rm, groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) { |
149 | |
|
150 | |
|
151 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
152 | |
} |
153 | |
} |
154 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
155 | 0 | } |
156 | |
|
157 | |
public void removePrincipalFromRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier ) { |
158 | |
|
159 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
160 | |
|
161 | 0 | role.refreshReferenceObject("members"); |
162 | |
|
163 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
164 | 0 | if ( doesMemberMatch( rm, principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) { |
165 | |
|
166 | |
|
167 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
168 | |
} |
169 | |
} |
170 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
171 | 0 | } |
172 | |
|
173 | |
public void removeRoleFromRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) { |
174 | |
|
175 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
176 | |
|
177 | |
|
178 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
179 | 0 | if ( doesMemberMatch( rm, roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) { |
180 | |
|
181 | |
|
182 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
183 | |
} |
184 | |
} |
185 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
186 | 0 | } |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public void saveDelegationMemberForRole(String delegationMemberId, |
195 | |
String roleMemberId, String memberId, String memberTypeCode, String delegationTypeCode, |
196 | |
String roleId, AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{ |
197 | 0 | if(StringUtils.isEmpty(delegationMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){ |
198 | 0 | throw new IllegalArgumentException("Either Delegation member ID or a combination of member ID and role ID must be passed in."); |
199 | |
} |
200 | |
|
201 | 0 | RoleImpl role = getRoleImpl(roleId); |
202 | 0 | KimDelegationImpl delegation = getDelegationOfType(role.getRoleId(), delegationTypeCode); |
203 | |
|
204 | 0 | KimDelegationMemberImpl newDelegationMember = new KimDelegationMemberImpl(); |
205 | |
|
206 | 0 | KimDelegationMemberImpl origDelegationMember = null; |
207 | 0 | if(StringUtils.isNotEmpty(delegationMemberId)){ |
208 | 0 | origDelegationMember = getKimDelegationMemberImpl(delegationMemberId); |
209 | |
} else{ |
210 | 0 | List<KimDelegationMemberImpl> origDelegationMembers = |
211 | |
getKimDelegationMemberImplListByMemberAndDelegationId(memberId, delegation.getDelegationId()); |
212 | 0 | origDelegationMember = |
213 | |
(origDelegationMembers!=null && origDelegationMembers.size()>0) ? origDelegationMembers.get(0) : null; |
214 | |
} |
215 | 0 | if(origDelegationMember!=null){ |
216 | 0 | newDelegationMember.setDelegationMemberId(origDelegationMember.getDelegationMemberId()); |
217 | 0 | newDelegationMember.setVersionNumber(origDelegationMember.getVersionNumber()); |
218 | |
} else{ |
219 | 0 | newDelegationMember.setDelegationMemberId(getNewDelegationMemberId()); |
220 | |
} |
221 | 0 | newDelegationMember.setMemberId(memberId); |
222 | 0 | newDelegationMember.setDelegationId(delegation.getDelegationId()); |
223 | 0 | newDelegationMember.setRoleMemberId(roleMemberId); |
224 | 0 | newDelegationMember.setMemberTypeCode(memberTypeCode); |
225 | 0 | if (activeFromDate != null) { |
226 | 0 | newDelegationMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime())); |
227 | |
} |
228 | 0 | if (activeToDate != null) { |
229 | 0 | newDelegationMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime())); |
230 | |
} |
231 | |
|
232 | |
|
233 | 0 | addDelegationMemberAttributeData( newDelegationMember, qualifications, role.getKimTypeId() ); |
234 | |
|
235 | 0 | List<KimDelegationMemberImpl> delegationMembers = new ArrayList<KimDelegationMemberImpl>(); |
236 | 0 | delegationMembers.add(newDelegationMember); |
237 | 0 | delegation.setMembers(delegationMembers); |
238 | |
|
239 | 0 | getBusinessObjectService().save(delegation); |
240 | 0 | for(KimDelegationMemberImpl delegationMember: delegation.getMembers()){ |
241 | 0 | deleteNullDelegationMemberAttributeData(delegationMember.getAttributes()); |
242 | |
} |
243 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
244 | 0 | } |
245 | |
|
246 | |
public RoleMemberCompleteInfo saveRoleMemberForRole(String roleMemberId, String memberId, String memberTypeCode, String roleId, |
247 | |
AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{ |
248 | 0 | if(StringUtils.isEmpty(roleMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){ |
249 | 0 | throw new IllegalArgumentException("Either Role member ID or a combination of member ID and role ID must be passed in."); |
250 | |
} |
251 | 0 | RoleMemberImpl origRoleMember = null; |
252 | |
RoleImpl role; |
253 | |
|
254 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
255 | 0 | if(StringUtils.isEmpty(roleMemberId)){ |
256 | |
|
257 | 0 | role = getRoleImpl(roleId); |
258 | |
|
259 | 0 | origRoleMember = matchingMemberRecord( role.getMembers(), memberId, memberTypeCode, qualifications ); |
260 | |
} else{ |
261 | 0 | origRoleMember = getRoleMemberImpl(roleMemberId); |
262 | 0 | role = getRoleImpl(origRoleMember.getRoleId()); |
263 | |
} |
264 | |
|
265 | 0 | if(origRoleMember !=null){ |
266 | 0 | newRoleMember.setRoleMemberId(origRoleMember.getRoleMemberId()); |
267 | 0 | newRoleMember.setVersionNumber(origRoleMember.getVersionNumber()); |
268 | |
} else { |
269 | |
|
270 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
271 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
272 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
273 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
274 | |
} |
275 | 0 | newRoleMember.setRoleId(role.getRoleId()); |
276 | 0 | newRoleMember.setMemberId( memberId ); |
277 | 0 | newRoleMember.setMemberTypeCode( memberTypeCode ); |
278 | 0 | if (activeFromDate != null) { |
279 | 0 | newRoleMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime())); |
280 | |
} |
281 | 0 | if (activeToDate != null) { |
282 | 0 | newRoleMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime())); |
283 | |
} |
284 | |
|
285 | 0 | addMemberAttributeData( newRoleMember, qualifications, role.getKimTypeId() ); |
286 | |
|
287 | |
|
288 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
289 | 0 | deleteNullMemberAttributeData(newRoleMember.getAttributes()); |
290 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
291 | |
|
292 | 0 | return findRoleMemberCompleteInfo(newRoleMember.getRoleMemberId()); |
293 | |
} |
294 | |
|
295 | |
public void saveRoleRspActions(String roleResponsibilityActionId, String roleId, String roleResponsibilityId, String roleMemberId, |
296 | |
String actionTypeCode, String actionPolicyCode, Integer priorityNumber, Boolean forceAction){ |
297 | 0 | RoleResponsibilityActionImpl newRoleRspAction = new RoleResponsibilityActionImpl(); |
298 | 0 | newRoleRspAction.setActionPolicyCode(actionPolicyCode); |
299 | 0 | newRoleRspAction.setActionTypeCode(actionTypeCode); |
300 | 0 | newRoleRspAction.setPriorityNumber(priorityNumber); |
301 | 0 | newRoleRspAction.setForceAction(forceAction); |
302 | 0 | newRoleRspAction.setRoleMemberId(roleMemberId); |
303 | 0 | newRoleRspAction.setRoleResponsibilityId(roleResponsibilityId); |
304 | 0 | if(StringUtils.isEmpty(roleResponsibilityActionId)){ |
305 | |
|
306 | 0 | Map<String, String> criteria = new HashMap<String, String>(1); |
307 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ID, roleResponsibilityId); |
308 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId); |
309 | 0 | List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>) |
310 | |
getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria); |
311 | 0 | if(roleResponsibilityActionImpls!=null && roleResponsibilityActionImpls.size()>0){ |
312 | 0 | newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId()); |
313 | 0 | newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber()); |
314 | |
} else{ |
315 | |
|
316 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
317 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
318 | |
KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S, RoleResponsibilityActionImpl.class); |
319 | 0 | newRoleRspAction.setRoleResponsibilityActionId(nextSeq.toString()); |
320 | |
} |
321 | 0 | } else{ |
322 | 0 | Map<String, String> criteria = new HashMap<String, String>(1); |
323 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ACTION_ID, roleResponsibilityActionId); |
324 | 0 | List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>) |
325 | |
getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria); |
326 | 0 | if(CollectionUtils.isNotEmpty(roleResponsibilityActionImpls) && roleResponsibilityActionImpls.size()>0){ |
327 | 0 | newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId()); |
328 | 0 | newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber()); |
329 | |
} |
330 | |
} |
331 | 0 | getBusinessObjectService().save(newRoleRspAction); |
332 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
333 | 0 | } |
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
private void deleteNullMemberAttributeData(List<RoleMemberAttributeDataImpl> attributes) { |
340 | 0 | List<RoleMemberAttributeDataImpl> attributesToDelete = new ArrayList<RoleMemberAttributeDataImpl>(); |
341 | 0 | for(RoleMemberAttributeDataImpl attribute: attributes){ |
342 | 0 | if(attribute.getAttributeValue()==null){ |
343 | 0 | attributesToDelete.add(attribute); |
344 | |
} |
345 | |
} |
346 | 0 | getBusinessObjectService().delete(attributesToDelete); |
347 | 0 | } |
348 | |
|
349 | |
private void deleteNullDelegationMemberAttributeData(List<KimDelegationMemberAttributeDataImpl> attributes) { |
350 | 0 | List<KimDelegationMemberAttributeDataImpl> attributesToDelete = new ArrayList<KimDelegationMemberAttributeDataImpl>(); |
351 | 0 | for(KimDelegationMemberAttributeDataImpl attribute: attributes){ |
352 | 0 | if(attribute.getAttributeValue()==null){ |
353 | 0 | attributesToDelete.add(attribute); |
354 | |
} |
355 | |
} |
356 | 0 | getBusinessObjectService().delete(attributesToDelete); |
357 | 0 | } |
358 | |
|
359 | |
protected void addMemberAttributeData( RoleMemberImpl roleMember, AttributeSet qualifier, String kimTypeId ) { |
360 | 0 | List<RoleMemberAttributeDataImpl> attributes = new ArrayList<RoleMemberAttributeDataImpl>(); |
361 | 0 | for ( String attributeName : qualifier.keySet() ) { |
362 | 0 | RoleMemberAttributeDataImpl a = new RoleMemberAttributeDataImpl(); |
363 | 0 | a.setAttributeValue( qualifier.get( attributeName ) ); |
364 | 0 | a.setKimTypeId( kimTypeId ); |
365 | 0 | a.setRoleMemberId( roleMember.getRoleMemberId() ); |
366 | |
|
367 | 0 | a.setKimAttributeId( getKimAttributeId( attributeName ) ); |
368 | |
|
369 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
370 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId()); |
371 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMember.getRoleMemberId()); |
372 | 0 | List<RoleMemberAttributeDataImpl> origRoleMemberAttributes = |
373 | |
(List<RoleMemberAttributeDataImpl>)getBusinessObjectService().findMatching(RoleMemberAttributeDataImpl.class, criteria); |
374 | 0 | RoleMemberAttributeDataImpl origRoleMemberAttribute = |
375 | |
(origRoleMemberAttributes!=null && origRoleMemberAttributes.size()>0) ? origRoleMemberAttributes.get(0) : null; |
376 | 0 | if(origRoleMemberAttribute!=null){ |
377 | 0 | a.setAttributeDataId(origRoleMemberAttribute.getAttributeDataId()); |
378 | 0 | a.setVersionNumber(origRoleMemberAttribute.getVersionNumber()); |
379 | |
} else{ |
380 | |
|
381 | 0 | a.setAttributeDataId(getNewAttributeDataId()); |
382 | |
} |
383 | 0 | attributes.add( a ); |
384 | 0 | } |
385 | 0 | roleMember.setAttributes( attributes ); |
386 | 0 | } |
387 | |
|
388 | |
protected void addDelegationMemberAttributeData( KimDelegationMemberImpl delegationMember, AttributeSet qualifier, String kimTypeId ) { |
389 | 0 | List<KimDelegationMemberAttributeDataImpl> attributes = new ArrayList<KimDelegationMemberAttributeDataImpl>(); |
390 | 0 | for ( String attributeName : qualifier.keySet() ) { |
391 | 0 | KimDelegationMemberAttributeDataImpl a = new KimDelegationMemberAttributeDataImpl(); |
392 | 0 | a.setAttributeValue( qualifier.get( attributeName ) ); |
393 | 0 | a.setKimTypeId( kimTypeId ); |
394 | 0 | a.setDelegationMemberId( delegationMember.getDelegationMemberId() ); |
395 | |
|
396 | 0 | a.setKimAttributeId( getKimAttributeId( attributeName ) ); |
397 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
398 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId()); |
399 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMember.getDelegationMemberId()); |
400 | 0 | List<KimDelegationMemberAttributeDataImpl> origDelegationMemberAttributes = |
401 | |
(List<KimDelegationMemberAttributeDataImpl>)getBusinessObjectService().findMatching(KimDelegationMemberAttributeDataImpl.class, criteria); |
402 | 0 | KimDelegationMemberAttributeDataImpl origDelegationMemberAttribute = |
403 | |
(origDelegationMemberAttributes!=null && origDelegationMemberAttributes.size()>0) ? origDelegationMemberAttributes.get(0) : null; |
404 | 0 | if(origDelegationMemberAttribute!=null){ |
405 | 0 | a.setAttributeDataId(origDelegationMemberAttribute.getAttributeDataId()); |
406 | 0 | a.setVersionNumber(origDelegationMemberAttribute.getVersionNumber()); |
407 | |
} else{ |
408 | |
|
409 | 0 | a.setAttributeDataId(getNewAttributeDataId()); |
410 | |
} |
411 | 0 | attributes.add( a ); |
412 | 0 | } |
413 | 0 | delegationMember.setAttributes( attributes ); |
414 | 0 | } |
415 | |
|
416 | |
public void saveRole(String roleId, String roleName, String roleDescription, boolean active, String kimTypeId, String namespaceCode) throws UnsupportedOperationException { |
417 | |
|
418 | 0 | RoleImpl role = getBusinessObjectService().findBySinglePrimaryKey(RoleImpl.class, roleId); |
419 | 0 | if (role == null) { |
420 | 0 | role = new RoleImpl(); |
421 | 0 | role.setRoleId(roleId); |
422 | |
} |
423 | |
|
424 | 0 | role.setRoleName(roleName); |
425 | 0 | role.setRoleDescription(roleDescription); |
426 | 0 | role.setActive(active); |
427 | 0 | role.setKimTypeId(kimTypeId); |
428 | 0 | role.setNamespaceCode(namespaceCode); |
429 | |
|
430 | 0 | getBusinessObjectService().save(role); |
431 | 0 | } |
432 | |
|
433 | |
public String getNextAvailableRoleId() throws UnsupportedOperationException { |
434 | 0 | Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleImpl.class); |
435 | |
|
436 | 0 | if (nextSeq == null) { |
437 | 0 | LOG.error("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S); |
438 | 0 | throw new RuntimeException("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S); |
439 | |
} |
440 | |
|
441 | 0 | return nextSeq.toString(); |
442 | |
} |
443 | |
|
444 | |
public void assignPermissionToRole(String permissionId, String roleId) throws UnsupportedOperationException { |
445 | 0 | RolePermissionImpl newRolePermission = new RolePermissionImpl(); |
446 | |
|
447 | 0 | Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S, RolePermissionImpl.class); |
448 | |
|
449 | 0 | if (nextSeq == null) { |
450 | 0 | LOG.error("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S); |
451 | 0 | throw new RuntimeException("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S); |
452 | |
} |
453 | |
|
454 | 0 | newRolePermission.setRolePermissionId(nextSeq.toString()); |
455 | 0 | newRolePermission.setRoleId(roleId); |
456 | 0 | newRolePermission.setPermissionId(permissionId); |
457 | 0 | newRolePermission.setActive(true); |
458 | |
|
459 | 0 | getBusinessObjectService().save(newRolePermission); |
460 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
461 | 0 | } |
462 | |
} |