• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HOW TO ADD LDAP ENTRIES USING JNDI?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i am running OpenLDAP server and i wish to add CN to DC=webselfcare,DC=com. And this i wish to do it from a JNDI Java Program. I am able to read entries from the LDAP server using simple authentication. Now i wish to add and update entries to it, how do i do this??
regards
suneel
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this with IPlanet LDAP long back. Just see if it works for you.

 
suneel suresh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks karthik
i shall run it and let you know.
regards
suneel
 
suneel suresh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
karthik i ran the code you gave me but i am getting the following error:Here is my Stdout
Context Sucessfully Initialized
javax.naming.OperationNotSupportedException: [LDAP: error code 53 - referral missing]; remaining name 'uid=defaultuser'
And here is my code:
/*
* Created on Dec 8, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author root
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.NamingException;
import java.util.Hashtable;

public class LdapExampleAdd {
public static void main(String[] args)
{

//Identify service provider to use
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "dc=webselfcare, dc=com");
env.put(Context.SECURITY_CREDENTIALS, "takecare");
try
{
// Create the initial directory context
InitialDirContext initialContext = new InitialDirContext(env);
DirContext dCtx = (DirContext)initialContext;

System.out.println("Context Sucessfully Initialized");


Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute("uid", "defaultuser"));
matchAttrs.put(new BasicAttribute("cn", "defaultuser"));
matchAttrs.put(new BasicAttribute("givenname", "defaultuser"));
matchAttrs.put(new BasicAttribute("sn", "defaultuser"));
matchAttrs.put(new BasicAttribute("userpassword", "password"));
matchAttrs.put(new BasicAttribute("objectclass", "top"));
matchAttrs.put(new BasicAttribute("objectclass", "person"));
matchAttrs.put(new BasicAttribute("objectclass", "organizationalPerson"));
matchAttrs.put(new BasicAttribute("objectclass","inetorgperson"));
String name="uid=defaultuser";

InitialDirContext iniDirContext = (InitialDirContext)dCtx;
iniDirContext.bind(name,dCtx,matchAttrs);

iniDirContext.close();
dCtx.close();
}
catch (NamingException ne)
{
System.err.println(ne);
}
catch(Exception e)
{
System.err.println(e);
}
}
}

Whats wrong here karthik?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suneel, I have a solution to your problem.

I don't know if you have figured this out already but I was having the same problem and I found this poast on Google. I figured out what was wrong and felt i should share =D

The problem is occuring because your LDAP server does not know where to put the new entity. Your string String name="uid=defaultuser" is specifying the DN of the new entry. This DN must be suffixed by the full path to where the entry resides, including and DC entries used in your LDAP server's suffix.

For example, if your suffix is "dc=something,dc=com", and you have created one organization unit with the DN of "ou=users,dc=something,dc=com", you must specify the full DN of your new entry as "uid=defaultuser,ou=users,dc=something,dc=com".

I ran across this problem because I had mistyped the suffix in my DN string =$. I looked up what the error meant from an LDAP perspective and it is related to when you are adding an entry to a slave LDAP server and have not specified an LDAP server to refer to for the rest of the information regarding the suffix you specified.

I hope that this helps you. Good Luck!

-- Thaddeus
 
mod_critical
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, that post was December 2003. Well, I hope this helps someone then =D
 
suneel suresh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks for ur message although its a few years later! but i am no longer working...am doing my masters! thanks again
[ March 23, 2005: Message edited by: suneel suresh ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all
i have a similar problem
I am having a servlet in which i wanted to call the class which is adding the entries to the ldap server.my questions are:

1. will i have to create a directory externally or the code which adds will
add itself to the default directory

2. shall i use jndi or normal java class that authenticates and adds is ok

3. if the entry of the user keeps on logging on and off should i every time create entry and authenticate or i should maintain a database

4. which server would be good to run on windows platform

thanks
Monarch
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi can any one send reply for Monarch Bhojani question i too have same doubts

thanks
pramu
 
Oh the stink of it! Smell my tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic