1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.ldap;
17
18 import org.kuali.rice.kim.api.identity.name.EntityName;
19 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
20 import org.springframework.ldap.core.ContextMapper;
21 import org.springframework.ldap.core.DirContextOperations;
22
23 import javax.naming.NamingException;
24
25
26
27
28
29 public class EntityNamePrincipalNameMapper extends BaseMapper<EntityNamePrincipalName> {
30
31 private ContextMapper defaultNameMapper;
32
33 @Override
34 EntityNamePrincipalName mapDtoFromContext(DirContextOperations context) {
35 EntityNamePrincipalName.Builder builder = mapBuilderFromContext(context);
36 return builder != null ? builder.build() : null;
37 }
38
39 EntityNamePrincipalName.Builder mapBuilderFromContext(DirContextOperations context) {
40 final EntityNamePrincipalName.Builder person = EntityNamePrincipalName.Builder.create();
41
42 try {
43 person.setDefaultName((EntityName.Builder) getDefaultNameMapper().mapFromContext(context));
44 } catch (NamingException e) {
45 e.printStackTrace();
46 throw new RuntimeException(e.getMessage());
47 }
48
49 person.setPrincipalName(context.getStringAttribute(getConstants().getKimLdapNameProperty()));
50 return person;
51 }
52
53
54
55
56
57
58 public final ContextMapper getDefaultNameMapper() {
59 return this.defaultNameMapper;
60 }
61
62
63
64
65
66
67 public final void setDefaultNameMapper(final ContextMapper argDefaultNameMapper) {
68 this.defaultNameMapper = argDefaultNameMapper;
69 }
70 }