File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to add a user in the Active Directory via JNDI/LDAP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to add a user in the Active Directory via JNDI/LDAP?" Watch "How to add a user in the Active Directory via JNDI/LDAP?" New topic
Author

How to add a user in the Active Directory via JNDI/LDAP?

Fansy Zjy
Greenhorn

Joined: Feb 05, 2002
Posts: 2
HI all,
I am puzzled how to add a user in AD,please show your hands?
Server : Win2k Advanced Server,Active Directory,Exchange Server 2000
Client : jdk1.4
I access AD via JNDI/LDAP to add an entry,and the codes as below
public void addUser(){
/* Specify the DN we're adding */
String dn = "CN=test1,CN=Users,DC=acdemo,DC=com";
Attribute cn = new BasicAttribute("cn", "test1");
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("person");
objClasses.add("organizationalPerson");
objClasses.add("user");
Attribute instanceType = new BasicAttribute("instanceType", "4");
Attribute objectCategory = new BasicAttribute("objectCategory", "CN=Person,CN=Schema,CN=Configuration,DC=acdemo,DC=com");
......
Attributes orig = new BasicAttributes(true);
orig.put(objClasses);
orig.put(cn);
orig.put(instanceType);
orig.put(objectCategory);
......
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://172.16.251.212");
/* specify authentication information */
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=Administrator,CN=Users,DC=acdemo,DC=com");
env.put(Context.SECURITY_CREDENTIALS, "pass");//password
DirContext ctx = null;
try {
ctx = new InitialDirContext(env);
/* Add the entry */
ctx.createSubcontext(dn, orig);
}
catch (NamingException e) {
e.printStackTrace();
}
}
when I run,it throws the exception as below:
javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000209A: SvcErr: DSID-031A0929, problem 5003 (WILL_NOT_PERFORM), data 0
...
Anybody can help me?
I got points from SUN's forum that I should make a SSL connection between C/S,but may you show me a step-by-step guides?
Thanks in advance


Hello All!<br />SCJP & SCWCD
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Moving this to the Security forum.
Dave
 
 
subject: How to add a user in the Active Directory via JNDI/LDAP?
 
Similar Threads
Simple Add using JNDI
How to add a user in the Active Directory via JNDI/LDAP?
LDAP: Add Users
JNDI, LDAP, & Active Directory
Modifying an attribute in LDAP using JNDI