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.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.core.api.membership.MemberType;
24 import org.kuali.rice.kim.api.KimConstants;
25 import org.kuali.rice.kim.api.group.Group;
26 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
27 import org.kuali.rice.kim.api.identity.email.EntityEmail;
28 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
29 import org.kuali.rice.kim.api.identity.entity.Entity;
30 import org.kuali.rice.kim.api.identity.name.EntityName;
31 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
32 import org.kuali.rice.kim.api.identity.principal.Principal;
33 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
34 import org.kuali.rice.kim.api.role.Role;
35 import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
36 import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
37 import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
38 import org.kuali.rice.kim.bo.ui.PersonDocumentName;
39 import org.kuali.rice.kim.bo.ui.PersonDocumentPhone;
40 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
41 import org.kuali.rice.kim.impl.common.delegate.DelegateTypeBo;
42 import org.kuali.rice.kim.impl.group.GroupBo;
43 import org.kuali.rice.kim.impl.group.GroupMemberBo;
44 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
45 import org.kuali.rice.kim.impl.identity.principal.PrincipalBo;
46 import org.kuali.rice.kim.impl.role.RoleBo;
47 import org.kuali.rice.kim.impl.role.RoleMemberAttributeDataBo;
48 import org.kuali.rice.kim.impl.role.RoleMemberBo;
49 import org.kuali.rice.kim.impl.role.RoleResponsibilityActionBo;
50 import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
51 import org.kuali.rice.krad.document.Document;
52 import org.kuali.rice.krad.util.KRADUtils;
53
54
55
56
57
58
59 public class LdapUiDocumentServiceImpl extends org.kuali.rice.kim.service.impl.UiDocumentServiceImpl {
60
61
62
63
64
65 @Override
66 public void loadEntityToPersonDoc(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId) {
67 Principal principal = this.getIdentityService().getPrincipal(principalId);
68 if(principal==null) {
69 throw new RuntimeException("Principal does not exist for principal id:"+principalId);
70 }
71
72 identityManagementPersonDocument.setPrincipalId(principal.getPrincipalId());
73 identityManagementPersonDocument.setPrincipalName(principal.getPrincipalName());
74
75 identityManagementPersonDocument.setActive(principal.isActive());
76 Entity kimEntity = this.getIdentityService().getEntity(principal.getEntityId());
77 identityManagementPersonDocument.setEntityId(kimEntity.getId());
78 if ( KRADUtils.isNotNull( kimEntity.getPrivacyPreferences() ) ) {
79 identityManagementPersonDocument.setPrivacy(loadPrivacyReferences(kimEntity.getPrivacyPreferences()));
80 }
81
82 identityManagementPersonDocument.setAffiliations(loadAffiliations(kimEntity.getAffiliations(),kimEntity.getEmploymentInformation()));
83 identityManagementPersonDocument.setNames(loadNames( identityManagementPersonDocument, principalId, kimEntity.getNames(), identityManagementPersonDocument.getPrivacy().isSuppressName() ));
84 EntityTypeContactInfo entityType = null;
85 for (EntityTypeContactInfo type : kimEntity.getEntityTypeContactInfos()) {
86 if (KimConstants.EntityTypes.PERSON.equals(type.getEntityTypeCode())) {
87 entityType = EntityTypeContactInfo.Builder.create(type).build();
88 }
89 }
90
91 if(entityType!=null){
92 identityManagementPersonDocument.setEmails(loadEmails(identityManagementPersonDocument, principalId, entityType.getEmailAddresses(), identityManagementPersonDocument.getPrivacy().isSuppressEmail()));
93 identityManagementPersonDocument.setPhones(loadPhones(identityManagementPersonDocument, principalId, entityType.getPhoneNumbers(), identityManagementPersonDocument.getPrivacy().isSuppressPhone()));
94 identityManagementPersonDocument.setAddrs(loadAddresses(identityManagementPersonDocument, principalId, entityType.getAddresses(), identityManagementPersonDocument.getPrivacy().isSuppressAddress()));
95 }
96
97 List<Group> groups = getGroupService().getGroups(getGroupService().getDirectGroupIdsByPrincipalId(
98 identityManagementPersonDocument.getPrincipalId()));
99 loadGroupToPersonDoc(identityManagementPersonDocument, groups);
100 loadRoleToPersonDoc(identityManagementPersonDocument);
101 loadDelegationsToPersonDoc(identityManagementPersonDocument);
102 }
103
104 protected String getInitiatorPrincipalId(Document document){
105 try{
106 return document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
107 } catch(Exception ex){
108 return null;
109 }
110 }
111
112
113
114
115 @Override
116 public void saveEntityPerson(IdentityManagementPersonDocument identityManagementPersonDocument) {
117 boolean inactivatingPrincipal = false;
118
119 List <GroupMemberBo> groupPrincipals = populateGroupMembers(identityManagementPersonDocument);
120 List <RoleMemberBo> rolePrincipals = populateRoleMembers(identityManagementPersonDocument);
121 List <DelegateTypeBo> personDelegations = populateDelegations(identityManagementPersonDocument);
122 List <Object> bos = new ArrayList<Object>();
123 List <RoleResponsibilityActionBo> roleRspActions = populateRoleRspActions(identityManagementPersonDocument);
124 List <RoleMemberAttributeDataBo> blankRoleMemberAttrs = getBlankRoleMemberAttrs(rolePrincipals);
125
126
127 bos.addAll(groupPrincipals);
128 bos.addAll(rolePrincipals);
129 bos.addAll(roleRspActions);
130 bos.addAll(personDelegations);
131
132 for ( Object bo : bos ) {
133 getDataObjectService().save(bo);
134 }
135
136 for ( RoleMemberAttributeDataBo blankRoleMemberAttr : blankRoleMemberAttrs ) {
137 getDataObjectService().delete(blankRoleMemberAttr);
138 }
139 if ( inactivatingPrincipal ) {
140
141 KimImplServiceLocator.getRoleInternalService().principalInactivated(identityManagementPersonDocument.getPrincipalId());
142 }
143 }
144
145 @Override
146 protected boolean setupPrincipal(IdentityManagementPersonDocument identityManagementPersonDocument,EntityBo kimEntity, List<PrincipalBo> origPrincipals) {
147 boolean inactivatingPrincipal = false;
148 List<PrincipalBo> principals = new ArrayList<PrincipalBo>();
149 Principal.Builder principal = Principal.Builder.create(identityManagementPersonDocument.getPrincipalName());
150 principal.setPrincipalId(identityManagementPersonDocument.getPrincipalId());
151
152 principal.setActive(identityManagementPersonDocument.isActive());
153 principal.setEntityId(identityManagementPersonDocument.getEntityId());
154 if(KRADUtils.isNotNull(origPrincipals)){
155 for (PrincipalBo prncpl : origPrincipals) {
156 if (prncpl.getPrincipalId()!=null && StringUtils.equals(prncpl.getPrincipalId(), principal.getPrincipalId())) {
157 principal.setVersionNumber(prncpl.getVersionNumber());
158 principal.setObjectId(prncpl.getObjectId());
159
160 if ( prncpl.isActive() && !principal.isActive() ) {
161 inactivatingPrincipal = true;
162 }
163 }
164 }
165 }
166 principals.add(PrincipalBo.from(principal.build()));
167
168 kimEntity.setPrincipals(principals);
169 return inactivatingPrincipal;
170 }
171
172 @Override
173 protected List<PersonDocumentAffiliation> loadAffiliations(List <EntityAffiliation> affiliations, List<EntityEmployment> empInfos) {
174 List<PersonDocumentAffiliation> docAffiliations = new ArrayList<PersonDocumentAffiliation>();
175 if(KRADUtils.isNotNull(affiliations)){
176 for (EntityAffiliation affiliation: affiliations) {
177 if(affiliation.isActive()){
178 PersonDocumentAffiliation docAffiliation = new PersonDocumentAffiliation();
179 docAffiliation.setAffiliationTypeCode(affiliation.getAffiliationType().getCode());
180 docAffiliation.setCampusCode(affiliation.getCampusCode());
181 docAffiliation.setActive(affiliation.isActive());
182 docAffiliation.setDflt(affiliation.isDefaultValue());
183 docAffiliation.setEntityAffiliationId(affiliation.getId());
184 docAffiliation.refreshReferenceObject("affiliationType");
185
186 docAffiliations.add(docAffiliation);
187 docAffiliation.setEdit(true);
188
189 List<PersonDocumentEmploymentInfo> docEmploymentInformations = new ArrayList<PersonDocumentEmploymentInfo>();
190 if(KRADUtils.isNotNull(empInfos)){
191 for (EntityEmployment empInfo: empInfos) {
192 if (empInfo.isActive()
193 && StringUtils.equals(docAffiliation.getEntityAffiliationId(),
194 (empInfo.getEntityAffiliation() != null ? empInfo.getEntityAffiliation().getId() : null))) {
195 PersonDocumentEmploymentInfo docEmpInfo = new PersonDocumentEmploymentInfo();
196 docEmpInfo.setEntityEmploymentId(empInfo.getEmployeeId());
197 docEmpInfo.setEmployeeId(empInfo.getEmployeeId());
198 docEmpInfo.setEmploymentRecordId(empInfo.getEmploymentRecordId());
199 docEmpInfo.setBaseSalaryAmount(empInfo.getBaseSalaryAmount());
200 docEmpInfo.setPrimaryDepartmentCode(empInfo.getPrimaryDepartmentCode());
201 docEmpInfo.setEmploymentStatusCode(empInfo.getEmployeeStatus() != null ? empInfo.getEmployeeStatus().getCode() : null);
202 docEmpInfo.setEmploymentTypeCode(empInfo.getEmployeeType() != null ? empInfo.getEmployeeType().getCode() : null);
203 docEmpInfo.setActive(empInfo.isActive());
204 docEmpInfo.setPrimary(empInfo.isPrimary());
205 docEmpInfo.setEntityAffiliationId(empInfo.getEntityAffiliation() != null ? empInfo.getEntityAffiliation().getId() : null);
206
207
208 docEmpInfo.setEdit(true);
209 docEmpInfo.refreshReferenceObject("employmentType");
210 docEmploymentInformations.add(docEmpInfo);
211 }
212 }
213 }
214 docAffiliation.setEmpInfos(docEmploymentInformations);
215 }
216 }
217 }
218 return docAffiliations;
219
220 }
221
222
223 @Override
224 protected List<PersonDocumentName> loadNames( IdentityManagementPersonDocument personDoc, String principalId, List <EntityName> names, boolean suppressDisplay ) {
225 List<PersonDocumentName> docNames = new ArrayList<PersonDocumentName>();
226 if(KRADUtils.isNotNull(names)){
227 for (EntityName name: names) {
228 if(name.isActive()){
229 PersonDocumentName docName = new PersonDocumentName();
230 if (name.getNameType() != null) {
231 docName.setNameCode(name.getNameType().getCode());
232 }
233
234
235 docName.setFirstName(name.getFirstNameUnmasked());
236 docName.setLastName(name.getLastNameUnmasked());
237 docName.setMiddleName(name.getMiddleNameUnmasked());
238 docName.setNamePrefix(name.getNamePrefixUnmasked());
239 docName.setNameSuffix(name.getNameSuffixUnmasked());
240
241 docName.setActive(name.isActive());
242 docName.setDflt(name.isDefaultValue());
243 docName.setEdit(true);
244 docName.setEntityNameId(name.getId());
245 docNames.add(docName);
246 }
247 }
248 }
249 return docNames;
250 }
251
252 @Override
253 protected List<PersonDocumentEmail> loadEmails(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId, List<EntityEmail> entityEmails, boolean suppressDisplay ) {
254 List<PersonDocumentEmail> emails = new ArrayList<PersonDocumentEmail>();
255 if(KRADUtils.isNotNull(entityEmails)){
256 for (EntityEmail email: entityEmails) {
257 if(email.isActive()){
258 PersonDocumentEmail docEmail = new PersonDocumentEmail();
259
260 docEmail.setEntityTypeCode(email.getEntityTypeCode());
261 if (email.getEmailType() != null) {
262 docEmail.setEmailTypeCode(email.getEmailType().getCode());
263 }
264
265
266
267 docEmail.setEmailAddress(email.getEmailAddressUnmasked());
268
269 docEmail.setActive(email.isActive());
270 docEmail.setDflt(email.isDefaultValue());
271 docEmail.setEntityEmailId(email.getId());
272 docEmail.setEdit(true);
273 emails.add(docEmail);
274 }
275 }
276 }
277 return emails;
278 }
279
280 @Override
281 protected List<PersonDocumentPhone> loadPhones(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId, List<EntityPhone> entityPhones, boolean suppressDisplay ) {
282 List<PersonDocumentPhone> docPhones = new ArrayList<PersonDocumentPhone>();
283 if(KRADUtils.isNotNull(entityPhones)){
284 for (EntityPhone phone: entityPhones) {
285 if(phone.isActive()){
286 PersonDocumentPhone docPhone = new PersonDocumentPhone();
287 if (phone.getPhoneType() != null) {
288 docPhone.setPhoneTypeCode(phone.getPhoneType().getCode());
289 }
290
291 docPhone.setEntityTypeCode(phone.getEntityTypeCode());
292
293 docPhone.setPhoneNumber(phone.getPhoneNumberUnmasked());
294 docPhone.setCountryCode(phone.getCountryCodeUnmasked());
295 docPhone.setExtensionNumber(phone.getExtensionNumberUnmasked());
296
297 docPhone.setActive(phone.isActive());
298 docPhone.setDflt(phone.isDefaultValue());
299 docPhone.setEntityPhoneId(phone.getId());
300 docPhone.setEdit(true);
301 docPhones.add(docPhone);
302 }
303 }
304 }
305 return docPhones;
306
307 }
308
309 public Object getMember(String memberTypeCode, String memberId){
310 Class<? extends Object> roleMemberTypeClass = null;
311 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)){
312 roleMemberTypeClass = PrincipalBo.class;
313 Principal principalInfo = getIdentityService().getPrincipal(memberId);
314 if (principalInfo != null) {
315
316 }
317 } else if(MemberType.GROUP.getCode().equals(memberTypeCode)){
318 roleMemberTypeClass = GroupBo.class;
319 Group groupInfo = null;
320 groupInfo = getGroupService().getGroup(memberId);
321 if (groupInfo != null) {
322
323 }
324 } else if(MemberType.ROLE.getCode().equals(memberTypeCode)){
325 roleMemberTypeClass = RoleBo.class;
326 Role role = getRoleService().getRole(memberId);
327 if (role != null) {
328
329 }
330 }
331 return getDataObjectService().find(roleMemberTypeClass, memberId);
332 }
333
334
335
336
337
338
339 @Override
340 public boolean canModifyEntity( String currentUserPrincipalId, String toModifyPrincipalId ){
341 return (StringUtils.isNotBlank(currentUserPrincipalId) && StringUtils.isNotBlank(toModifyPrincipalId) &&
342 currentUserPrincipalId.equals(toModifyPrincipalId)) ||
343 getPermissionService().isAuthorized(
344 currentUserPrincipalId,
345 KimConstants.NAMESPACE_CODE,
346 KimConstants.PermissionNames.MODIFY_ENTITY,
347 Collections.singletonMap(KimConstants.AttributeConstants.PRINCIPAL_ID, currentUserPrincipalId));
348 }
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402 }