Improve user management
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / directory / ldap / LdapEntry.java
index 45788b93576ac0757643252aef9cd3080ca295a0..cf293cee2e94aa2ec6eda2312ae4aef2209a19ab 100644 (file)
@@ -1,11 +1,18 @@
 package org.argeo.util.directory.ldap;
 
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.List;
+import java.util.Set;
+import java.util.StringJoiner;
+import java.util.TreeSet;
 
 import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapName;
 
+import org.argeo.util.naming.LdapAttrs;
+
+/** An LDAP entry. */
 public interface LdapEntry {
        LdapName getDn();
 
@@ -13,10 +20,21 @@ public interface LdapEntry {
 
        void publishAttributes(Attributes modifiedAttributes);
 
-       public List<LdapName> getReferences(String attributeId);
-       
-       public Dictionary<String, Object> getProperties();
+       List<LdapName> getReferences(String attributeId);
+
+       Dictionary<String, Object> getProperties();
 
-       public boolean hasCredential(String key, Object value) ;
+       boolean hasCredential(String key, Object value);
 
+       /*
+        * UTILITIES
+        */
+       public static void addObjectClasses(Dictionary<String, Object> properties, Set<String> objectClasses) {
+               String value = properties.get(LdapAttrs.objectClasses.name()).toString();
+               Set<String> currentObjectClasses = new TreeSet<>(Arrays.asList(value.toString().split("\n")));
+               currentObjectClasses.addAll(objectClasses);
+               StringJoiner values = new StringJoiner("\n");
+               currentObjectClasses.forEach((s) -> values.add(s));
+               properties.put(LdapAttrs.objectClasses.name(), values.toString());
+       }
 }