go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Entry MUST NOT exist for the AddRequest to succeed.
 
Subject: Entry MUST NOT exist for the AddRequest to succeed.
Author: eLDAP
In response to: I am unable to add an entry, what is wrong with the code.
Posted on: 05/27/2009 01:05:45 PM

Hi singularity,

Next time when you post source code you can wrap it with [code] ... [/code] so that it appears more readiable.

Could you please post your error messages thrown from the exception? But for the code you given, the problem is obvious: the entry "cn=Manager,dc=test,dc=com" you tried to add was already there.

Regards,
eLDAP



 

> On 05/25/2009 07:27:49 AM singularity wrote:


import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;

public class JNDI_Add {
public static void main(String args[]) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/cn=Manager,dc=test,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=test,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "openldap");
try {
//create an initial context
DirContext ctx = new InitialDirContext(env);
//Th distinguished name of the new entry
String dn = "cn=Manager,dc=test,dc=com";
//create an attribute to be associated with this new entry
Attributes attrs = new BasicAttributes(true);
//ObjectClass Required in must List
Attribute oc = new BasicAttribute("objectClass"); //required by top
oc.add("top");
oc.add("person");
oc.add("inetOrgPerson");
attrs.put(oc);
//Other Mandatory Attributes
attrs.put("cn", "Manager"); //required by Person
attrs.put("sn", "Smith2"); //required by person
//optional Attributes
attrs.put("mail","jsmith2@test.com");
//Create the Context
Context result = ctx.createSubcontext(dn, attrs);
//Close the context when we are done
result.close();
ctx.close();

} catch (NamingException e) {
e.printStackTrace();
}
}

}




References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.