This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About LDAP and JNDI

 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
I sent a question to u.but i didnt get the reply.PLz help.when i am trying to connect to a ldap server after creating Initialdirectorycontext factory, igot the the following stacktrace.






Plz help me by telling the possible reasons for this exception.
Eagerly waiting for the reply.
[ December 13, 2005: Message edited by: Mark Spritzler ]
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ayan,

Not an answer, but just a hint. Open your browser and type this url:



Second, open another browser and type this url:



Wait for a while and look at the error message you�ll get back because it might make sense to you. The way I understand it is that there is no problem with your code, but either the parameters used to connect to ldap are wrong, or the LDAP server is not configured properly. Either way you should probably contact the LDAP provider for help or use another LDAP server (search the net for openldap).
Regards.
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i already tried it Valentin but of no conclusion.For the first url(ldap://ldap.bath.ac.uk),i was asked to type my name and e-mail and then press search.


for the later (ldap://ldap.bath.ac.uk/o=bath.ac.uk) ,i got an alert message that this directory service may not be reached.Either that server is down or the server name is incorrect.But i got this Url from one of the sample code on net.plz reply


i should inform you that i am writing this class as simple java class without any xml or server side attached with it,bcoz i think this is just the process of gettting the data from certain source and so only path itself is enough to reveal that.If i am wrong plz reply descriptively



plzzzzzzzzzz do reply
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ayan,

Unfortunately is nothing much I can do to help you. In the previous answer I tried to emphasize that there is something wrong with the URL or the ldap server is probably not able to establish a connection. It was not a solution to your problem.
The error you got:



Is self descriptive and could be either because the URL used to connect to ldap is wrong, or the server is not able to establish the connection (more likely). I don�t think the server is down otherwise you�ll get an appropriate error message; something like connection refused no available router to destination, etc. I can only suggest you couple of things:

  • Contact the customer support and ask them for help. Explain them your experience and ask them about the fix.
  • Download the openldap and own your own LDAP server.



  • Other than that is nothing much I can do.
    Good luck!
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17278
    6
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Origianlly posted by Ayan, but accidently clicks the add new thread button instead of the add reply button. It happens.


    i already tried it Valentin but of no conclusion.For the first url(ldap://ldap.bath.ac.uk),i was asked to type my name and e-mail and then press search.


    for the later (ldap://ldap.bath.ac.uk/o=bath.ac.uk) ,i got an alert message that this directory service may not be reached.Either that server is down or the server name is incorrect.But i got this Url from one of the sample code on net.plz reply


    i should inform you that i am writing this class as simple java class without any xml or server side attached with it,bcoz i think this is just the process of gettting the data from certain source and so only path itself is enough to reveal that.If i am wrong plz reply descriptively



    plzzzzzzzzzz do reply

    Ayan
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17278
    6
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK Ayan, I can understand you being frustrated because no one replied to you right away in your original thread. And, unfortunately, I don't think we have many people on the site that is or has used LDAP to answer you right away.

    But, you kind of violated a rule we have here.

    1. No duplicate posting.

    I have deleted your duplicate posts.

    Mark
     
    Ayan Dutta
    Ranch Hand
    Posts: 94
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am sorry for my act ayan but frankly saying i wasn't aware.Take my words,such acts wont be repeated.
     
    Ayan Dutta
    Ranch Hand
    Posts: 94
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi Valentin and mark and all others,
    i got it to work with a directory service as ldap://ldap.yo-linux.com but when i tried it with www.openldap.com and i passed the command line arguments as ou=people(the code was all same. ijust changed my URL and base DN)


    code:-


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


    public class SimpleQuery {

    public static void main(String[] args) {
    if (args.length != 1) {
    System.out.println("Syntax: SimpleQuery query");
    return;
    }
    String query = args[0];
    try {
    String dirRoot = "dc=OpenLDAP,o=OpenLDAP";
    Hashtable env = new Hashtable();
    env.put("com.sun.jndi.ldap.connect.pool", "true");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://www.openldap.com/"+dirRoot);

    env.put("com.sun.jndi.ldap.netscape.schemaBugs", "true");
    env.put("com.sun.jndi.ldap.trace.ber", System.out);


    DirContext context = new InitialDirContext(env);
    SearchControls ctrl = new SearchControls();
    ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);

    NamingEnumeration enumeration = context.search("", query, ctrl);

    while (enumeration.hasMore()) {
    SearchResult result= (SearchResult)enumeration.next();

    String dn = result.getName() + "," + dirRoot;
    Attributes attribs = result.getAttributes();
    BasicAttribute cnAttrib = (BasicAttribute) attribs.get("cn");
    System.out.println("Known As ha ha ha ha : " + cnAttrib);
    String commonName = (String) cnAttrib.get(0);
    System.out.println("Known As:::::::;;: " + commonName);

    }

    } catch (NamingException ne) {
    ne.printStackTrace();
    System.out.println("Error: " + ne);
    }
    }

    public SimpleQuery() {}
    }


    i got the following stacktrace and the output:-

    -> www.openldap.com:389

    0000: 30 0C 02 01 01 60 07 02 01 03 04 00 80 00 0....`........


    <- www.openldap.com:389

    0000: 30 0C 02 01 01 61 07 0A 01 00 04 00 04 00 0....a........

    -> www.openldap.com:389

    0000: 30 5C 02 01 02 63 3A 04 16 64 63 3D 4F 70 65 6E 0\...c:..dc=Open
    0010: 4C 44 41 50 2C 6F 3D 4F 70 65 6E 4C 44 41 50 0A LDAP,o=OpenLDAP.
    0020: 01 02 0A 01 03 02 01 00 02 01 00 01 01 00 A3 0F ................
    0030: 04 02 63 6E 04 09 44 69 72 65 63 74 6F 72 79 30 ..cn..Directory0
    0040: 00 A0 1B 30 19 04 17 32 2E 31 36 2E 38 34 30 2E ...0...2.16.840.
    0050: 31 2E 31 31 33 37 33 30 2E 33 2E 34 2E 32 1.113730.3.4.2


    <- www.openldap.com:389

    0000: 30 0C 02 01 02 65 07 0A 01 20 04 00 04 00 0....e... ....

    javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name ''
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
    at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
    at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
    at javax.naming.directory.InitialDirContext.search(Unknown Source)
    at SimpleQuery.main(SimpleQuery.java:71)
    Error: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name ''
     
    Valentin Tanase
    Ranch Hand
    Posts: 704
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Mark,


    OK Ayan, I can understand you being frustrated because no one replied to you right away in your original thread. And, unfortunately, I don't think we have many people on the site that is or has used LDAP to answer you right away.


    I swear I do, although I was still not able to gice a complete answer :-)
     
    Mark Spritzler
    ranger
    Sheriff
    Posts: 17278
    6
    IntelliJ IDE Mac Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Valentin Tanase:
    Hi Mark,



    I swear I do, although I was still not able to gice a complete answer :-)


    But I said "not many", not "not any"

    Thanks for helping out.

    Mark
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic