程序如下:
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;
import java.util.Hashtable;
import com.sun.jndi.ldap.*;class Create {
    public static void main(String args[]) {
     //set up the environment for creating the initial context
     Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, 
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, 
    "ldap://testserver:389/dc=test,dc=com");
env.put(Context.SECURITY_PROTOCOL,"SSL");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, args[0]);//管理员administrator
        env.put(Context.SECURITY_CREDENTIALS, args[1]);//密码   
     try {
         // Create the initial context
    DirContext ctx = new InitialDirContext(env);            
            Attributes attributes = new BasicAttributes(true);
            /*制定用户属性*/    
                    
            Attribute objectCategory = new BasicAttribute("objectCategory");
            objectCategory.add("CN=Person,CN=Schema,CN=Configuration,DC=test,DC=com");                                
            Attribute mail = new BasicAttribute("mail");
            mail.add("[email protected]");                       
            Attribute proxyAddresses = new BasicAttribute("proxyAddresses");
            proxyAddresses.add("SMTP:[email protected]");
            proxyAddresses.add("X400:c=us;a= ;p=First Organizati;o=Exchange;s=Smith;g=John;i=John;");                     
            
            //类别为用户
            Attribute objectClass = new BasicAttribute("objectClass");
            objectClass.add("top");
            objectClass.add("person");
            objectClass.add("organizationalPerson");
            objectClass.add("user");                         
            Attribute name = new BasicAttribute("name");
            name.add("John");
            Attribute userAccountControl = new BasicAttribute("userAccountControl","66048");            
            Attribute displayName = new BasicAttribute("displayName");
            displayName.add("John");            
            Attribute userPrincipalName = new BasicAttribute("userPrincipalName");
            userPrincipalName.add("[email protected]");            
            Attribute mailNickname = new BasicAttribute("mailNickname");
            mailNickname.add("John");            
            Attribute sAMAccountName = new BasicAttribute("sAMAccountName");
            sAMAccountName.add("John");                                    
            
            /*将属性填入*/            
            attributes.put(objectCategory);
            attributes.put(mail);            
            attributes.put(proxyAddresses);            
            attributes.put(objectClass);
            attributes.put(name);
            attributes.put(userAccountControl);
            attributes.put(displayName);
            attributes.put(userPrincipalName);
            attributes.put(mailNickname);
            attributes.put(sAMAccountName);
            Context result = ctx.createSubcontext("cn=john,cn=Users",attributes);
            //创建用户            
        } catch (Exception e) {
            e.printStackTrace(); 
        }
    }
}可能还有别的属性,就不追究了,但是密码肯定少不了啊,可是不知道和密码有关的属性是什么名称,运行程序后,用户设定了,可是密码却没有,看看了看MSDN的相关内容,
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/w2k2/DN_user.asp),也没找到很好的办法,有谁能帮我看一下, 谢谢!