]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/nature/SimpleUserNatureMapper.java
Restructure security
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / ldap / 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 basicUserInfo = new SimpleUserNature();
13 basicUserInfo.setLastName(ctx.getStringAttribute("sn"));
14 basicUserInfo.setFirstName(ctx.getStringAttribute("givenName"));
15 basicUserInfo.setEmail(ctx.getStringAttribute("mail"));
16 basicUserInfo.setUuid(ctx.getStringAttribute("seeAlso"));
17 return basicUserInfo;
18 }
19
20 public void mapUserInfoToContext(UserNature userInfoArg,
21 DirContextAdapter ctx) {
22 SimpleUserNature userInfo = (SimpleUserNature) userInfoArg;
23 ctx.setAttributeValue("cn", userInfo.getFirstName() + " "
24 + userInfo.getLastName());
25 ctx.setAttributeValue("sn", userInfo.getLastName());
26 ctx.setAttributeValue("givenName", userInfo.getFirstName());
27 ctx.setAttributeValue("mail", userInfo.getEmail());
28 // TODO: find a cleaner way?
29 ctx.setAttributeValue("seeAlso", userInfo.getUuid());
30 }
31
32 public Boolean supports(UserNature userInfo) {
33 return userInfo instanceof SimpleUserNature;
34 }
35
36 }