I Can't create and add en entry in Ldap using Java

Hello there,
I'm pretty new to LDAP programming, and I have been trying to create and add an entry to a directory using the code sample provided in the JNDI tutorial, but for some reasons, I didn't manage.
the configuration file is well set up because I can't create, add, delete and modify just about anything I want from openLDAP command lines, but my real problem is to do it with java.
here is my code:
import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
import javax.net.ssl.*;
import java.io.*;
public class Newuser
     public static void main (String[] args)
          //LDAPEntry myEntry = new LDAPEntry();
          Hashtable<String, String> env = new Hashtable<String, String>(11);
          String adminName = "CN=ldap_admin,o=JNDITutorial,dc=img,dc=org";
          String adminPassword = "xxxxxx";
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          //set security credentials, note using simple cleartext authentication
          env.put(Context.SECURITY_AUTHENTICATION,"simple");
          env.put(Context.SECURITY_PRINCIPAL,adminName);
          env.put(Context.SECURITY_CREDENTIALS,adminPassword);
          //connect to my domain controller
          env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial,dc=img,dc=org");
               // Create the initial directory context
               //JNDILDAPConnectionManager jndiManager = new JNDILDAPConnectionManagerImpl();
              try{
                   DirContext ctx = new InitialDirContext(env);
                    System.out.println("Connection to LDAP server done" );
                   final String groupDN ="ou=people,o=JNDITutorial,dc=img,dc=org";
                  //DirContext dirCtx = jndiManager.getLDAPDirContext();
                  People people = new People("Thiru","Thiru","Thiru Ganesh","Ramalingam","ou=people","[email protected]");
                  // The Common name must be equal in Attributes common Name
                  ctx.bind("cn=Thiru," + groupDN, people);
                  System.out.println("** Entry added **");
                  //jndiManager.disConnectLDAPConnection(ctx);
              }catch(NamingException exception){
                  System.out.println("**** Error ****");
                  exception.printStackTrace();
                  System.exit(0);
}adn this is the class People that i want to instantiate
import java.util.Hashtable;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.*;
public class People implements DirContext {
     public People(String uid,String cn,String givenname,String sn,String ou,String mail) {
    BasicAttributes myAttrs = new BasicAttributes(true);  //Basic Attributes
    Attribute objectClass = new BasicAttribute("objectclass"); //Adding Object Classes
    objectClass.add("inetOrgPerson");
    /*objectClass.add("organizationalPerson");
    objectClass.add("person");
    objectClass.add("top");*/
    Attribute ouSet = new BasicAttribute("ou");
    ouSet.add("people");
    ouSet.add(ou);
    myAttrs.put(objectClass);
    myAttrs.put(ouSet);
    myAttrs.put("cn",cn);
    myAttrs.put("sn",sn);
    myAttrs.put("mail",mail);
}as I said, I can add the new entry using an LDIF file "new.txt" that looks like this:
dn:cn=Hamido Saddo,ou=People,o=JNDITutorial,dc=img,dc=org
cn:Hamido Saddo
mail:[email protected]
telephonenumber:3838393038703
sn:hamido
objectclass:top
objectclass:person
objectclass:organizationalPerson
objectclass:inetOrgPersonusing the following command:
ldapadd -D "cn=ldap_admin,o=JNDITutorial,dc=org,dc=img" -W -f new.txtand eveything works
but when i try with the java, i get the following error:
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - entry has no objectClass attribute]
so, can anyone help me please !!!

uncomment these lines
/*objectClass.add("organizationalPerson");
objectClass.add("person");
objectClass.add("top");*/
you need all of them to add successfully
your LDIF has all the four lines
objectclass:top
objectclass:person
objectclass:organizationalPerson
objectclass:inetOrgPerson
hope this helps

Similar Messages

  • Can I create MS-Word files or PDF files using java

    We are developnig a web based application for banks and in this at some point we need to provide reports to the Banks for downloading and printing . Now I do not want to make simple .txt files ,I wan to use some sophsticated file format which look nice.
    So is it possible for the server to create files in say .doc format or in say PDF format etc which the banks may download and print.
    I am using java servlets and jsp as front end and java classes in middle tier and oracle is my database.

    Please try this code:
    import god.java.pdf.*;
    PDFWriter pw=new PDFWriter(new OutputFile(new String("sample.pdf")));
    pw.print("This is your text.");
    pw.close();

  • Can I create and add my own customized attribute in Org.Model?

    Hi,
    I have a question on Org.Model. If I have to add my own attribute in the 'Attributes' tab, how can I add one.
    My scenario is like this:
    We are using the std Org determination based on employee responsible. But an employee may exist in more than one position in the CRM Org.structure. The ideal scenario would be to have the Org Determination talking place with a combination of Employee Responsible and the Store(customized) partner function.
    Please see what guidance you experts can give me. Points will be generous.
    Thanks,
    John

    Hi Fredrick,
    I dont think this should be a problem as when a user is assigned to two different org units, and when you are using the rule based to determine org based on the user (standard rule 10000194), the system will pop up to select the relevant org (it will pop up both org units where the user is assigned) and you need to select one that is relevant to you.
    This pop comes in transactions when you enter the employee responsible and if the org data profile is assigned to the transaction type.
    Hope this clarifies as per my undersatnding of your requirement and reward points if useful.
    Srini

  • Cannot create and add a new entry to LDAP

    Hi,
    I'm pretty new at LDAP and JNDI, i've been trying to create and add a new entry to the directory but somehow it's not working.
    here is my code and I would appreciate it if someone can help.
    import java.util.Hashtable;
    import javax.naming.ldap.*;
    import javax.naming.directory.*;
    import javax.naming.*;
    import javax.net.ssl.*;
    import java.io.*;
    public class Newuser
         public static void main (String[] args)
              //LDAPEntry myEntry = new LDAPEntry();
              Hashtable<String, String> env = new Hashtable<String, String>(11);
              String adminName = "CN=ldap_admin,o=JNDITutorial,dc=img,dc=org";
              String adminPassword = "secret";
              env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
              //set security credentials, note using simple cleartext authentication
              env.put(Context.SECURITY_AUTHENTICATION,"simple");
              env.put(Context.SECURITY_PRINCIPAL,adminName);
              env.put(Context.SECURITY_CREDENTIALS,adminPassword);
              //connect to my domain controller
              env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial,dc=img,dc=org");
                   // Create the initial directory context
                   //JNDILDAPConnectionManager jndiManager = new JNDILDAPConnectionManagerImpl();
                  try{
                       DirContext ctx = new InitialDirContext(env);
                        System.out.println("Connection to LDAP server done" );
                       final String groupDN ="ou=people,o=JNDITutorial,dc=img,dc=org";
                      //DirContext dirCtx = jndiManager.getLDAPDirContext();
                      People people = new People("Thiru","Thiru","Thiru Ganesh","Ramalingam","ou=people","[email protected]");
                      // The Common name must be equal in Attributes common Name
                      ctx.bind("cn=Thiru," + groupDN, people);
                      System.out.println("** Entry added **");
                      //jndiManager.disConnectLDAPConnection(ctx);
                  }catch(NamingException exception){
                      System.out.println("**** Error ****");
                      exception.printStackTrace();
                      System.exit(0);
    }here is the Object class People that i'm trying to instantiate
    public class People implements DirContext {
         public People(String uid,String cn,String givenname,String sn,String ou,String mail) {
        BasicAttributes myAttrs = new BasicAttributes(true);  //Basic Attributes
        Attribute objectClass = new BasicAttribute("objectclass"); //Adding Object Classes
        objectClass.add("inetOrgPerson");
        /*objectClass.add("organizationalPerson");
        objectClass.add("person");
        objectClass.add("top");*/
        Attribute ouSet = new BasicAttribute("ou");
        ouSet.add("people");
        ouSet.add(ou);
        myAttrs.put(objectClass);
        myAttrs.put(ouSet);
        myAttrs.put("cn",cn);
        myAttrs.put("sn",sn);
        myAttrs.put("mail",mail);
    ...the message i keep getting is:
    javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - entry has no objectClass attribute]
    the thing is that I can create and add a new entry in openLDAP from the console and it works.
    and here is how I proceed
    I create a text file: new.txt
    dn:cn=Hamido Saddo,ou=People,o=JNDITutorial,dc=img,dc=org
    cn:Hamido Saddo
    mail:[email protected]
    telephonenumber:3838393038703
    sn:hamdio
    objectclass:top
    objectclass:person
    objectclass:organizationalPerson
    objectclass:inetOrgPersonand i use this command to add the entry:
    ldapadd -D "cn=ldap_admin,O=JNDITutorial,dc=img,dc=org" -W -f new.txtand everything works, i get no errors.
    does anyone has a clue maybe???

    You must have an IMAP email account in order to add additional folders on the iPad mail app.
    If you go to your email account in the Mail app and look at the window where your inbox, trash folder and sent folder are - if there is an Edit button at the top of the window - tap that and then tap Add Mailbox at the bottom.
    If the Edit button is not there - you cannot create folders on the iPad. Your email account is not IMAP. Only IMAP email accounts can create folders on the iPad. Any folders that you would already have in an IMAP account would sync to the device as well.

  • Can I create and manage collections in itunes instead of on the ipad?

    Can I create and manage collections in itunes instead of on the ipad? I have hundreds (maybe thousands) of PDF files for technical work items that I need to categorize and use on my ipad but it is a bit cumbersome to manually move them one at a time on the ipad.

    While you can add pdf files to iTunes it is not really intended to be used for organizing things other than a music collection.  It will only accept PDF files and media (audio, movie) files.  On the other hand if you can creatively come up with a way to make it work for you then go for it.

  • Can I create and use more than one repository on OVM 2.1.5

    The version of Oracle VM I am using is 2.1.5 .
    I wonder can I create and use more than one repository on OVM 2.1.5. Because I want to install different GOS on different disks.
    I know in Oracle VM 2.2 we can use following commands to realize that.
    a. #/opt/ovs-agent-2.3/utils/repos.py –n /dev/mapper/mpathxp1
    b. #/opt/ovs-agent-2.3/utils/repos.py –r UUID
    c. #/opt/ovs-agent-2.3/utils/repos.py –i
    And other repositories can also be mounted and found under /var/ovs/mount/UUID.
    But in Oracle VM 2.1.5, seems just one repository can be created and mounted. For example:
    At first, I create a repository using mpath1p1:
    a. # mkfs.ocfs2 /dev/mapper/mpath1p1
    b. #/usr/lib/ovs/ovs-makerepo /dev/mapper/mpath1p1 C "cluster root"
    c. I can find the repository has been mounted under /OVS.
    But if I want to use "/usr/lib/ovs/ovs-makerepo /dev/mapper/mpath2p1 C "cluster root" to create another repository, and check the mount status using command "mount", these two disks are all have been mounted under /OVS.
    "# cat /etc/ovs/repositories", only mpath1p1 with UUID was recorded there.
    After reboot, only repository with mpath1p1 was mounted under OVS.
    Can anyone tell me how to use more than one repositories on OVM 2.1.5. Do I have to install all the GOSs on the same disk and repository.
    Thank you very much.

    Now I've known how to create different repository. They will be mounted under /OVS/UUID. Thanks.

  • HT201441 how can i create and audio cd from a music track I have on my ipod

    how can i create and audio cd from a music track I have on my ipod

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • Can I create and order photo book using iPhoto in UAE?

    Hello,
    Curretly I'm in UAE, Dubai. Can I create and order a phto book using iPhoto and get it in my Dubai or Abu Dhabi address?
    Regards

    The list of countries, where apple print products are available, is here:
    http://store.apple.com/us/help/print_products/routing
    I don't see UAE, sorry, but better check yourself.
    Regards
    Léonie

  • How to create and add table type to a DDIC Structure in sap 3.1H

    How to create and add table type to a DDIC Structure in sap 3.1H

    How to create and add table type to a DDIC Structure in sap 3.1H

  • Can you create and print a hard cover photo album on iPhoto when you only have a iPad,  can someone please help.  Did not see the option to print.

    I am trying to create and print a hard cover photobook using iPhoto on my iPad, can this be done?  Did not see the option.  Can someone please help?

    It can't be done on the iPad using iPhoto for iOS.  You need to use iPhoto for the Mac.

  • I downloaded the Acrobat 11 trial and  I can open the product. During the install it deleted the existing print driver and did not install a new print driver so I CAN Not create and print pdf files.

    I downloaded the Acrobat 11 trial and  I can open the product. During the install it deleted the existing print driver and did not install a new print driver so I CAN Not create and print pdf files.

    What OS? Have you tried a repair and updates from the HELP menu? The updates may be the key.

  • I have an early model MacBook Air purchased 2008 with a removable back casing can I purchase and add an additional 2 GB of memory?

    I have an early model MacBook Air purchased 2008 with a removable back casing. Can I purchase and add an additional 2 GB of memory?

    Whether you open it or not, is completely irrelevant to the question.
    All Macbook Airs have memory that is permanently soldered to the logic board, and there are no expansion slots. Hence, no Macbook Air may be upgraded from the memory configuration it had when it was manufactured.
    Your system came with 2 Gb, it will always have only 2 Gb.

  • How to accessed,created and modified date of particular file in java

    Hi,
    I am facing one problem.
    I know how to get the modified date/time of file in java.
    but i don't know how to find created and accessed date/time of file in java.
    Thanks,
    Tejas

    I guess thats not possible in in Windows.
    But if u r trying it on a unix machine.
    You can use Runtime class to call exec on the command
    ls -l filename
    and then store the result in a file . And then take out the last modified time. But you cant get created time.
    Thats a clumpsy way i believe.

  • Can't Drag and Drop with a Double Tap using Single Finger in Lion?

    I installed the Mac OS X Lion two days. But I can't drag and drop with a Double tap using Single Finger, which I used to do in Snow Leopard.
    If I choose Three Finger Move, then Swap Between Pages goes back to "Scroll left or right with Two Fingers" that only works with Safari, but doesn't work with Chrome or Firefox.
    I tried literally every setting in Trackpad and also checked if there was a override settings and there is no overrride setting.
    Would be thankful, if you guys could suggest me what to do?
    ======================================
    My Machine Configuration:
    Macbook Pro 13" (mid 2010)
    Intel Core 2 Duo 2.4GHz
    4GB Ram
    Nvidia Geforce 320m
    Mac OS X Lion (Installe on a updated Snow Leopard 10.6.8)

    Hey Serge many thanks for telling me how to do. now its working like previously
    I just cheked the Dragging under Trackpad option and unchecked Three Finger Moves. now I can drag and drop with a double tap using single finger.
    Thank you guys. You are the best

  • Apple should make a macBook where the screen can turn around and become touch screen, for easier use

    Apple should make a macBook where the screen can turn around and become touch screen, for easier use. especially for when i go to uni

    Why touch and swivel screens arent a good idea on a laptop:
    The so-called Gorilla arm: Gorilla arm is a term describing the tired arms users get after reaching out and touching a screen for a long time.
    Added thickness: Touch screen panels are usually thicker than non-touch ones—especially if the touch panel has an active digitizer for pen support.
    Possibly shorter battery life: Touch screens require more power. Laptop Magazine compared a couple of touch screen laptops with their non-touch counterparts (same model and size) and found that the non-touch laptops lasted over an hour longer.
    Easy to break: Swivel screens are notoriously prone to break, especially the hinge and the cable that feeds the screen from the logic board which is being constantly twisted.
    And thats what the Ipad is for.

Maybe you are looking for

  • IMac Leopard Hard Drive--who knows what's the problem

    Alright, this all started last night. I downloaded some P2P programs and was downloading a few large files. I should have thought something was wrong when I got a message saying my start-up disk was too full and I needed to delete files. I figured I

  • Is fix 6345743  part of current JVM builds

    I am running into issues that are similar as reported in bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6345743 is there a public build that has a fix for this issue? (it doesn't seem to be part of update 6

  • Cancelling online number but want call forwarding

    Hi, I have a Skype online number that is about to expire. I don't really need this number anymore, so I don't want to renew my subscription. However, I don't want someone calling the number I used to have and receving a "this number does not exist."

  • Download and Play videos

    I am attempting to build a video player that can play files we store on amazon s3, but also download them to play when offline. When a user selects a video, I would like to have the video start downloading to an app directory and immediately have FLV

  • Flash gone wrong...

    Hi all, probably did something stupid here but I'm in need of a point in the right direction. AMD 2600+ MSI K7N2 Delta-L 1x512 Kingsoton Value Ram KV$400X64C25/512 Saphire Radeon 9600 SE 400W PSU +3.3V/28A | +5V/30A | +12V/11A | -12V/0.8A | +5SB/3A 8