]> git.argeo.org Git - lgpl/argeo-commons.git/blob - nature/SimpleUserNatureMapper.java
Prepare next development cycle
[lgpl/argeo-commons.git] / nature / SimpleUserNatureMapper.java
1 package org.argeo.security.ldap.nature;
2
3 import org.argeo.security.UserNature;
4 import org.argeo.security.ldap.UserNatureMapper;
5 import org.argeo.security.nature.SimpleUserNature;
6 import org.springframework.ldap.core.DirContextAdapter;
7 import org.springframework.ldap.core.DirContextOperations;
8
9 public class SimpleUserNatureMapper implements UserNatureMapper {
10
11 public UserNature mapUserInfoFromContext(DirContextOperations ctx) {
12 SimpleUserNature nature = new SimpleUserNature();
13 nature.setLastName(ctx.getStringAttribute("sn"));
14 nature.setFirstName(ctx.getStringAttribute("givenName"));
15 nature.setEmail(ctx.getStringAttribute("mail"));
16 nature.setDescription(ctx.getStringAttribute("description"));
17 return nature;
18 }
19
20 public void mapUserInfoToContext(UserNature userInfoArg,
21 DirContextAdapter ctx) {
22 SimpleUserNature nature = (SimpleUserNature) userInfoArg;
23 ctx.setAttributeValue("cn", nature.getFirstName() + " "
24 + nature.getLastName());
25 ctx.setAttributeValue("sn", nature.getLastName());
26 ctx.setAttributeValue("givenName", nature.getFirstName());
27 ctx.setAttributeValue("mail", nature.getEmail());
28 if (nature.getDescription() != null) {
29 ctx.setAttributeValue("description", nature.getDescription());
30 }
31 }
32
33 public Boolean supports(UserNature userNature) {
34 return userNature instanceof SimpleUserNature;
35 }
36
37 }