]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - 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
diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/nature/SimpleUserNatureMapper.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/ldap/nature/SimpleUserNatureMapper.java
new file mode 100644 (file)
index 0000000..3bc4b51
--- /dev/null
@@ -0,0 +1,36 @@
+package org.argeo.security.ldap.nature;
+
+import org.argeo.security.UserNature;
+import org.argeo.security.ldap.UserNatureMapper;
+import org.argeo.security.nature.SimpleUserNature;
+import org.springframework.ldap.core.DirContextAdapter;
+import org.springframework.ldap.core.DirContextOperations;
+
+public class SimpleUserNatureMapper implements UserNatureMapper {
+
+       public UserNature mapUserInfoFromContext(DirContextOperations ctx) {
+               SimpleUserNature basicUserInfo = new SimpleUserNature();
+               basicUserInfo.setLastName(ctx.getStringAttribute("sn"));
+               basicUserInfo.setFirstName(ctx.getStringAttribute("givenName"));
+               basicUserInfo.setEmail(ctx.getStringAttribute("mail"));
+               basicUserInfo.setUuid(ctx.getStringAttribute("seeAlso"));
+               return basicUserInfo;
+       }
+
+       public void mapUserInfoToContext(UserNature userInfoArg,
+                       DirContextAdapter ctx) {
+               SimpleUserNature userInfo = (SimpleUserNature) userInfoArg;
+               ctx.setAttributeValue("cn", userInfo.getFirstName() + " "
+                               + userInfo.getLastName());
+               ctx.setAttributeValue("sn", userInfo.getLastName());
+               ctx.setAttributeValue("givenName", userInfo.getFirstName());
+               ctx.setAttributeValue("mail", userInfo.getEmail());
+               // TODO: find a cleaner way?
+               ctx.setAttributeValue("seeAlso", userInfo.getUuid());
+       }
+
+       public Boolean supports(UserNature userInfo) {
+               return userInfo instanceof SimpleUserNature;
+       }
+
+}