13 Replies Latest reply: Aug 2, 2012 12:59 AM by 953167 RSS

    Create base dn using JNDI...

    953167
      Hi

      I want to create the base dn for OpenDJ LDAP using JNDI below is the code i am using for the same but it is thorwing me the error could any body help me to tell me where exactly i am doing wrong .

      public static String ldapUri = "ldap://169.144.104.75:389";
           public static String admindn = "cn=Directory Manager";
           public static String admincred = "redhat";
           
           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, ldapUri);
                env.put( Context.SECURITY_PRINCIPAL, admindn );
                env.put( Context.SECURITY_CREDENTIALS, admincred );
                try {
                DirContext ctx = new InitialDirContext(env);
                
                Attributes attrs = new BasicAttributes(true);
                Attribute objclass = new BasicAttribute("objectclass");
                objclass.add("top");
                objclass.add("domain");
                objclass.add("ds-cfg-branch");
                attrs.put(objclass);
                attrs.put("dn","ds-cfg-backend-id=userRoot,cn=Backends,cn=config");
                ctx.createSubcontext("dc=naren1,dc=naren1",attrs);
                ctx.close();


      The error is am getting is
      javax.naming.NameNotFoundException: [LDAP: error code 32 - The provided entry dc=naren1,dc=naren1 cannot be added because its suffix is not defined as one of the suffixes within the Directory Server]; remaining name 'dc=naren1,dc=naren1'
           at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3057)
           at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2978)
        • 1. Re: Create base dn using JNDI...
          EJP
          The provided entry dc=naren1,dc=naren1 cannot be added because its suffix is not defined as one of the suffixes within the Directory Server]; remaining name 'dc=naren1,dc=naren1'
          What part of that isn't clear?
          • 2. Re: Create base dn using JNDI...
            953167
            The Thing is that what suffix i have to add to create the base dn .....
            • 3. Re: Create base dn using JNDI...
              953167
              Please waiting some response i am being stuck in that problem and not able to solve the same.

              Thanks in advance.
              • 4. Re: Create base dn using JNDI...
                gimbal2
                user5454760 wrote:
                Please waiting some response i am being stuck in that problem and not able to solve the same.

                Thanks in advance.
                So you tried doing a Google search for "LDAP: error code 32 - The provided entry cannot be added because its suffix is not defined as one of the suffixes within the Directory Server" to see what other people had to say about this error?

                Note what I did there: I took the error message and took out the part that is specific to your environment.

                You can keep waiting for someone to hand you a solution all you want, but I predict you'll be waiting for a long time.
                • 5. Re: Create base dn using JNDI...
                  953167
                  Yes i have been tried each and every scenario i could be think of ..... Dont know where exactly is the problem for the suffix ...
                  • 6. Re: Create base dn using JNDI...
                    gimbal2
                    user5454760 wrote:
                    Yes i have been tried each and every scenario i could be think of ..... Dont know where exactly is the problem for the suffix ...
                    Reading a good book on LDAP (not JNDI, not Java and LDAP - LDAP on its own) might remedy that.
                    • 7. Re: Create base dn using JNDI...
                      EJP
                      what suffix i have to add to create the base dn .....
                      As the error message clearly says,* "one of the suffixes within the Directory Server". Only you can possibly know what they are.
                      • 8. Re: Create base dn using JNDI...
                        953167
                        I want to create the base dn on the OpenDJ and i have used the above mentioned code to create the basedn .

                        I am the confing file where this entry should be created

                        dn: ds-cfg-backend-id=userRoot,cn=Backends,cn=config
                        objectClass: ds-cfg-backend
                        objectClass: top
                        objectClass: ds-cfg-local-db-backend
                        ds-cfg-preload-time-limit: 0 seconds
                        ds-cfg-compact-encoding: true
                        ds-cfg-db-checkpointer-bytes-interval: 20 megabytes
                        ds-cfg-db-logging-level: CONFIG
                        ds-cfg-db-checkpointer-wakeup-interval: 30 seconds
                        ds-cfg-disk-full-threshold: 20 megabytes
                        ds-cfg-db-evictor-keep-alive: 600 seconds
                        ds-cfg-disk-low-threshold: 100 megabytes
                        ds-cfg-db-directory: db
                        ds-cfg-base-dn: dc=com
                        ds-cfg-base-dn: dc=ex,dc=com1
                        ds-cfg-base-dn: dc=exam,dc=com2


                        I have also read one artical on the same http://stackoverflow.com/questions/8977946/how-to-create-new-base-dn-using-jndi

                        But unable to find the error . If any body can help who had worked on to create the base dn on LDAP.
                        • 9. Re: Create base dn using JNDI...
                          EJP
                          Sigh. Nobody can answer this question for you. Only you know what is in your LDAP tree. Please stop wasting time. You have only one alternative: have a look in your LDAP tree to see what its base is. Then you would have your answer. You won't get it here and you won't get it from Google.
                          • 10. Re: Create base dn using JNDI...
                            953167
                            when i am creating the basedn using the OpenDJ it is creating fine .... in the userRoot ...

                            If i have to create the same using JNDI then any help ,.... Not created any directory structure by me ... That is by default what open DJ will create.

                            This code will works fine :
                            ctx.createSubcontext("dc=n1,dc=n1");

                            But in my case it is not i have read the same on the Google too for this.
                            • 11. Re: Create base dn using JNDI...
                              953167
                              When this error is coming for the adding the base dn in opendj.

                              because its suffix is not defined as one of the suffixes within the Directory Server

                              code is

                              ctx.createSubcontext(entryDN, attri);
                              • 12. Re: Create base dn using JNDI...
                                EJP
                                You don't need to explain it to us, it is perfectly clear. You need to read and understand what you've already been told here. If you don't understand it, ask. Don't just keep re-posting the same information. If you continue as you are doing now, the thread will be locked.
                                • 13. Re: Create base dn using JNDI...
                                  953167
                                  Yes by the defination is it saying there is some problem in the Directory structure but when i will add the same base dn like dc="exam",dc="com" which is present in the OpenDJ then it will give the error as "Can not add the duplicate entry " It means it is present in the same directory structure otherwise it should throw the same error to me..

                                  One more thing i am able to create ,update users in the basedn perfectly but not able to create the basedn.