1 package net.sf.provisioner.utils; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import javax.naming.directory.Attribute; 7 import javax.naming.directory.BasicAttribute; 8 import javax.naming.directory.BasicAttributes; 9 10 public class LDAPUtils { 11 12 public static BasicAttributes buildAttrs(String className, Map<String, Object> attrs) { 13 return buildAttrs( 14 new String[] { className }, 15 attrs 16 ); 17 } 18 19 public static BasicAttributes buildAttrs(String className, String attrName, Object attrValue) { 20 Map<String, Object> attrs = new HashMap<String, Object>(1); 21 attrs.put(attrName, attrValue); 22 23 return buildAttrs(className, attrs); 24 } 25 26 public static BasicAttributes buildAttrs(String[] classNames, Map<String, Object> attrs) { 27 BasicAttributes result = new BasicAttributes(); 28 Attribute classes = new BasicAttribute("objectClass"); 29 classes.add("top"); 30 for (String className : classNames) { 31 if (className.equals("top")) continue; 32 classes.add(className); 33 } 34 result.put(classes); 35 36 for (String key : attrs.keySet()) { 37 result.put(key, attrs.get(key)); 38 } 39 return result; 40 } 41 42 }